2

我一直在尝试使用Tk::GraphViz.

我有以下代码:

use strict;
use warnings;
use Tk::GraphViz;
use Tk;


my $graph ='graph PathsOfPin {
    a [label = "aaa"];
    b [label = "bbb"];
    c [label = "ccc"];
    d [label = "ddd"];
    e [label = "eee"];
    f [label = "fff"];
    a--b;
    c--d;
    e--f;
    b--c;
    d--e;
}';
my $mw = new MainWindow();
my $gv = $mw->GraphViz ( qw/-width 800 -height 800/ )->pack ( qw/-expand yes -fill both/ );

$gv->fit(); # This does nothing - down't affect the view
$gv->zoom( -in => 100 ); # This gives me error
$gv->show ( $graph );
MainLoop;

当我尝试在没有fitand的情况下运行代码时zoom,我得到了这个非常小的图形(看起来像一个点),我需要用鼠标将其放大几次,直到我看到它。

  1. 我尝试了fit,它应该适合图表查看 - 但它并没有真正起作用。
  2. 当我尝试使用 对缩放进行硬编码时$gv-zoom,出现以下错误:

    Tk::Error: Can't set -scrollregion to ARRAY(0xbb8d30) for Tk::GraphViz=HASH(0xd1bbb0): bad       scrollRegion "???" at /5.8.5/lib/site_perl/5.8.5/x86_64-linux/Tk/Configure.pm line 46.
    at /5.8.5/lib/site_perl/5.8.5/x86_64-linux/Tk/Derived.pm line 294
    Tk callback for .
    Tk callback for .graphviz
    Tk callback for .graphviz
    Tk::Derived::configure at 5.8.5/lib/site_perl/5.8.5/x86_64-linux/Tk/Derived.pm line 306
    Tk::GraphViz::_scaleAndMoveView at GraphViz.pm line 1445
    Tk::GraphViz::zoom at Tk/GraphViz.pm line 1864
    Can't set -scrollregion to ARRAY(0xbb8d30) for Tk::GraphViz=HASH(0xd1bbb0): bad scrollRegion "???" at 5.8.5/x86_64-linux/Tk/Configure.pm line 46.
    at 5.8.5/x86_64-linux/Tk/Derived.pm line 294
    

将图形自动适合缩放的更好方法是什么?

4

1 回答 1

0

有!在the之前执行 azoom或 a会导致大问题。如果您省略, 并在演出后执行,则一切都在repo的当前代码中运行。fit showzoomfitmaster

此代码现在有效:

use strict;
use warnings;
use Tk::GraphViz;
use Tk;

my $graph ='graph PathsOfPin {
    a [label = "aaa"];
    b [label = "bbb"];
    c [label = "ccc"];
    d [label = "ddd"];
    e [label = "eee"];
    f [label = "fff"];
    a--b;
    c--d;
    e--f;
    b--c;
    d--e;
}';

my $mw = new MainWindow();
my $gv = $mw->Scrolled('GraphViz', qw/-scrollbars osoe -width 800 -height 800/ )->pack ( qw/-expand no -fill both/ );

$gv->show ( $graph );
$gv->fit();
$mw->update;
MainLoop;

当您阅读本文时,该库的更新版本将在 CPAN 上。为了处理 DOT 输出格式的变化,需要进行各种修复。它现在似乎运作良好。请尝试一下,并在 GitHub 问题中报告任何问题。

于 2020-11-07T04:28:36.657 回答