Tk :: GraphViz缩放

时间:2013-05-08 12:08:24

标签: perl graphviz tk

我一直在尝试使用Tk::GraphWiz绘制连接图。

我有以下代码:

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;

当我尝试运行没有fitzoom的代码时,我会得到这个非常小的图形(看起来像一个点),我需要用鼠标放大几次直到我看到我应该这样做。

  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
    
  3. 将图表自动调整到缩放是更好的方法吗?

1 个答案:

答案 0 :(得分:0)

有!在zoom之前做fitshow 会引起很大的问题。如果您省略了zoom,并在演出后执行了fit,则一切都将以仓库中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问题中的所有问题。