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
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,11 @@
1
+ === 0.3.4 / 2010-12-11
2
+
3
+ * Implemented Layout::Grid and Layout::Tree
4
+ * New example: census treemap. Added spec for layout
5
+ * Examples reordered
6
+ * Bug fix: Area with 0 on height create infinite loop
7
+ * Bug fix: Layout::Pack overlaps circles on NE position
8
+
1
9
  === 0.3.3 / 2010-11-23
2
10
 
3
11
  * Implemented Rubyvis::Layout::Pack, Rubyvis::Layout::Indent and Rubyvis::Flatten
@@ -2,42 +2,48 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- examples/antibiotics/antibiotics_data.rb
6
- examples/antibiotics/antibiotics_scatter.rb
7
- examples/antibiotics/antibiotics_wedge.rb
8
- examples/area.rb
9
- examples/area_interpolation.rb
10
- examples/bar_column_chart.rb
11
- examples/barley/barley.rb
12
- examples/barley/barley_data.rb
13
- examples/bubble_charts.rb
14
- examples/cars/cars.rb
15
- examples/cars/cars_data.rb
16
- examples/circle_packing.rb
17
- examples/crimea/crimea_data.rb
18
- examples/crimea/crimea_grouped_bar.rb
19
- examples/crimea/crimea_line.rb
20
- examples/dendogram.rb
21
- examples/dot.rb
22
- examples/first_protovis_api.rb
23
- examples/first_rbp_api.rb
24
- examples/fixtures/tipsy.gif
25
- examples/grouped_charts.rb
26
- examples/icicle.rb
27
- examples/image.rb
28
- examples/indent.rb
29
- examples/line.rb
30
- examples/line_and_step.rb
31
- examples/line_interpolation.rb
32
- examples/nested_grid.rb
33
- examples/pie_and_donut.rb
34
- examples/scatterplot.rb
35
- examples/second.rb
36
- examples/stacked_charts.rb
37
- examples/sunburst.rb
38
- examples/third.rb
39
- examples/treemap/treemap.rb
40
- examples/treemap/treemap_data.rb
5
+ examples/1_basic/1a_bar_rbp_api.rb
6
+ examples/1_basic/1b_bar_pv_api.rb
7
+ examples/1_basic/2_bar_and_rule.rb
8
+ examples/1_basic/3_grouped_bars.rb
9
+ examples/1_basic/area_interpolation.rb
10
+ examples/1_basic/dot.rb
11
+ examples/1_basic/fixtures/tipsy.gif
12
+ examples/1_basic/grid.rb
13
+ examples/1_basic/image.rb
14
+ examples/1_basic/line.rb
15
+ examples/1_basic/line_interpolation.rb
16
+ examples/2_medium/censo_agropecuario/censo_agropecuario_chile_data.rb
17
+ examples/2_medium/censo_agropecuario/census_treemap.rb
18
+ examples/2_medium/censo_agropecuario/create_data.rb
19
+ examples/2_medium/censo_agropecuario/resultset.csv
20
+ examples/2_medium/nested_grid.rb
21
+ examples/3_pv_conventional/area.rb
22
+ examples/3_pv_conventional/bar_column_chart.rb
23
+ examples/3_pv_conventional/grouped_charts.rb
24
+ examples/3_pv_conventional/line_and_step.rb
25
+ examples/3_pv_conventional/pie_and_donut.rb
26
+ examples/3_pv_conventional/scatterplot.rb
27
+ examples/3_pv_conventional/stacked_charts.rb
28
+ examples/4_pv_custom/antibiotics/antibiotics_data.rb
29
+ examples/4_pv_custom/antibiotics/antibiotics_scatter.rb
30
+ examples/4_pv_custom/antibiotics/antibiotics_wedge.rb
31
+ examples/4_pv_custom/barley/barley.rb
32
+ examples/4_pv_custom/barley/barley_data.rb
33
+ examples/4_pv_custom/cars/cars.rb
34
+ examples/4_pv_custom/cars/cars_data.rb
35
+ examples/4_pv_custom/crimea/crimea_data.rb
36
+ examples/4_pv_custom/crimea/crimea_grouped_bar.rb
37
+ examples/4_pv_custom/crimea/crimea_line.rb
38
+ examples/5_pv_hierarchies/bubble_charts.rb
39
+ examples/5_pv_hierarchies/bubble_charts_matrix.rb
40
+ examples/5_pv_hierarchies/circle_packing.rb
41
+ examples/5_pv_hierarchies/dendogram.rb
42
+ examples/5_pv_hierarchies/icicle.rb
43
+ examples/5_pv_hierarchies/indent.rb
44
+ examples/5_pv_hierarchies/node_link_tree.rb
45
+ examples/5_pv_hierarchies/sunburst.rb
46
+ examples/5_pv_hierarchies/treemap.rb
41
47
  lib/rubyvis.rb
42
48
  lib/rubyvis/color/color.rb
43
49
  lib/rubyvis/color/colors.rb
@@ -51,12 +57,14 @@ lib/rubyvis/internals.rb
51
57
  lib/rubyvis/javascript_behaviour.rb
52
58
  lib/rubyvis/layout.rb
53
59
  lib/rubyvis/layout/cluster.rb
60
+ lib/rubyvis/layout/grid.rb
54
61
  lib/rubyvis/layout/hierarchy.rb
55
62
  lib/rubyvis/layout/indent.rb
56
63
  lib/rubyvis/layout/network.rb
57
64
  lib/rubyvis/layout/pack.rb
58
65
  lib/rubyvis/layout/partition.rb
59
66
  lib/rubyvis/layout/stack.rb
67
+ lib/rubyvis/layout/tree.rb
60
68
  lib/rubyvis/layout/treemap.rb
61
69
  lib/rubyvis/mark.rb
62
70
  lib/rubyvis/mark/anchor.rb
@@ -98,6 +106,7 @@ spec/histogram_spec.rb
98
106
  spec/internal_spec.rb
99
107
  spec/javascript_behaviour_spec.rb
100
108
  spec/label_spec.rb
109
+ spec/layout_stack_spec.rb
101
110
  spec/line_spec.rb
102
111
  spec/mark_spec.rb
103
112
  spec/nest_spec.rb
@@ -2,7 +2,7 @@
2
2
  # This is the RBP API version of "Getting Started" example of Protovis introduction.
3
3
  # On this example we build a bar chart using panel and bar marks.
4
4
  # A mark represents a set of graphical elements that share data and visual encodings. Although marks are simple by themselves, you can combine them in interesting ways to make rich, interactive visualizations
5
- $:.unshift(File.dirname(__FILE__)+"/../lib")
5
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
6
6
  require 'rubyvis'
7
7
 
8
8
  vis = Rubyvis::Panel.new do
@@ -2,7 +2,7 @@
2
2
  # This is the protovis API version of "Getting Started" example of Protovis introduction.
3
3
  # On this example we build a bar chart using panel and bar marks.
4
4
  # A mark represents a set of graphical elements that share data and visual encodings. Although marks are simple by themselves, you can combine them in interesting ways to make rich, interactive visualizations
5
- $:.unshift(File.dirname(__FILE__)+"/../lib")
5
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
6
6
  require 'rubyvis'
7
7
  vis = Rubyvis::Panel.new.width(150).height(150);
8
8
 
@@ -1,7 +1,7 @@
1
1
  # = Inheritance and labels
2
2
  # Second example of Protovis "Getting Started section"
3
- # The rules label inherits the data and bottom property, causing it to appear on the rule and render the value (datum) as text. The bar’s label uses the bottom anchor to tweak positioning, so that the label is centered at the bottom of the bar.
4
- $:.unshift(File.dirname(__FILE__)+"/../lib")
3
+ # The rule's label inherits the data and bottom property, causing it to appear on the rule and render the value (datum) as text. The bar’s label uses the bottom anchor to tweak positioning, so that the label is centered at the bottom of the bar.
4
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
5
5
  require 'rubyvis'
6
6
 
7
7
  vis = pv.Panel.new()
@@ -1,6 +1,6 @@
1
1
  # = Using parent
2
2
  # This example shows how to group bars on groups and use the parent property to identify and color them
3
- $:.unshift(File.dirname(__FILE__)+"/../lib")
3
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
4
4
  require 'rubyvis'
5
5
 
6
6
  vis = pv.Panel.new().width(200).height(150);
@@ -7,7 +7,7 @@
7
7
  # * cardinal
8
8
  #
9
9
  # See also "Line Interpolation":line_interpolation.html
10
- $:.unshift(File.dirname(__FILE__)+"/../lib")
10
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
11
11
  require 'rubyvis'
12
12
 
13
13
  data = Rubyvis.range(0, 10, 0.5).map {|x|
@@ -1,6 +1,6 @@
1
1
  # = Dot and anchors
2
2
  # This example shows how looks differents positions of anchors on dots
3
- $:.unshift(File.dirname(__FILE__)+"/../lib")
3
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
4
4
  require 'rubyvis'
5
5
 
6
6
  vis = pv.Panel.new().width(200).height(200);
@@ -0,0 +1,29 @@
1
+ # = Grid
2
+ # A simple heatmap, using a Bar.fill_style to represent
3
+ # data
4
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
5
+ require 'rubyvis'
6
+
7
+ w = 400
8
+ h = 400
9
+
10
+ vis = pv.Panel.new()
11
+ .width(w)
12
+ .height(h)
13
+ .bottom(0)
14
+ .left(0)
15
+ .right(0)
16
+ .top(0)
17
+
18
+ arrays=10.times.map {|i| 10.times.map {|j| i/10.0+j/100.0}}
19
+
20
+ vis.add(Rubyvis::Layout::Grid).rows(arrays).
21
+ cell.add(Rubyvis::Bar).
22
+ fill_style(Rubyvis.ramp("white", "black")).anchor("center").
23
+ add(Rubyvis::Label).
24
+ text_style(Rubyvis.ramp("black","white"))
25
+
26
+ vis.render();
27
+
28
+
29
+ puts vis.to_svg
@@ -1,6 +1,6 @@
1
1
  # = Image
2
2
  # This example shows how to include an image
3
- $:.unshift(File.dirname(__FILE__)+"/../lib")
3
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
4
4
  require 'rubyvis'
5
5
 
6
6
  img_url="fixtures/tipsy.gif"
@@ -1,7 +1,7 @@
1
1
  # = Line Chart
2
2
  # This line chart is constructed a Line mark.
3
3
  # The second line, inside the first one, is created using an anchor.
4
- $:.unshift(File.dirname(__FILE__)+"/../lib")
4
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
5
5
  require 'rubyvis'
6
6
 
7
7
  data = pv.range(0, 10, 0.1).map {|x|
@@ -9,7 +9,7 @@
9
9
  # * cardinal
10
10
  #
11
11
  # See also "Area Interpolation":area_interpolation.html
12
- $:.unshift(File.dirname(__FILE__)+"/../lib")
12
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
13
13
  require 'rubyvis'
14
14
 
15
15
  data = pv.range(0, 10, 1).map {|x|
@@ -0,0 +1,53 @@
1
+ # encoding: UTF-8
2
+ $censo = [
3
+ {:glosa=>"Alto Bío-Bío", :te=>1, :superficie=>161659.68, :ovinos=>8092, :bovinos=>7736},
4
+ {:glosa=>"Alto Bío-Bío", :te=>2, :superficie=>44214.8, :ovinos=>881, :bovinos=>1327},
5
+ {:glosa=>"Alto Bío-Bío", :te=>3, :superficie=>0, :ovinos=>45, :bovinos=>45},
6
+ {:glosa=>"Alto Bío-Bío", :te=>5, :superficie=>12451.1, :ovinos=>0, :bovinos=>0},
7
+ {:glosa=>"Antuco", :te=>1, :superficie=>67807.4, :ovinos=>1211, :bovinos=>1993},
8
+ {:glosa=>"Antuco", :te=>2, :superficie=>9449.69, :ovinos=>22, :bovinos=>57},
9
+ {:glosa=>"Antuco", :te=>3, :superficie=>0, :ovinos=>0, :bovinos=>0},
10
+ {:glosa=>"Antuco", :te=>5, :superficie=>12883, :ovinos=>0, :bovinos=>0},
11
+ {:glosa=>"Cabrero", :te=>1, :superficie=>33278.04, :ovinos=>1383, :bovinos=>16849},
12
+ {:glosa=>"Cabrero", :te=>2, :superficie=>26802.78, :ovinos=>5, :bovinos=>135},
13
+ {:glosa=>"Cabrero", :te=>3, :superficie=>0, :ovinos=>0, :bovinos=>0},
14
+ {:glosa=>"Laja", :te=>1, :superficie=>16540.64, :ovinos=>1953, :bovinos=>5818},
15
+ {:glosa=>"Laja", :te=>2, :superficie=>12741.56, :ovinos=>0, :bovinos=>52},
16
+ {:glosa=>"Laja", :te=>3, :superficie=>0, :ovinos=>0, :bovinos=>166},
17
+ {:glosa=>"Laja", :te=>4, :superficie=>0.1, :ovinos=>0, :bovinos=>0},
18
+ {:glosa=>"Los Angeles", :te=>1, :superficie=>120432.71, :ovinos=>3640, :bovinos=>87098},
19
+ {:glosa=>"Los Angeles", :te=>2, :superficie=>20205.1, :ovinos=>13, :bovinos=>219},
20
+ {:glosa=>"Los Angeles", :te=>3, :superficie=>0, :ovinos=>0, :bovinos=>9},
21
+ {:glosa=>"Los Angeles", :te=>4, :superficie=>19.4, :ovinos=>0, :bovinos=>0},
22
+ {:glosa=>"Mulchén", :te=>1, :superficie=>87515.1, :ovinos=>5472, :bovinos=>28562},
23
+ {:glosa=>"Mulchén", :te=>2, :superficie=>101300.3, :ovinos=>149, :bovinos=>279},
24
+ {:glosa=>"Mulchén", :te=>3, :superficie=>0, :ovinos=>22, :bovinos=>41},
25
+ {:glosa=>"Mulchén", :te=>4, :superficie=>10, :ovinos=>0, :bovinos=>0},
26
+ {:glosa=>"Nacimiento", :te=>1, :superficie=>25258.2, :ovinos=>2535, :bovinos=>4027},
27
+ {:glosa=>"Nacimiento", :te=>2, :superficie=>47295.23, :ovinos=>155, :bovinos=>266},
28
+ {:glosa=>"Nacimiento", :te=>3, :superficie=>0, :ovinos=>0, :bovinos=>3},
29
+ {:glosa=>"Negrete", :te=>1, :superficie=>10213.42, :ovinos=>564, :bovinos=>7424},
30
+ {:glosa=>"Negrete", :te=>2, :superficie=>1875.2, :ovinos=>0, :bovinos=>0},
31
+ {:glosa=>"Negrete", :te=>3, :superficie=>0, :ovinos=>0, :bovinos=>42},
32
+ {:glosa=>"Quilaco", :te=>1, :superficie=>21624.2, :ovinos=>5078, :bovinos=>5765},
33
+ {:glosa=>"Quilaco", :te=>2, :superficie=>70669.92, :ovinos=>71, :bovinos=>428},
34
+ {:glosa=>"Quilaco", :te=>3, :superficie=>0, :ovinos=>135, :bovinos=>359},
35
+ {:glosa=>"Quilaco", :te=>4, :superficie=>18.1, :ovinos=>0, :bovinos=>0},
36
+ {:glosa=>"Quilleco", :te=>1, :superficie=>46422.6399999999, :ovinos=>8635, :bovinos=>17881},
37
+ {:glosa=>"Quilleco", :te=>2, :superficie=>51873.11, :ovinos=>99, :bovinos=>161},
38
+ {:glosa=>"Quilleco", :te=>4, :superficie=>1089.7, :ovinos=>0, :bovinos=>0},
39
+ {:glosa=>"San Rosendo", :te=>1, :superficie=>3101.07, :ovinos=>52, :bovinos=>314},
40
+ {:glosa=>"San Rosendo", :te=>2, :superficie=>4809.14, :ovinos=>0, :bovinos=>10},
41
+ {:glosa=>"Santa Bárbara", :te=>1, :superficie=>91126.6000000003, :ovinos=>9540, :bovinos=>15316},
42
+ {:glosa=>"Santa Bárbara", :te=>2, :superficie=>30337.87, :ovinos=>273, :bovinos=>678},
43
+ {:glosa=>"Santa Bárbara", :te=>3, :superficie=>0, :ovinos=>12, :bovinos=>37},
44
+ {:glosa=>"Santa Bárbara", :te=>4, :superficie=>45.5, :ovinos=>0, :bovinos=>0},
45
+ {:glosa=>"Tucapel", :te=>1, :superficie=>76164.0399999999, :ovinos=>8941, :bovinos=>5436},
46
+ {:glosa=>"Tucapel", :te=>2, :superficie=>46603.55, :ovinos=>12, :bovinos=>60},
47
+ {:glosa=>"Tucapel", :te=>3, :superficie=>0, :ovinos=>18, :bovinos=>16},
48
+ {:glosa=>"Tucapel", :te=>4, :superficie=>7.8, :ovinos=>0, :bovinos=>0},
49
+ {:glosa=>"Yumbel", :te=>1, :superficie=>31260.98, :ovinos=>1462, :bovinos=>7899},
50
+ {:glosa=>"Yumbel", :te=>2, :superficie=>25284.95, :ovinos=>1, :bovinos=>52},
51
+ {:glosa=>"Yumbel", :te=>3, :superficie=>0, :ovinos=>3, :bovinos=>167},
52
+ {:glosa=>"Yumbel", :te=>4, :superficie=>7.1, :ovinos=>0, :bovinos=>0}
53
+ ]
@@ -0,0 +1,63 @@
1
+ # encoding: UTF-8
2
+ # = Censo Agropecuario 2007, Chile: Treemap
3
+ # This treemap represents farm explotations on Biobío province, Chile.
4
+ # Colors represent different 'comunas' and bar inside one color
5
+ # represent different types of explotation
6
+ $:.unshift(File.dirname(__FILE__)+"/../../../lib")
7
+ require 'rubyvis'
8
+ load(File.dirname(__FILE__)+"/censo_agropecuario_chile_data.rb")
9
+
10
+ w = 500
11
+ h = 500
12
+ max_s=30
13
+
14
+ c_p_c={}
15
+
16
+ te = {
17
+ 1=>"Explotación agropecuaria con actividad",
18
+ 2=>"Explotación forestal",
19
+ 3=>"Explotación agropecuaria sin tierra",
20
+ 4=>"Explotación agropecuaria temporalmente sin actividad",
21
+ 5=>"Parques nacionales y reservas forestales"}
22
+
23
+ number=Rubyvis::Format.number
24
+ color=Rubyvis::Colors.category20
25
+
26
+ $censo.each_with_index do |c,i|
27
+ c_p_c[c[:glosa]]||=Hash.new
28
+ c_p_c[c[:glosa]][c[:te]]=OpenStruct.new(c)
29
+ end
30
+
31
+
32
+
33
+ nodes = pv.dom(c_p_c).root("censo").nodes
34
+
35
+ # The root panel.
36
+ vis = pv.Panel.new()
37
+ .width(w)
38
+ .height(h)
39
+ .bottom(20)
40
+ .left(30)
41
+ .right(10)
42
+ .top(5);
43
+
44
+ treemap = vis.add(Rubyvis::Layout::Treemap).
45
+ nodes(nodes).mode("squarify").round(true).
46
+ size(lambda {|d| d.node_value.superficie})
47
+
48
+ treemap.leaf.add(Rubyvis::Panel).
49
+ fill_style(lambda{|d|
50
+ color.scale(d.node_value.glosa)}).
51
+ stroke_style("#fff").
52
+ line_width(1).
53
+ antialias(false).
54
+ title(lambda {|d| d.parent_node ? d.node_value.glosa+"-#{te[d.node_value.te]}" : ""})
55
+
56
+ treemap.node_label.add(Rubyvis::Label).
57
+ text_style(lambda {|d| pv.rgb(0, 0, 0, 1)}).
58
+ visible(lambda {|d| d.node_value and d.node_value.superficie>200}).
59
+ text(lambda {|d| number.format(d.node_value.superficie.to_i)})
60
+
61
+
62
+ vis.render()
63
+ puts vis.to_svg
@@ -0,0 +1,10 @@
1
+ require 'statsample'
2
+ a=Statsample::CSV.read('resultset.csv')
3
+ File.open("censo_agropecuario_chile_data.rb","w") do |fp|
4
+ fp.puts "# encoding: UTF-8"
5
+ fp.puts "$censo = ["
6
+ a.each do |row|
7
+ fp.puts row.inject({}) {|ac,v| ac[v[0].to_sym]=v[1];ac}.inspect+","
8
+ end
9
+ fp.puts "]"
10
+ end
@@ -0,0 +1,51 @@
1
+ "glosa","te","superficie","ovinos","bovinos"
2
+ "Alto Bío-Bío",1,161659.68,8092,7736
3
+ "Alto Bío-Bío",2,44214.8,881,1327
4
+ "Alto Bío-Bío",3,0,45,45
5
+ "Alto Bío-Bío",5,12451.1,0,0
6
+ "Antuco",1,67807.4,1211,1993
7
+ "Antuco",2,9449.69,22,57
8
+ "Antuco",3,0,0,0
9
+ "Antuco",5,12883,0,0
10
+ "Cabrero",1,33278.04,1383,16849
11
+ "Cabrero",2,26802.78,5,135
12
+ "Cabrero",3,0,0,0
13
+ "Laja",1,16540.64,1953,5818
14
+ "Laja",2,12741.56,0,52
15
+ "Laja",3,0,0,166
16
+ "Laja",4,0.1,0,0
17
+ "Los Angeles",1,120432.71,3640,87098
18
+ "Los Angeles",2,20205.1,13,219
19
+ "Los Angeles",3,0,0,9
20
+ "Los Angeles",4,19.4,0,0
21
+ "Mulchén",1,87515.1,5472,28562
22
+ "Mulchén",2,101300.3,149,279
23
+ "Mulchén",3,0,22,41
24
+ "Mulchén",4,10,0,0
25
+ "Nacimiento",1,25258.2,2535,4027
26
+ "Nacimiento",2,47295.23,155,266
27
+ "Nacimiento",3,0,0,3
28
+ "Negrete",1,10213.42,564,7424
29
+ "Negrete",2,1875.2,0,0
30
+ "Negrete",3,0,0,42
31
+ "Quilaco",1,21624.2,5078,5765
32
+ "Quilaco",2,70669.92,71,428
33
+ "Quilaco",3,0,135,359
34
+ "Quilaco",4,18.1,0,0
35
+ "Quilleco",1,46422.6399999999,8635,17881
36
+ "Quilleco",2,51873.11,99,161
37
+ "Quilleco",4,1089.7,0,0
38
+ "San Rosendo",1,3101.07,52,314
39
+ "San Rosendo",2,4809.14,0,10
40
+ "Santa Bárbara",1,91126.6000000003,9540,15316
41
+ "Santa Bárbara",2,30337.87,273,678
42
+ "Santa Bárbara",3,0,12,37
43
+ "Santa Bárbara",4,45.5,0,0
44
+ "Tucapel",1,76164.0399999999,8941,5436
45
+ "Tucapel",2,46603.55,12,60
46
+ "Tucapel",3,0,18,16
47
+ "Tucapel",4,7.8,0,0
48
+ "Yumbel",1,31260.98,1462,7899
49
+ "Yumbel",2,25284.95,1,52
50
+ "Yumbel",3,0,3,167
51
+ "Yumbel",4,7.1,0,0
@@ -1,8 +1,7 @@
1
1
  # = Nested grid
2
- # Two level nested grid.
3
- # The first is created at random with n rows and m columns
4
- # The second level is a 9x9 grid inside the cell of first level
5
- $:.unshift(File.dirname(__FILE__)+"/../lib")
2
+ # Two level nested grid. The first is created at random with n rows and m columns The second level is a 9x9 grid inside the cell of first level
3
+ # You can obtain the same result using a grid layout
4
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
6
5
  require 'rubyvis'
7
6
 
8
7
 
@@ -3,7 +3,7 @@
3
3
  # Although this example is basic, it provides a good starting point for adding more complex features. For instance, multiple series of data can be added to produce a stacked area chart.
4
4
  # * "Protovis version":http://vis.stanford.edu/protovis/ex/area.html
5
5
  # * Syntax: RBP
6
- $:.unshift(File.dirname(__FILE__)+"/../lib")
6
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
7
7
  require 'rubyvis'
8
8
 
9
9
  data = pv.range(0, 10, 0.1).map {|x|
@@ -2,7 +2,7 @@
2
2
  # This simple bar chart is constructed using a bar mark. A linear scale is used to compute the width of the bar, while an ordinal scale sets the top position and height for the categorical dimension. Next, rules and labels are added for reference values.
3
3
  # Bars can be used in a variety of ways. For instance, they can be stacked or grouped to show multiple data series, or arranged as vertical columns rather than bars.
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(10).map {|d| rand + 0.1 }