rubyvis 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +13 -1
  3. data/Manifest.txt +19 -0
  4. data/examples/antibiotics/antibiotics.rb +96 -0
  5. data/examples/antibiotics/antibiotics_data.rb +20 -0
  6. data/examples/area.rb +103 -0
  7. data/examples/bar_column_chart.rb +55 -0
  8. data/examples/barley/barley.rb +29 -19
  9. data/examples/barley/barley_data.rb +122 -0
  10. data/examples/crimea/crimea_grouped_bar.rb +59 -0
  11. data/examples/dot.rb +19 -0
  12. data/examples/first.rb +1 -6
  13. data/examples/line.rb +84 -0
  14. data/examples/pie_and_donut.rb +38 -0
  15. data/examples/scatterplot.rb +55 -0
  16. data/examples/second.rb +3 -4
  17. data/examples/third.rb +1 -1
  18. data/lib/rubyvis.rb +3 -1
  19. data/lib/rubyvis/color/color.rb +31 -3
  20. data/lib/rubyvis/color/colors.rb +3 -3
  21. data/lib/rubyvis/format/number.rb +80 -10
  22. data/lib/rubyvis/internals.rb +11 -5
  23. data/lib/rubyvis/javascript_behaviour.rb +1 -0
  24. data/lib/rubyvis/mark.rb +43 -20
  25. data/lib/rubyvis/mark/anchor.rb +1 -1
  26. data/lib/rubyvis/mark/area.rb +15 -13
  27. data/lib/rubyvis/mark/bar.rb +2 -2
  28. data/lib/rubyvis/mark/dot.rb +85 -0
  29. data/lib/rubyvis/mark/label.rb +1 -1
  30. data/lib/rubyvis/mark/line.rb +7 -6
  31. data/lib/rubyvis/mark/panel.rb +0 -1
  32. data/lib/rubyvis/mark/rule.rb +5 -4
  33. data/lib/rubyvis/mark/wedge.rb +124 -0
  34. data/lib/rubyvis/nest.rb +158 -0
  35. data/lib/rubyvis/scale.rb +4 -0
  36. data/lib/rubyvis/scale/log.rb +55 -0
  37. data/lib/rubyvis/scale/ordinal.rb +34 -11
  38. data/lib/rubyvis/scale/quantitative.rb +17 -3
  39. data/lib/rubyvis/scene/svg_area.rb +197 -0
  40. data/lib/rubyvis/scene/svg_dot.rb +67 -0
  41. data/lib/rubyvis/scene/svg_label.rb +17 -15
  42. data/lib/rubyvis/scene/svg_line.rb +0 -2
  43. data/lib/rubyvis/scene/svg_rule.rb +2 -2
  44. data/lib/rubyvis/scene/svg_scene.rb +8 -1
  45. data/lib/rubyvis/scene/svg_wedge.rb +56 -0
  46. data/lib/rubyvis/sceneelement.rb +2 -1
  47. data/spec/bar_spec.rb +27 -3
  48. data/spec/label_spec.rb +1 -1
  49. data/spec/nest_spec.rb +41 -0
  50. data/spec/panel_spec.rb +1 -1
  51. data/spec/scale_linear_spec.rb +2 -2
  52. data/spec/scale_ordinal_spec.rb +81 -0
  53. data/spec/spec.opts +0 -1
  54. metadata +24 -3
  55. metadata.gz.sig +0 -0
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,4 +1,16 @@
1
- === 0.1.2 / 2010-10-04
1
+ === 0.1.3 / 2010-10-08
2
+
3
+ * New Wedge and Dot mark
4
+ * New Log scale and Nest.
5
+ * Area mark working.
6
+ * Automatic color scales doesn't work on every ocasion, yet
7
+ * Color, Format::Number and Quantitative fixed.
8
+ * Fixed attributes works as expected (damn c like 0=false)
9
+ * Added examples (antibiotics and barley)
10
+ * Bug fix: right anchor doesn't affect labels.
11
+ * Crimea grouped bars works. Ordinal scales operational
12
+
13
+ === 0.1.2 / 2010-10-04
2
14
 
3
15
  * Bug fix: SvgScene.panel only parse first element. Crimea-line example works (almost) as expected
4
16
  * Support for lines as anchors (not tested, yet)
data/Manifest.txt CHANGED
@@ -2,10 +2,20 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
+ examples/antibiotics/antibiotics.rb
6
+ examples/antibiotics/antibiotics_data.rb
7
+ examples/area.rb
8
+ examples/bar_column_chart.rb
5
9
  examples/barley/barley.rb
10
+ examples/barley/barley_data.rb
6
11
  examples/crimea/crimea.rb
12
+ examples/crimea/crimea_grouped_bar.rb
7
13
  examples/crimea/crimea_line.rb
14
+ examples/dot.rb
8
15
  examples/first.rb
16
+ examples/line.rb
17
+ examples/pie_and_donut.rb
18
+ examples/scatterplot.rb
9
19
  examples/second.rb
10
20
  examples/third.rb
11
21
  lib/rubyvis.rb
@@ -22,21 +32,28 @@ lib/rubyvis/mark.rb
22
32
  lib/rubyvis/mark/anchor.rb
23
33
  lib/rubyvis/mark/area.rb
24
34
  lib/rubyvis/mark/bar.rb
35
+ lib/rubyvis/mark/dot.rb
25
36
  lib/rubyvis/mark/label.rb
26
37
  lib/rubyvis/mark/line.rb
27
38
  lib/rubyvis/mark/panel.rb
28
39
  lib/rubyvis/mark/rule.rb
40
+ lib/rubyvis/mark/wedge.rb
41
+ lib/rubyvis/nest.rb
29
42
  lib/rubyvis/property.rb
30
43
  lib/rubyvis/scale.rb
31
44
  lib/rubyvis/scale/linear.rb
45
+ lib/rubyvis/scale/log.rb
32
46
  lib/rubyvis/scale/ordinal.rb
33
47
  lib/rubyvis/scale/quantitative.rb
48
+ lib/rubyvis/scene/svg_area.rb
34
49
  lib/rubyvis/scene/svg_bar.rb
50
+ lib/rubyvis/scene/svg_dot.rb
35
51
  lib/rubyvis/scene/svg_label.rb
36
52
  lib/rubyvis/scene/svg_line.rb
37
53
  lib/rubyvis/scene/svg_panel.rb
38
54
  lib/rubyvis/scene/svg_rule.rb
39
55
  lib/rubyvis/scene/svg_scene.rb
56
+ lib/rubyvis/scene/svg_wedge.rb
40
57
  lib/rubyvis/sceneelement.rb
41
58
  lib/rubyvis/transform.rb
42
59
  spec/bar_spec.rb
@@ -44,9 +61,11 @@ spec/internal_spec.rb
44
61
  spec/javascript_behaviour_spec.rb
45
62
  spec/label_spec.rb
46
63
  spec/mark_spec.rb
64
+ spec/nest_spec.rb
47
65
  spec/panel_spec.rb
48
66
  spec/scale_linear_datetime_spec.rb
49
67
  spec/scale_linear_spec.rb
68
+ spec/scale_ordinal_spec.rb
50
69
  spec/scale_spec.rb
51
70
  spec/spec.opts
52
71
  spec/spec_helper.rb
@@ -0,0 +1,96 @@
1
+ $:.unshift(File.dirname(__FILE__)+"/../../lib")
2
+ require 'rubyvis'
3
+ load(File.dirname(__FILE__)+"/antibiotics_data.rb")
4
+
5
+ s = 180
6
+ _p = 20
7
+ z = pv.Scale.log(0.001, 1000).range(0, s)
8
+ color = pv.colors("darkred", "darkblue").by(lambda {|d| d[:gram]})
9
+ ticks = pv.range(-2, 3).map {|e| 10**e}
10
+
11
+ #/* Root panel. */
12
+ vis = Rubyvis::Panel.new
13
+ .height(s * $antibiotics.size+ _p * ($antibiotics.size- 1))
14
+ .width(lambda {self.height()})
15
+ .top(14.5)
16
+ .left(14.5)
17
+ .bottom(44)
18
+ .right(14);
19
+
20
+ #/* Cell for each antibiotic pair. */
21
+ cell = vis.add(pv.Panel)
22
+ .data($antibiotics)
23
+ .width(s)
24
+ .left(lambda {(s + _p) * self.index})
25
+ .add(pv.Panel)
26
+ .data($antibiotics)
27
+ .height(s)
28
+ .top(lambda{(s + _p) * self.index})
29
+
30
+ #/* Label. */
31
+ cell.anchor("center").add(pv.Label)
32
+ .visible(lambda {|d, y, x| x == y})
33
+ .font("bold 14px sans-serif")
34
+ .text(lambda {|d, y, x| x});
35
+
36
+ #/* Dot plot and frame. */
37
+ plot = cell.add(pv.Panel)
38
+ .data(lambda {|y, x| [x]})
39
+ .visible(lambda {|x, y| x != y})
40
+ .stroke_style(pv.color("#aaa"));
41
+
42
+ #/* Ticks. */
43
+ tick = pv.Rule.new()
44
+ .visible(lambda {|d, x, y| x != y})
45
+ .data(ticks)
46
+ .stroke_style(pv.color("#ddd"));
47
+
48
+ #/* X-axis ticks. */
49
+ xtick = plot.add(pv.Rule)
50
+ .extend(tick)
51
+ .left(lambda {|d| z.scale(d)});
52
+
53
+ #/* Bottom and top labels. */
54
+ xtick.anchor("bottom").add(pv.Label)
55
+ .visible(lambda {cell.index == $antibiotics.size- 1});
56
+ xtick.anchor("top").add(pv.Label)
57
+ .visible(lambda {cell.index == 0});
58
+
59
+ #/* Y-axis ticks. */
60
+ ytick = plot.add(pv.Rule)
61
+ .extend(tick)
62
+ .bottom(lambda {|d| z.scale(d)});
63
+
64
+ #/* Bottom and top labels. */
65
+ ytick.anchor("right").add(pv.Label)
66
+ .visible(lambda {cell.parent.index == $antibiotics.size- 1})
67
+ .text_angle(Math::PI / 2.0)
68
+ .text_baseline("bottom")
69
+ .text_align("center");
70
+ ytick.anchor("left").add(pv.Label)
71
+ .visible(lambda {cell.parent.index == 0})
72
+ .text_angle(-Math::PI / 2.0)
73
+ .text_baseline("bottom")
74
+ .text_align("center");
75
+
76
+ #/* Dot plot. */
77
+ dot = plot.add(pv.Dot)
78
+ .data($bacteria)
79
+ .stroke_style(pv.color("red"))
80
+ .fill_style(lambda {self.stroke_style()})
81
+ .left(lambda {|d, x, y| z.scale(d[x])})
82
+ .bottom(lambda {|d, x, y| z.scale(d[y])})
83
+ .title(lambda {|d| d[:name]});
84
+
85
+ #/* Legend. */
86
+ vis.add(pv.Dot)
87
+ .extend(dot)
88
+ .data([{gram:"positive"}, {gram:"negative"}])
89
+ .bottom(-30)
90
+ .left(lambda { self.index * 100})
91
+ .title(nil)
92
+ .anchor("right").add(pv.Label)
93
+ .text(lambda {|d| "Gram-" + d[:gram]});
94
+
95
+ vis.render();
96
+ puts vis.to_svg
@@ -0,0 +1,20 @@
1
+ $antibiotics = ["penicillin", "streptomycin", "neomycin"];
2
+
3
+ $bacteria = [
4
+ {name: "Mycobacterium tuberculosis", penicillin: 800, streptomycin: 5, neomycin: 2, gram: "negative"},
5
+ {name: "Salmonella schottmuelleri", penicillin: 10, streptomycin: 0.8, neomycin: 0.09, gram: "negative"},
6
+ {name: "Proteus vulgaris", penicillin: 3, streptomycin: 0.1, neomycin: 0.1, gram: "negative"},
7
+ {name: "Klebsiella pneumoniae", penicillin: 850, streptomycin: 1.2, neomycin: 1, gram: "negative"},
8
+ {name: "Brucella abortus", penicillin: 1, streptomycin: 2, neomycin: 0.02, gram: "negative"},
9
+ {name: "Pseudomonas aeruginosa", penicillin: 850, streptomycin: 2, neomycin: 0.4, gram: "negative"},
10
+ {name: "Escherichia coli", penicillin: 100, streptomycin: 0.4, neomycin: 0.1, gram: "negative"},
11
+ {name: "Salmonella (Eberthella) typhosa", penicillin: 1, streptomycin: 0.4, neomycin: 0.008, gram: "negative"},
12
+ {name: "Aerobacter aerogenes", penicillin: 870, streptomycin: 1, neomycin: 1.6, gram: "negative"},
13
+ {name: "Brucella antracis", penicillin: 0.001, streptomycin: 0.01, neomycin: 0.007, gram: "positive"},
14
+ {name: "Streptococcus fecalis", penicillin: 1, streptomycin: 1, neomycin: 0.1, gram: "positive"},
15
+ {name: "Staphylococcus aureus", penicillin: 0.03, streptomycin: 0.03, neomycin: 0.001, gram: "positive"},
16
+ {name: "Staphylococcus albus", penicillin: 0.007, streptomycin: 0.1, neomycin: 0.001, gram: "positive"},
17
+ {name: "Streptococcus hemolyticus", penicillin: 0.001, streptomycin: 14, neomycin: 10, gram: "positive"},
18
+ {name: "Streptococcus viridans", penicillin: 0.005, streptomycin: 10, neomycin: 40, gram: "positive"},
19
+ {name: "Diplococcus pneumoniae", penicillin: 0.005, streptomycin: 11, neomycin: 10, gram: "positive"}
20
+ ];
data/examples/area.rb ADDED
@@ -0,0 +1,103 @@
1
+ $:.unshift(File.dirname(__FILE__)+"/../lib")
2
+ require 'rubyvis'
3
+
4
+ data = pv.range(0, 10, 1).map {|x|
5
+ OpenStruct.new({:x=> x, :y=> Math.sin(x) + 2})
6
+ }
7
+
8
+
9
+ w = 400
10
+ h = 200
11
+ x = pv.Scale.linear(data, lambda {|d| d.x}).range(0, w)
12
+
13
+
14
+ y = pv.Scale.linear(0, 4).range(0, h);
15
+
16
+ #/* The root panel. */
17
+ vis = pv.Panel.new()
18
+ .width(w)
19
+ .height(h)
20
+ .bottom(20)
21
+ .left(20)
22
+ .right(10)
23
+ .top(5)
24
+
25
+ # Y-axis and ticks.
26
+ vis.add(pv.Rule)
27
+ .data(y.ticks(5))
28
+ .bottom(y)
29
+ .stroke_style(lambda {|d| d!=0 ? "#eee" : "#000"})
30
+ .anchor("left").add(pv.Label)
31
+ .text(y.tick_format)
32
+
33
+ # X-axis and ticks.
34
+ vis.add(pv.Rule)
35
+ .data(x.ticks())
36
+ .visible(lambda {|d| d!=0})
37
+ .left(x)
38
+ .bottom(-5)
39
+ .height(5)
40
+ .anchor("bottom").add(pv.Label)
41
+ .text(x.tick_format)
42
+
43
+ #/* The area with top line. */
44
+ vis.add(pv.Area)
45
+ .data(data)
46
+ .bottom(1)
47
+ .left(lambda {|d| x.scale(d.x)})
48
+ .height(lambda {|d| y.scale(d.y)})
49
+ .fill_style("rgb(121,173,210)")
50
+ .anchor("top").add(pv.Line)
51
+ .line_width(3)
52
+
53
+ vis.render();
54
+
55
+
56
+ puts vis.to_svg
57
+
58
+ =begin
59
+ <svg font-size="10px" font-family="sans-serif" fill="none" stroke="none" stroke-width="1.5" width="430" height="225">
60
+ <g transform="translate(20, 5)">
61
+ <line shape-rendering="crispEdges" x1="0" y1="200" x2="400" y2="200" stroke="rgb(0,0,0)" stroke-width="1"/>
62
+ <line shape-rendering="crispEdges" x1="0" y1="150" x2="400" y2="150" stroke="rgb(238,238,238)" stroke-width="1"/>
63
+ <line shape-rendering="crispEdges" x1="0" y1="100" x2="400" y2="100" stroke="rgb(238,238,238)" stroke-width="1"/>
64
+ <line shape-rendering="crispEdges" x1="0" y1="50" x2="400" y2="50" stroke="rgb(238,238,238)" stroke-width="1"/>
65
+ <line shape-rendering="crispEdges" x1="0" y1="0" x2="400" y2="0" stroke="rgb(238,238,238)" stroke-width="1"/>
66
+ </g>
67
+ <g transform="translate(20, 5)">
68
+ <text pointer-events="none" x="-3" dy="0.35em" transform="translate(0, 200)" fill="rgb(0,0,0)" text-anchor="end">0</text>
69
+ <text pointer-events="none" x="-3" dy="0.35em" transform="translate(0, 150)" fill="rgb(0,0,0)" text-anchor="end">1</text>
70
+ <text pointer-events="none" x="-3" dy="0.35em" transform="translate(0, 100)" fill="rgb(0,0,0)" text-anchor="end">2</text>
71
+ <text pointer-events="none" x="-3" dy="0.35em" transform="translate(0, 50)" fill="rgb(0,0,0)" text-anchor="end">3</text>
72
+ <text pointer-events="none" x="-3" dy="0.35em" fill="rgb(0,0,0)" text-anchor="end">4</text>
73
+ </g>
74
+ <g transform="translate(20, 5)">
75
+ <line shape-rendering="crispEdges" x1="44.44444444444444" y1="200" x2="44.44444444444444" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
76
+ <line shape-rendering="crispEdges" x1="88.88888888888889" y1="200" x2="88.88888888888889" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
77
+ <line shape-rendering="crispEdges" x1="133.33333333333331" y1="200" x2="133.33333333333331" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
78
+ <line shape-rendering="crispEdges" x1="177.77777777777777" y1="200" x2="177.77777777777777" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
79
+ <line shape-rendering="crispEdges" x1="222.22222222222223" y1="200" x2="222.22222222222223" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
80
+ <line shape-rendering="crispEdges" x1="266.66666666666663" y1="200" x2="266.66666666666663" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
81
+ <line shape-rendering="crispEdges" x1="311.11111111111114" y1="200" x2="311.11111111111114" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
82
+ <line shape-rendering="crispEdges" x1="355.55555555555554" y1="200" x2="355.55555555555554" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
83
+ <line shape-rendering="crispEdges" x1="400" y1="200" x2="400" y2="205" stroke="rgb(0,0,0)" stroke-width="1"/>
84
+ </g>
85
+ <g transform="translate(20, 5)">
86
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(44.4444, 205)" fill="rgb(0,0,0)" text-anchor="middle">1</text>
87
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(88.8889, 205)" fill="rgb(0,0,0)" text-anchor="middle">2</text>
88
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(133.333, 205)" fill="rgb(0,0,0)" text-anchor="middle">3</text>
89
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(177.778, 205)" fill="rgb(0,0,0)" text-anchor="middle">4</text>
90
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(222.222, 205)" fill="rgb(0,0,0)" text-anchor="middle">5</text>
91
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(266.667, 205)" fill="rgb(0,0,0)" text-anchor="middle">6</text>
92
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(311.111, 205)" fill="rgb(0,0,0)" text-anchor="middle">7</text>
93
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(355.556, 205)" fill="rgb(0,0,0)" text-anchor="middle">8</text>
94
+ <text pointer-events="none" y="3" dy="0.71em" transform="translate(400, 205)" fill="rgb(0,0,0)" text-anchor="middle">9</text>
95
+ </g>
96
+ <g transform="translate(20, 5)">
97
+ <path d="M0,99L44.44444444444444,56.92645075960516L88.88888888888889,53.535128658715905L133.33333333333331,91.94399959700664L177.77777777777777,136.8401247653964L222.22222222222223,146.94621373315692L266.66666666666663,112.9707749099463L311.11111111111114,66.15067006406053L355.55555555555554,49.53208766883091L400,78.39407573791217L400,199L355.55555555555554,199L311.11111111111114,199L266.66666666666663,199L222.22222222222223,199L177.77777777777777,199L133.33333333333331,199L88.88888888888889,199L44.44444444444444,199L0,199Z" fill="rgb(121,173,210)"/>
98
+ </g>
99
+ <g transform="translate(20, 5)">
100
+ <path d="M0,99L44.44444444444444,56.92645075960516L88.88888888888889,53.535128658715905L133.33333333333331,91.94399959700664L177.77777777777777,136.8401247653964L222.22222222222223,146.94621373315692L266.66666666666663,112.9707749099463L311.11111111111114,66.15067006406053L355.55555555555554,49.53208766883091L400,78.39407573791217" stroke="rgb(31,119,180)" stroke-width="3"/>
101
+ </g>
102
+ </svg>
103
+ =end
@@ -0,0 +1,55 @@
1
+ $:.unshift(File.dirname(__FILE__)+"/../lib")
2
+ require 'rubyvis'
3
+
4
+ data = pv.range(10).map {|d| rand + 0.1 }
5
+
6
+
7
+
8
+ #/* Sizing and scales. *
9
+ w = 400
10
+ h = 250
11
+ x = pv.Scale.linear(0, 1.1).range(0, w)
12
+ y = pv.Scale.ordinal(pv.range(10)).split_banded(0, h, 4/5.0)
13
+
14
+ #/* The root panel. */
15
+ vis = pv.Panel.new()
16
+ .width(w)
17
+ .height(h)
18
+ .bottom(20)
19
+ .left(20)
20
+ .right(10)
21
+ .top(5);
22
+
23
+ #/* The bars. */
24
+ bar = vis.add(pv.Bar)
25
+ .data(data)
26
+ .top(lambda { y.scale(self.index)})
27
+ .height(y.range_band)
28
+ .left(0)
29
+ .width(x)
30
+
31
+ #/* The value label. */
32
+ bar.anchor("right").add(pv.Label)
33
+ .text_style("white")
34
+ .text(lambda {|d| "%0.1f" % d})
35
+
36
+ #/* The variable label. */
37
+ bar.anchor("left").add(pv.Label)
38
+ .text_margin(5)
39
+ .text_align("right")
40
+ .text(lambda { "ABCDEFGHIJK"[self.index,1]});
41
+
42
+ #/* X-axis ticks. */
43
+ vis.add(pv.Rule)
44
+ .data(x.ticks(5))
45
+ .left(x)
46
+ .stroke_style(lambda {|d| d!=0 ? "rgba(255,255,255,.3)" : "#000"})
47
+ .add(pv.Rule)
48
+ .bottom(0)
49
+ .height(5)
50
+ .stroke_style("#000")
51
+ .anchor("bottom").add(pv.Label)
52
+ .text(x.tick_format);
53
+
54
+ vis.render();
55
+ puts vis.to_svg
@@ -1,13 +1,21 @@
1
1
  $:.unshift(File.dirname(__FILE__)+"/../../lib")
2
2
  require 'rubyvis'
3
-
3
+ load(File.dirname(__FILE__)+"/barley_data.rb")
4
4
  # Nest yields data by site then year. */
5
5
 
6
- barley = pv.nest(barley)
7
- .key(lambda {|d| d.site})
6
+ # Compute yield medians by site and by variety. */
7
+ median=lambda {|data| pv.median(data, lambda {|d| d[:yield]}) }
8
+
9
+ site = pv.nest($barley).key(lambda {|d| d[:site]}).rollup(median)
10
+
11
+ variety = pv.nest($barley).key(lambda {|d| d[:variety]}).rollup(median);
12
+
13
+
14
+ barley = pv.nest($barley)
15
+ .key(lambda {|d| d[:site]})
8
16
  .sort_keys(lambda {|a, b| site[b] - site[a]})
9
- .key(lambda {|d| d.year})
10
- .sort_values(function {|a, b| variety[b.variety] - variety[a.variety]})
17
+ .key(lambda {|d| d[:year]})
18
+ .sort_values(lambda {|a, b| variety[b[:variety]] - variety[a[:variety]]})
11
19
  .entries()
12
20
 
13
21
  # Sizing and scales. */
@@ -17,12 +25,12 @@ x = pv.Scale.linear(10, 90).range(0, w)
17
25
  c = pv.Colors.category10()
18
26
 
19
27
  # The root panel. */
20
- var vis = new pv.Panel()
28
+ vis = Rubyvis::Panel.new
21
29
  .width(w)
22
30
  .height(h * pv.keys(site).length)
23
31
  .top(15.5)
24
32
  .left(0.5)
25
- .right(.5)
33
+ .right(0.5)
26
34
  .bottom(25);
27
35
 
28
36
  # A panel per site-year. */
@@ -31,40 +39,40 @@ cell = vis.add(pv.Panel)
31
39
  .height(h)
32
40
  .left(90)
33
41
  .top(lambda { self.index * h})
34
- .strokeStyle("#999");
42
+ .stroke_style(pv.color("#999"));
35
43
 
36
44
  # Title bar. */
37
45
  cell.add(pv.Bar)
38
46
  .height(14)
39
- .fillStyle("bisque")
47
+ .fill_style(pv.color("bisque"))
40
48
  .anchor("center").add(pv.Label)
41
49
  .text(lambda{|site| site.key});
42
50
 
43
51
  # A dot showing the yield. */
44
- var dot = cell.add(pv.Panel)
52
+ dot = cell.add(pv.Panel)
45
53
  .data(lambda {|site| site.values})
46
54
  .top(23)
47
55
  .add(pv.Dot)
48
56
  .data(lambda {|year| year.values})
49
- .left(lamdba {|d| x(d.yield)})
57
+ .left(lambda {|d| x.scale(d[:yield])})
50
58
  .top(lambda {self.index * 11})
51
- .shapeSize(10)
52
- .lineWidth(2)
53
- .strokeStyle(lambda {|d| c(d.year)})
59
+ .shape_size(10)
60
+ .line_width(2)
61
+ .stroke_style(lambda {|d| c.scale(d[:year])})
54
62
 
55
63
  # A label showing the variety. */
56
64
  dot.anchor("left").add(pv.Label)
57
65
  .visible(lambda { !self.parent.index})
58
66
  .left(-2)
59
- .text(lambda {|d| d.variety})
67
+ .text(lambda {|d| d[:variety]})
60
68
 
61
69
  # X-ticks. */
62
70
  vis.add(pv.Rule)
63
71
  .data(x.ticks())
64
- .left(lambda {|d| 90 + x.scale(d)})
72
+ .left(lambda {|d| x.scale(d)})
65
73
  .bottom(-5)
66
74
  .height(5)
67
- .strokeStyle("#999")
75
+ .stroke_style(pv.color("#999"))
68
76
  .anchor("bottom").add(pv.Label);
69
77
 
70
78
  # A legend showing the year. */
@@ -74,6 +82,8 @@ vis.add(pv.Dot)
74
82
  .left(lambda {|d| 260 + self.index * 40})
75
83
  .top(-8)
76
84
  .anchor("right").add(pv.Label)
77
- .text(lambda {|d| d.year})
85
+ .text(lambda {|d| d[:year]})
86
+
87
+ vis.render()
78
88
 
79
- vis.render()
89
+ puts vis.to_svg