rubyvis 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +8 -0
  3. data/Manifest.txt +45 -36
  4. data/examples/{first_rbp_api.rb → 1_basic/1a_bar_rbp_api.rb} +1 -1
  5. data/examples/{first_protovis_api.rb → 1_basic/1b_bar_pv_api.rb} +1 -1
  6. data/examples/{second.rb → 1_basic/2_bar_and_rule.rb} +2 -2
  7. data/examples/{third.rb → 1_basic/3_grouped_bars.rb} +1 -1
  8. data/examples/{area_interpolation.rb → 1_basic/area_interpolation.rb} +1 -1
  9. data/examples/{dot.rb → 1_basic/dot.rb} +1 -1
  10. data/examples/{fixtures → 1_basic/fixtures}/tipsy.gif +0 -0
  11. data/examples/1_basic/grid.rb +29 -0
  12. data/examples/{image.rb → 1_basic/image.rb} +1 -1
  13. data/examples/{line.rb → 1_basic/line.rb} +1 -1
  14. data/examples/{line_interpolation.rb → 1_basic/line_interpolation.rb} +1 -1
  15. data/examples/2_medium/censo_agropecuario/censo_agropecuario_chile_data.rb +53 -0
  16. data/examples/2_medium/censo_agropecuario/census_treemap.rb +63 -0
  17. data/examples/2_medium/censo_agropecuario/create_data.rb +10 -0
  18. data/examples/2_medium/censo_agropecuario/resultset.csv +51 -0
  19. data/examples/{nested_grid.rb → 2_medium/nested_grid.rb} +3 -4
  20. data/examples/{area.rb → 3_pv_conventional/area.rb} +1 -1
  21. data/examples/{bar_column_chart.rb → 3_pv_conventional/bar_column_chart.rb} +1 -1
  22. data/examples/{grouped_charts.rb → 3_pv_conventional/grouped_charts.rb} +1 -1
  23. data/examples/{line_and_step.rb → 3_pv_conventional/line_and_step.rb} +1 -1
  24. data/examples/{pie_and_donut.rb → 3_pv_conventional/pie_and_donut.rb} +1 -1
  25. data/examples/{scatterplot.rb → 3_pv_conventional/scatterplot.rb} +1 -1
  26. data/examples/{stacked_charts.rb → 3_pv_conventional/stacked_charts.rb} +1 -3
  27. data/examples/{antibiotics → 4_pv_custom/antibiotics}/antibiotics_data.rb +0 -0
  28. data/examples/{antibiotics → 4_pv_custom/antibiotics}/antibiotics_scatter.rb +1 -1
  29. data/examples/{antibiotics → 4_pv_custom/antibiotics}/antibiotics_wedge.rb +1 -1
  30. data/examples/{barley → 4_pv_custom/barley}/barley.rb +5 -1
  31. data/examples/{barley → 4_pv_custom/barley}/barley_data.rb +0 -0
  32. data/examples/{cars → 4_pv_custom/cars}/cars.rb +1 -1
  33. data/examples/{cars → 4_pv_custom/cars}/cars_data.rb +0 -0
  34. data/examples/{crimea → 4_pv_custom/crimea}/crimea_data.rb +0 -0
  35. data/examples/{crimea → 4_pv_custom/crimea}/crimea_grouped_bar.rb +1 -1
  36. data/examples/{crimea → 4_pv_custom/crimea}/crimea_line.rb +1 -1
  37. data/examples/{bubble_charts.rb → 5_pv_hierarchies/bubble_charts.rb} +3 -2
  38. data/examples/5_pv_hierarchies/bubble_charts_matrix.rb +64 -0
  39. data/examples/{circle_packing.rb → 5_pv_hierarchies/circle_packing.rb} +4 -4
  40. data/examples/{dendogram.rb → 5_pv_hierarchies/dendogram.rb} +2 -2
  41. data/examples/{icicle.rb → 5_pv_hierarchies/icicle.rb} +2 -2
  42. data/examples/{indent.rb → 5_pv_hierarchies/indent.rb} +2 -2
  43. data/examples/5_pv_hierarchies/node_link_tree.rb +52 -0
  44. data/examples/{sunburst.rb → 5_pv_hierarchies/sunburst.rb} +2 -2
  45. data/examples/5_pv_hierarchies/treemap.rb +48 -0
  46. data/lib/rubyvis.rb +1 -1
  47. data/lib/rubyvis/dom.rb +16 -1
  48. data/lib/rubyvis/internals.rb +2 -2
  49. data/lib/rubyvis/layout.rb +2 -0
  50. data/lib/rubyvis/layout/grid.rb +105 -0
  51. data/lib/rubyvis/layout/pack.rb +53 -54
  52. data/lib/rubyvis/layout/stack.rb +26 -24
  53. data/lib/rubyvis/layout/tree.rb +267 -0
  54. data/lib/rubyvis/layout/treemap.rb +1 -0
  55. data/lib/rubyvis/mark.rb +10 -8
  56. data/lib/rubyvis/mark/area.rb +6 -6
  57. data/lib/rubyvis/mark/dot.rb +1 -1
  58. data/lib/rubyvis/mark/shorcut_methods.rb +29 -2
  59. data/lib/rubyvis/nest.rb +48 -2
  60. data/lib/rubyvis/scale/ordinal.rb +6 -6
  61. data/lib/rubyvis/scale/quantitative.rb +13 -7
  62. data/lib/rubyvis/scene/svg_area.rb +20 -14
  63. data/lib/rubyvis/scene/svg_bar.rb +1 -1
  64. data/lib/rubyvis/scene/svg_scene.rb +0 -1
  65. data/lib/rubyvis/sceneelement.rb +1 -1
  66. data/spec/area_spec.rb +12 -0
  67. data/spec/dom_spec.rb +15 -8
  68. data/spec/layout_stack_spec.rb +70 -0
  69. data/spec/nest_spec.rb +8 -2
  70. data/spec/scale_linear_spec.rb +7 -1
  71. data/spec/scale_ordinal_spec.rb +4 -0
  72. data/spec/spec_helper.rb +1 -1
  73. data/web/build_site.rb +6 -2
  74. data/web/index.haml +2 -2
  75. metadata +61 -68
  76. metadata.gz.sig +0 -0
  77. data/examples/treemap/treemap.rb +0 -29
  78. data/examples/treemap/treemap_data.rb +0 -285
@@ -1,7 +1,7 @@
1
1
  # = Grouped charts
2
2
  # In this multi-series bar chart, we group bars together rather than stack them. A grouped chart allows accurate comparison of individual values thanks to an aligned baseline: a position, rather than length, judgment is used.
3
3
  # An ordinal scale positions the groups vertically; the bars are then replicated inside a panel, a technique that is also used for small multiples.
4
- $:.unshift(File.dirname(__FILE__)+"/../lib")
4
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
5
5
  require 'rubyvis'
6
6
 
7
7
  n = 3
@@ -2,7 +2,7 @@
2
2
  # Line charts are often used to visualize time series data, encoding the value of a variable over time using position. Typically, linear interpolation is used between samples. However, in some cases, the data does not vary smoothly, but instead changes in response to discrete events.
3
3
  # Using the interpolate property, it is easy to change this behavior for lines and areas. Rubyvis also supports various nonlinear interpolation methods, including cardinal spline, Catmull-Rom spline, B-spline, and monotone cubic.
4
4
 
5
- $:.unshift(File.dirname(__FILE__)+"/../lib")
5
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
6
6
  require 'rubyvis'
7
7
 
8
8
  data = pv.range(0, 10, 0.2).map {|x|
@@ -1,4 +1,4 @@
1
- $:.unshift(File.dirname(__FILE__)+"/../lib")
1
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
2
2
  require 'rubyvis'
3
3
 
4
4
  # Sizing and scales. */
@@ -1,6 +1,6 @@
1
1
  # = Scatterplot
2
2
  # Scatterplots can facilitate visual analysis along multiple dimensions, though care should be taken to avoid interference. In this example, we encode three dimensions: two are encoded using position, while the third is redundantly encoded as both area and color.
3
- $:.unshift(File.dirname(__FILE__)+"/../lib")
3
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
4
4
  require 'rubyvis'
5
5
  data = pv.range(100).map {|x|
6
6
  OpenStruct.new({x: x, y: rand(), z: 10**(2*rand)})
@@ -1,6 +1,6 @@
1
1
  # = Stacked Area
2
2
  # This example uses the Stack layout to stack areas one over another.
3
- $:.unshift(File.dirname(__FILE__)+"/../lib")
3
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
4
4
  require 'rubyvis'
5
5
 
6
6
  data = pv.range(4).map {|i|
@@ -23,7 +23,6 @@ vis = pv.Panel.new()
23
23
  .left(20)
24
24
  .right(10)
25
25
  .top(5)
26
- if(true)
27
26
  #/* X-axis and ticks. */
28
27
  vis.add(pv.Rule)
29
28
  .data(x.ticks())
@@ -40,7 +39,6 @@ vis.add(pv.Rule)
40
39
  .strokeStyle(lambda {|d| d!=0 ? "rgba(128,128,128,.2)" : "#000"})
41
40
  .anchor("left").add(pv.Label)
42
41
  .text(y.tick_format)
43
- end
44
42
  #/* The stack layout. */
45
43
  vis.add(pv.Layout.Stack)
46
44
  .layers(data)
@@ -1,7 +1,7 @@
1
1
  # = Antibiotic Effectiveness : Scatterplot
2
2
  # After World War II, antibiotics earned the moniker “wonder drugs” for quickly treating previously-incurable diseases. Data was gathered to determine which drug worked best for each bacterial infection. Comparing drug performance was an enormous aid for practitioners and scientists alike. In the fall of 1951, Will Burtin published this graph showing the effectiveness of three popular antibiotics on 16 different bacteria, measured in terms of minimum inhibitory concentration.
3
3
  # Recreating this display revealed some minor errors in the original: a missing grid line at 0.01 μg/ml, and an exaggeration of some values for penicillin.
4
- $:.unshift(File.dirname(__FILE__)+"/../../lib")
4
+ $:.unshift(File.dirname(__FILE__)+"/../../../lib")
5
5
  require 'rubyvis'
6
6
  load(File.dirname(__FILE__)+"/antibiotics_data.rb")
7
7
 
@@ -1,7 +1,7 @@
1
1
  # = Antibiotic Effectiveness : Pie chart
2
2
  # After World War II, antibiotics earned the moniker “wonder drugs” for quickly treating previously-incurable diseases. Data was gathered to determine which drug worked best for each bacterial infection. Comparing drug performance was an enormous aid for practitioners and scientists alike. In the fall of 1951, Will Burtin published this graph showing the effectiveness of three popular antibiotics on 16 different bacteria, measured in terms of minimum inhibitory concentration.
3
3
  # Recreating this display revealed some minor errors in the original: a missing grid line at 0.01 μg/ml, and an exaggeration of some values for penicillin.
4
- $:.unshift(File.dirname(__FILE__)+"/../../lib")
4
+ $:.unshift(File.dirname(__FILE__)+"/../../../lib")
5
5
  require 'rubyvis'
6
6
  load(File.dirname(__FILE__)+"/antibiotics_data.rb")
7
7
 
@@ -1,4 +1,8 @@
1
- $:.unshift(File.dirname(__FILE__)+"/../../lib")
1
+ # = Becker’s Barley
2
+ # The "Trellis display":http://www.jstor.org/stable/1390777 by Becker et al. helped establish small multiples as a “powerful mechanism for understanding interactions in studies of how a response depends on explanatory variables”. Here we reproduce a trellis of Barley yields from the 1930s, complete with main-effects ordering to facilitate comparison. These examples demonstrate Protovis’ support for data transformation via the nest operator.
3
+ # Notice anything unusual about one of the sites? This anomaly led Becker et al. to suspect a major error with the data that went undetected for six decades.
4
+
5
+ $:.unshift(File.dirname(__FILE__)+"/../../../lib")
2
6
  require 'rubyvis'
3
7
  load(File.dirname(__FILE__)+"/barley_data.rb")
4
8
  # Nest yields data by site then year. */
@@ -2,7 +2,7 @@
2
2
  # Parallel coordinates is a popular method of visualizing high-dimensional data using dynamic queries.
3
3
  # On static setting, you could choose an attribute and colour each datum which belongs to an attribute differently. On this example, we choose to color :cylinders attribute and highlight the cars with 8 cylinders
4
4
 
5
- $:.unshift(File.dirname(__FILE__)+"/../../lib")
5
+ $:.unshift(File.dirname(__FILE__)+"/../../../lib")
6
6
  require 'rubyvis'
7
7
  load(File.dirname(__FILE__)+"/cars_data.rb")
8
8
  attr_to_color=:cylinders
@@ -1,6 +1,6 @@
1
1
  # = Crimeam War deaths (Grouped bar)
2
2
  # Florence Nightingale used a coxcomb diagram to emphasize the number of deaths due to “preventible or mitigable zymotic diseases”. This graph shows data using a stacked bar chart.
3
- $:.unshift(File.dirname(__FILE__)+"/../../lib")
3
+ $:.unshift(File.dirname(__FILE__)+"/../../../lib")
4
4
  require 'rubyvis'
5
5
  require 'ostruct'
6
6
  load(File.dirname(__FILE__)+"/crimea_data.rb")
@@ -1,7 +1,7 @@
1
1
  # = Crimeam War deaths (Grouped bar)
2
2
  # Florence Nightingale used a coxcomb diagram to emphasize the number of deaths due to “preventible or mitigable zymotic diseases”. This graph shows data using a line chart.
3
3
 
4
- $:.unshift(File.dirname(__FILE__)+"/../../lib")
4
+ $:.unshift(File.dirname(__FILE__)+"/../../../lib")
5
5
  require 'rubyvis'
6
6
  require 'ostruct'
7
7
  load(File.dirname(__FILE__)+"/crimea_data.rb")
@@ -1,5 +1,6 @@
1
+ # = Bubble charts
1
2
  # Bubble charts, such as those provided by "Many Eyes":http://manyeyes.alphaworks.ibm.com/manyeyes/page/Bubble_Chart.html, encode data in the area of circles. Although less perceptually accurate than bar charts, they can pack hundreds of values into a small space. A similar technique is the Dorling cartogram, where circles are positioned according to geography rather than arbitrarily. Here we compare the file sizes of the Rubyvis library files
2
- $:.unshift(File.dirname(__FILE__)+"/../lib")
3
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
3
4
  require 'rubyvis'
4
5
 
5
6
 
@@ -17,7 +18,7 @@ def get_files(path)
17
18
  h
18
19
  end
19
20
 
20
- files=get_files(File.dirname(__FILE__)+"/../lib")
21
+ files=get_files(File.dirname(__FILE__)+"/../../lib")
21
22
 
22
23
  classes = Rubyvis.nodes(Rubyvis.flatten(files).leaf(lambda {|v| v.is_a? Numeric}).array)
23
24
 
@@ -0,0 +1,64 @@
1
+ # = Bubble charts matrix
2
+ #
3
+ # Why have one boring bubble chart when
4
+ # you can have 20 multicolor charts?
5
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
6
+ require 'rubyvis'
7
+
8
+ panes=20
9
+ cols=2
10
+
11
+
12
+ p_w=200
13
+ p_h=150
14
+ #p data
15
+ w = 20+p_w*cols
16
+ h = (panes/cols)*10+p_h*(panes/cols)
17
+
18
+ colors20=Rubyvis::Colors.category20()
19
+ c20=Rubyvis::Colors.category20().by(lambda {|n| n.parent_node})
20
+ vis = pv.Panel.new()
21
+ .width(w)
22
+ .height(h)
23
+ .bottom(5)
24
+ .left(5)
25
+ .right(5)
26
+ .top(5)
27
+
28
+
29
+
30
+ (0..panes).each do |i|
31
+ n=i%cols
32
+ m=(i/cols.to_f).floor
33
+ panel=vis.add(Rubyvis::Panel).
34
+ left(n*(p_w+10)).
35
+ top(m*(p_h+10)).
36
+ width(p_w).
37
+ height(p_h)
38
+
39
+ d=Rubyvis.nodes((i+1).times.map {|ii| rand(5)+1})
40
+
41
+
42
+ panel.anchor('top').add(Rubyvis::Label).text("n#{i+1}")
43
+
44
+ pack=panel.add(pv.Layout.Pack).
45
+ nodes(d).
46
+ size(lambda {|n| n.node_value})
47
+
48
+ pack.node.add(Rubyvis::Dot).
49
+ visible( lambda {|n| n.parent_node}).
50
+ fill_style(lambda {|n|
51
+ colors20.scale(n.parent_node).
52
+ lighter((n.node_value) / 5.0)
53
+ }).
54
+ stroke_style(c20)
55
+
56
+ pack.node_label.add(Rubyvis::Label).
57
+ visible( lambda {|n| n.parent_node}).
58
+ text(lambda {index})
59
+
60
+ end
61
+
62
+ vis.render();
63
+ puts vis.to_svg
64
+
@@ -4,7 +4,7 @@
4
4
  # This example uses RBP API.
5
5
 
6
6
 
7
- $:.unshift(File.dirname(__FILE__)+"/../lib")
7
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
8
8
  require 'rubyvis'
9
9
 
10
10
 
@@ -22,7 +22,7 @@ def get_files(path)
22
22
  h
23
23
  end
24
24
 
25
- files=get_files(File.dirname(__FILE__)+"/../lib/")
25
+ files=get_files(File.dirname(__FILE__)+"/../../lib/")
26
26
 
27
27
  format = Rubyvis::Format.number();
28
28
 
@@ -38,8 +38,8 @@ vis = Rubyvis::Panel.new do
38
38
  d.first_child ? "rgba(31, 119, 180, 0.25)" : "#ff7f0e"
39
39
  }
40
40
  title {|d|
41
- d.node_name.to_s + (d.first_child ? "" : ": " + format.format(d.node_value))}
42
-
41
+ d.node_name.to_s + (d.first_child ? "" : ": " + format.format(d.node_value))
42
+ }
43
43
  line_width 1
44
44
  end
45
45
  node_label.label do
@@ -1,7 +1,7 @@
1
1
  # = Dendogram
2
2
  # 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.
3
3
  # Uses Protovis API
4
- $:.unshift(File.dirname(__FILE__)+"/../lib")
4
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
5
5
  require 'rubyvis'
6
6
 
7
7
 
@@ -19,7 +19,7 @@ def get_files(path)
19
19
  h
20
20
  end
21
21
 
22
- files=get_files(File.dirname(__FILE__)+"/../")
22
+ files=get_files(File.dirname(__FILE__)+"/../../")
23
23
 
24
24
 
25
25
  vis = Rubyvis::Panel.new do
@@ -1,7 +1,7 @@
1
1
  # = Icicle
2
2
  # An icicle is simply a sunburst transformed from polar to cartesian coordinates. Here we show the various files on Rubyvis package; the color of each cell corresponds to the package, while the area encodes the size of the source code in bytes
3
3
  # Uses Protovis API
4
- $:.unshift(File.dirname(__FILE__)+"/../lib")
4
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
5
5
  require 'rubyvis'
6
6
 
7
7
  def get_files(path)
@@ -18,7 +18,7 @@ def get_files(path)
18
18
  h
19
19
  end
20
20
 
21
- files=get_files(File.dirname(__FILE__)+"/../")
21
+ files=get_files(File.dirname(__FILE__)+"/../../")
22
22
 
23
23
  colors=Rubyvis::Colors.category19
24
24
  vis = Rubyvis::Panel.new.
@@ -3,7 +3,7 @@
3
3
  # In addition, the indent layout allows rapid scanning of node labels, and multivariate data such as file size can be displayed adjacent to the hierarchy.
4
4
  #
5
5
  # Uses Protovis API
6
- $:.unshift(File.dirname(__FILE__)+"/../lib")
6
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
7
7
  require 'rubyvis'
8
8
 
9
9
 
@@ -21,7 +21,7 @@ def get_files(path)
21
21
  h
22
22
  end
23
23
 
24
- files=get_files(File.dirname(__FILE__)+"/../")
24
+ files=get_files(File.dirname(__FILE__)+"/../../")
25
25
 
26
26
 
27
27
  root = Rubyvis.dom(files)
@@ -0,0 +1,52 @@
1
+ # = Node-Link Trees
2
+ # The tree layout implements the Reingold-Tilford algorithm for efficient, tidy arrangement of layered nodes. This node-link diagram is similar to the dendrogram, except the depth of nodes is computed by distance from the root, leading to a ragged appearance. Cartesian orientations are also supported.
3
+
4
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
5
+ require 'rubyvis'
6
+
7
+ def get_files(path)
8
+ h={}
9
+ Dir.glob("#{path}/*").each {|e|
10
+ next if File.expand_path(e)=~/pkg|web|vendor|doc|~/
11
+ pa=File.expand_path(e)
12
+ if File.stat(pa).directory?
13
+ h[File.basename(pa)]=get_files(pa)
14
+ else
15
+ h[File.basename(pa)]=File.stat(pa).size
16
+ end
17
+ }
18
+ h
19
+ end
20
+
21
+
22
+
23
+ files=get_files(File.dirname(__FILE__)+"/../../")
24
+ #files={:b=>{:c=>1,:d=>2}}
25
+
26
+
27
+ vis = Rubyvis::Panel.new()
28
+ .width(800)
29
+ .height(800)
30
+ .left(0)
31
+ .right(0)
32
+ .top(0)
33
+ .bottom(0)
34
+
35
+ tree = vis.add(Rubyvis::Layout::Tree).
36
+ nodes(Rubyvis.dom(files).root("rubyvis").nodes()).
37
+ orient('radial').
38
+ depth(85).
39
+ breadth(12)
40
+
41
+ tree.link.add(Rubyvis::Line)
42
+
43
+ tree.node.add(Rubyvis::Dot).
44
+ fill_style(lambda {|n| n.first_child ? "#aec7e8" : "#ff7f0e"}).
45
+ title(lambda {|n| n.node_name})
46
+
47
+ tree.node_label.add(Rubyvis::Label).
48
+ visible(lambda {|n| n.first_child})
49
+
50
+
51
+ vis.render
52
+ puts vis.to_svg
@@ -2,7 +2,7 @@
2
2
  # A sunburst is an adjacency diagram: a space-filling variant of the node-link diagram. Rather than drawing a link between parent and child in the hierarchy, nodes are drawn as solid areas (either wedges or bars), and their placement relative to adjacent nodes reveals their position in the hierarchy. Because the nodes are now space-filling, we can use an angle encoding for the size of software files. This reveals an additional dimension that would be difficult to show in a node-link diagram.
3
3
  # This example show files and directory inside rubyvis lib directory and uses RBP API
4
4
 
5
- $:.unshift(File.dirname(__FILE__)+"/../lib")
5
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
6
6
  require 'rubyvis'
7
7
 
8
8
  def get_files(path)
@@ -19,7 +19,7 @@ def get_files(path)
19
19
  h
20
20
  end
21
21
 
22
- files=get_files(File.dirname(__FILE__)+"/../lib/rubyvis/")
22
+ files=get_files(File.dirname(__FILE__)+"/../../lib/rubyvis/")
23
23
 
24
24
  #load(File.dirname(__FILE__)+"/treemap/treemap_data.rb")
25
25
 
@@ -0,0 +1,48 @@
1
+ # = Treemap
2
+ # Introduced by Ben Shneiderman in 1991, a treemap recursively subdivides area into rectangles. As with adjacency diagrams, the size of any node in the tree is quickly revealed. This example uses color to encode different packages of the rubyvis package, and area to encode file size. “Squarified” treemaps use approximately square rectangles, which offer better readability and size estimation than naive “slice-and-dice” subdivision.
3
+ # Fancier algorithms such as "Voronoi":http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.102.6281&rep=rep1&type=pdf and "jigsaw":http://www.research.ibm.com/visual/papers/158-wattenberg-final3.pdf treemaps also exist but are less common.
4
+
5
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
6
+ require 'rubyvis'
7
+
8
+ def get_files(path)
9
+ h={}
10
+ Dir.glob("#{path}/*").each {|e|
11
+ next if File.expand_path(e)=~/pkg|web|vendor|doc|~/
12
+ pa=File.expand_path(e)
13
+ if File.stat(pa).directory?
14
+ h[File.basename(pa)]=get_files(pa)
15
+ else
16
+ h[File.basename(pa)]=File.stat(pa).size
17
+ end
18
+ }
19
+ h
20
+ end
21
+
22
+ files=get_files(File.dirname(__FILE__)+"/../../")
23
+
24
+ format=Rubyvis::Format.number
25
+ color = pv.Colors.category20
26
+ nodes = pv.dom(files).root("rubyvis").nodes
27
+
28
+
29
+ vis = pv.Panel.new()
30
+ .width(600)
31
+ .height(1000)
32
+
33
+ treemap = vis.add(Rubyvis::Layout::Treemap).
34
+ nodes(nodes).mode("squarify").round(true)
35
+
36
+ treemap.leaf.add(Rubyvis::Panel).
37
+ fill_style(lambda{|d|
38
+ color.scale(d.parent_node.node_name)}).
39
+ stroke_style("#fff").
40
+ line_width(1).
41
+ antialias(false).
42
+ title(lambda {|d| d.node_name+" "+format.format(d.node_value)})
43
+
44
+ treemap.node_label.add(Rubyvis::Label).
45
+ text_style(lambda {|d| pv.rgb(0, 0, 0, 1)})
46
+
47
+ vis.render
48
+ puts vis.to_svg
@@ -30,7 +30,7 @@ require 'rubyvis/mark/shorcut_methods'
30
30
  module Rubyvis
31
31
  @document=nil
32
32
  # Rubyvis version
33
- VERSION = '0.3.3'
33
+ VERSION = '0.3.4'
34
34
  # Protovis API on which current Rubyvis is based
35
35
  PROTOVIS_API_VERSION='3.3'
36
36
  # You actually can do it! http://snipplr.com/view/2137/uses-for-infinity-in-ruby/
@@ -115,6 +115,12 @@ module Rubyvis
115
115
  attr_accessor :_p
116
116
  attr_accessor :n
117
117
 
118
+ ##
119
+ # Created for Tree
120
+
121
+ attr_accessor :ancestor, :prelim, :mod, :change, :shift, :number, :thread
122
+
123
+
118
124
  # Constructs a DOM node for the specified value. Instances of this class are
119
125
  # not typically created directly; instead they are generated from a JavaScript
120
126
  # map using the {@link pv.Dom} operator.
@@ -228,7 +234,16 @@ module Rubyvis
228
234
  block.call(n,i) if moment==:after
229
235
  end
230
236
  private :visit_visit
231
-
237
+ # Yield block on each child
238
+ # Replaces the javascript formula
239
+ # for (var c = o.first_child; c; c = c.nextSibling)
240
+ def each_child
241
+ c=@first_child
242
+ while c
243
+ yield c
244
+ c=c.next_sibling
245
+ end
246
+ end
232
247
  # Visits each node in the tree in preorder traversal, applying the specified
233
248
  # proc <i>block</i>. The arguments to the function are:<ol>
234
249
  #