我一直在尝试使用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;
当我尝试在没有fit
和zoom
的情况下运行代码时,我得到这个非常小的图形(看起来像一个点),我需要用鼠标放大几次,直到我看到它。
- 我尝试了
fit
,它应该适合图形查看-但它并没有真正工作。 当我尝试用
$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
是一个更好的方法来自动适应图形缩放?
有!在 show
之前做zoom
或fit
将导致大问题。如果您省略zoom
,并在显示之后执行fit
,则在repo的master
上的当前代码中一切正常。
下面的代码可以运行了:
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问题中的任何问题。