1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
# = Dendogram
# A dendrogram (or cluster layout) is a node-link diagram that places leaf nodes of the tree at the same depth. In this example, the classes (orange leaf nodes) are aligned on the right edge, with the packages (blue internal nodes) to the left. As with other tree layouts, dendrograms can also be oriented radially.
# Uses Protovis API
$:.unshift(File.dirname(__FILE__)+"/../../lib")
require 'rubyvis'
def get_files(path)
h={}
Dir.glob("#{path}/*").each {|e|
next if File.expand_path(e)=~/pkg|web|vendor|doc|~/
pa=File.expand_path(e)
if File.stat(pa).directory?
h[File.basename(pa)]=get_files(pa)
else
h[File.basename(pa)]=File.stat(pa).size
end
}
h
end
files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../lib/"))
vis = Rubyvis::Panel.new do
width 200
height 1500
left 40
right 160
top 10
bottom 10
layout_cluster do
nodes pv.dom(files).root("rubyvis").sort(lambda {|a,b| a.node_name<=>b.node_name}).nodes
group 0.2
orient "left"
link.line do
stroke_style "#ccc"
line_width 1
antialias false
end
node.dot do
fill_style {|n| n.first_child ? "#aec7e8" : "#ff7f0e"}
end
node_label.label
end
end
vis.render
puts vis.to_svg
|