LoginSignup
8
7

More than 5 years have passed since last update.

Ruby | Gviz で様々な layout を試してみる

Posted at

Ruby | Gviz で様々な layout を試してみる

概要

Gviz で様々な layout を試してみます。

Layouts

Graphviz の layout には以下の種類があります。
※リンク先は公式ドキュメント( PDF )

コード

require "gviz"

sexagenary_cycle = %w(子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥)
layouts = %i(circo dot fdp neato osage patchwork sfdp twopi)

layouts.each do |layout|
  Graph do
    global layout: layout, label:"sexagenary_#{layout}", fontsize:20, size:15, overlap:false
    nodes fontname:'MS GOTHIC', colorscheme: :paired12, style: :filled

    sexagenary_cycle.each_with_index do |e, i|
      edge "eto_#{i}"
      node :"#{i}", { label: e, fillcolor: i%12}
    end
    node :"eto", { label: '干支', fillcolor: :white }
    node :"0", { label: sexagenary_cycle.first, fillcolor: 1 }
    node :"11", { label: sexagenary_cycle.last, fillcolor: 12 }

    save :"sexagenary_#{layout}", :png
  end
end

出力

circo 出力結果

sexagenary_circo.png

dot 出力結果

sexagenary_dot.png

fdp 出力結果

sexagenary_fdp.png

neato 出力結果

sexagenary_neato.png

osage 出力結果

sexagenary_osage.png

patchwork 出力結果

sexagenary_patchwork.png

sfdp 出力結果

sexagenary_sfdp.png

twopi 出力結果

sexagenary_twopi.png

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7