在Graphviz中,如何将边缘与节点的顶部中心对齐?

时间:2014-12-16 12:28:33

标签: graphviz dot

在Graphviz / dot中,是否可以将边缘准确地连接到节点的顶部中心?阅读点指南,我认为tailportheadport会对我有帮助,但添加这些不会产生任何影响,有时会让我看起来更奇怪。

这就是我得到的:

sample graph

这就是我正在寻找的:

wanted results

我用来获取(不正确)图表的代码是:

digraph G {

  graph [splines = ortho];
  node [shape = box];
  edge [dir = none];

  {
    rank = same

    A
    AB [shape = point]
    B

    A -> AB
    AB -> B
  }

  {
    rank = same
    point1 [shape = point]
    point2 [shape = point]
    point3 [shape = point]
  }

  AB -> point1

  // The following section if to make the nodes appear in 
  // the correct order, not sure if there's a better way
  {
    edge [style = invisible]
    rank = same
    C
    D
    E
    F
    C -> D
    D -> E
  }

  point2 -> point1
  point2 -> C
  point1 -> point3
  point3 -> E
  point1 -> D

}

3 个答案:

答案 0 :(得分:4)

原来最新的(2.38)版本在Mac OS X Yosemite中无法正常工作,我不得不降级到2.36,如download page所示。

答案 1 :(得分:3)

注释

  1. splines=ortho不支持tailportheadport(请参阅:"Graphviz Issue Tracker - 0002142: ortho plots do not respect ports. also arrowheads seem to go the wrong way."
  2. 您可以使用隐藏节点,但不要在横向节点上使用它们(例如下面示例中的CF
  3. 图像

    Result

    代码

    此代码即使有超过3个子节点也可以使用,并且与Graphviz 2.38兼容。对组织结构图很有用(即使你有很多级别它也不完美 - 我仍然试图减少不对称)。

     graph {
        splines=ortho;
        {0, 1, 2, 3 [width=0, shape=point, style=invis];}
        {rank=same; 1 -- 2 -- 3;}
        0 -- 2;
        node [shape=box];
        {rank=same; A -- 0 -- B;}
        1 -- C;
        1 -- D;
        3 -- E;
        3 -- F;
    }
    

答案 2 :(得分:0)

我在Windows7下看到了相同的效果 - 没有尝试其他平台。

我试图摆弄'港口位置',见http://www.graphviz.org/content/attrs#kportPos

e.g。将代码的最后几行更改为

class BackgroundMap: UIView {
    var view: UIView!

    override init(frame: CGRect) {
        super.init(frame: frame)
        view = loadViewFromNib ()
        view.frame = bounds
        view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        view.translatesAutoresizingMaskIntoConstraints = true
        view.backgroundColor = UIColor(patternImage: UIImage(named: "MapWantd")!)
        self.addSubview(view)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        view = loadViewFromNib ()
        view.frame = bounds
        view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        view.translatesAutoresizingMaskIntoConstraints = true
        view.backgroundColor = UIColor(patternImage: UIImage(named: "MapWantd")!)
        self.addSubview(view)
    }

    func loadViewFromNib() ->UIView {
        let bundle = NSBundle(forClass: self.dynamicType)
        let nib = UINib(nibName: "BackgroundMap", bundle: bundle)
        let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
        return view
    }
}

给出了(略微)更好的连接线定位。