【问题标题】:Is it possible to generate a small GraphViz chart?是否可以生成一个小的 GraphViz 图表?
【发布时间】:2021-07-11 18:51:32
【问题描述】:

我需要生成一个小的 graphviz 图,它代表主 graphviz 的“价格图”。主图是:

digraph g {
  graph [rankdir = "LR"];

  a [label = "<f0>a | <f1> $139  | <f2> Chair | Brown" shape = "record"];
  b [label = "<f0>b | <f1> $280  | <f2> Speakers | Grey" shape = "record"];
  c [label = "<f0>c | <f1> $89  | <f2> Jacket | Beige" shape = "record"];
  d [label = "<f0>d | <f1> $19  | <f2> Mug | Green" shape = "record"];
  e [label = "<f0>e | <f1> $180  | <f2> Printer | Grey" shape = "record"];

  a -> b; a -> c; c -> d; c -> e;
}

它会生成:

当我尝试生成“小”价格图时:

digraph g {
  graph [rankdir = "LR"];
  node [shape=box];

  a[color=black, fillcolor=yellow, style=filled];
  b[color=black, fillcolor=red, style=filled];
  c;
  d;
  e[color=black, fillcolor=yellow, style=filled];

  a -> b; a -> c; c -> d; c -> e;
}

我明白了:

但我想要一个非常小的价格图,例如:

这可能吗?

【问题讨论】:

    标签: graphviz


    【解决方案1】:

    你真的应该阅读点指南,这是一个非常令人印象深刻的关于使用点的观点(尽管 HTMl 节点没有那么多功能):http://graphviz.org/pdf/dotguide.pdf

    尝试将形状更改为普通:

    node [shape=plain];
    

    结果:

    另一种可能性是使用 HTML 节点 - 我在此示例中的回答显示紧凑节点 https://stackoverflow.com/a/68320427/2318649

    另一种控制间距的方法是在图上使用nodesep和rankep,例如:

    digraph g {
      graph [rankdir="LR"  nodesep=0.1 ranksep=0.2];
      node [shape=plain];
    
      a[color=black, fillcolor=yellow, style=filled];
      b[color=black, fillcolor=red, style=filled];
      c;
      d;
      e[color=black, fillcolor=yellow, style=filled];
    
      a -> b; a -> c; c -> d; c -> e;
    }
    

    结果:

    另一种最小化盒子节点内空间的方法是将边距、宽度和高度全部设置为0:

    digraph g {
      graph [rankdir="LR"  nodesep=0.1 ranksep=0.2];
      node [shape=box  margin=0 width=0 height=0];
    
      a[color=black, fillcolor=yellow, style=filled];
      b[color=black, fillcolor=red, style=filled];
      c;
      d;
      e[color=black, fillcolor=yellow, style=filled];
    
      a -> b; a -> c; c -> d; c -> e;
    }
    

    结果:

    您可以控制每个边缘的箭头大小,例如:

      a -> b [arrowsize=0.5]; a -> c [arrowsize=0.5]; c -> d  [arrowsize=0.5]; c -> e;
    

    结果:

    或者您可以控制所有边缘的箭头大小:

    digraph g {
      graph [rankdir="LR"  nodesep=0.1 ranksep=0.2];
      node [shape=box  margin=0 width=0 height=0];
      edge [arrowsize=0.5]
      a[color=black, fillcolor=yellow, style=filled];
      b[color=black, fillcolor=red, style=filled];
      c;
      d;
      e[color=black, fillcolor=yellow, style=filled];
    
      a -> b; a -> c; c -> d; c -> e;
    }
    

    结果:

    阅读属性:http://graphviz.org/doc/info/attrs.html

    了解节点:http://graphviz.org/doc/info/shapes.html

    了解如何使用点:http://graphviz.org/pdf/dotguide.pdf

    【讨论】:

      猜你喜欢
      • 2021-03-23
      • 2013-04-25
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 2011-03-26
      • 1970-01-01
      • 2023-01-07
      相关资源
      最近更新 更多