rubyvis 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data.tar.gz.sig +3 -2
  2. data/History.txt +6 -0
  3. data/Rakefile +1 -1
  4. data/examples/5_pv_hierarchies/bubble_charts.rb +1 -1
  5. data/examples/5_pv_hierarchies/bubble_charts_matrix.rb +1 -1
  6. data/examples/5_pv_hierarchies/circle_packing.rb +1 -1
  7. data/examples/5_pv_hierarchies/dendogram.rb +1 -1
  8. data/examples/5_pv_hierarchies/icicle.rb +1 -1
  9. data/examples/5_pv_hierarchies/indent.rb +1 -1
  10. data/examples/5_pv_hierarchies/node_link_tree.rb +1 -1
  11. data/examples/5_pv_hierarchies/sunburst.rb +1 -1
  12. data/examples/5_pv_hierarchies/treemap.rb +1 -1
  13. data/lib/rubyvis.rb +1 -1
  14. data/lib/rubyvis/color/color.rb +35 -34
  15. data/lib/rubyvis/color/colors.rb +1 -1
  16. data/lib/rubyvis/internals.rb +2 -2
  17. data/lib/rubyvis/layout.rb +4 -1
  18. data/lib/rubyvis/layout/matrix.rb +105 -105
  19. data/lib/rubyvis/layout/network.rb +3 -3
  20. data/lib/rubyvis/mark.rb +5 -4
  21. data/lib/rubyvis/mark/area.rb +1 -1
  22. data/lib/rubyvis/mark/image.rb +1 -1
  23. data/lib/rubyvis/mark/rule.rb +2 -2
  24. data/lib/rubyvis/mark/shorcut_methods.rb +1 -0
  25. data/lib/rubyvis/mark/wedge.rb +31 -22
  26. data/lib/rubyvis/nest.rb +1 -1
  27. data/lib/rubyvis/scale/ordinal.rb +1 -1
  28. data/lib/rubyvis/scale/quantitative.rb +2 -1
  29. data/lib/rubyvis/scene/svg_curve.rb +24 -14
  30. data/lib/rubyvis/scene/svg_dot.rb +1 -1
  31. data/lib/rubyvis/scene/svg_label.rb +3 -2
  32. data/lib/rubyvis/scene/svg_scene.rb +6 -12
  33. data/spec/anchor_spec.rb +3 -3
  34. data/spec/area_spec.rb +22 -22
  35. data/spec/dot_spec.rb +9 -9
  36. data/spec/layout_arc_spec.rb +8 -8
  37. data/spec/layout_cluster_spec.rb +7 -6
  38. data/spec/layout_grid_spec.rb +18 -18
  39. data/spec/layout_indent_spec.rb +6 -6
  40. data/spec/layout_matrix_spec.rb +9 -9
  41. data/spec/layout_pack_spec.rb +6 -6
  42. data/spec/layout_partition_spec.rb +6 -6
  43. data/spec/layout_stack_spec.rb +10 -10
  44. data/spec/layout_tree_spec.rb +6 -6
  45. data/spec/layout_treemap_spec.rb +4 -4
  46. data/spec/line_spec.rb +14 -14
  47. data/spec/nest_spec.rb +2 -2
  48. data/spec/rule_spec.rb +11 -12
  49. data/spec/spec_helper.rb +8 -7
  50. data/spec/wedge_spec.rb +22 -22
  51. data/web/Rakefile +4 -1
  52. metadata +18 -5
  53. metadata.gz.sig +0 -0
data/spec/dot_spec.rb CHANGED
@@ -14,16 +14,16 @@ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
14
14
  w = 400
15
15
  h = 400
16
16
 
17
- vis = Rubyvis::Panel.new()
18
- .width(w)
19
- .height(h)
20
- .margin(20)
21
- .stroke_style("#ccc");
17
+ vis = Rubyvis::Panel.new().
18
+ width(w).
19
+ height(h).
20
+ margin(20).
21
+ stroke_style("#ccc");
22
22
 
23
- dot = vis.add(Rubyvis::Dot)
24
- .top(w / 2.0)
25
- .left(w / 2.0)
26
- .shape_radius(w >> 2)
23
+ dot = vis.add(Rubyvis::Dot).
24
+ top(w / 2.0).
25
+ left(w / 2.0).
26
+ shape_radius(w >> 2)
27
27
 
28
28
  dot.anchor("top").add(Rubyvis::Label).text("top");
29
29
  dot.anchor("left").add(Rubyvis::Label).text("left");
@@ -19,15 +19,15 @@ describe Rubyvis::Layout::Arc do
19
19
 
20
20
  color=Rubyvis::Colors.category19
21
21
 
22
- @vis = Rubyvis::Panel.new()
23
- .width(w)
24
- .height(h)
25
- .bottom(50)
26
- .left(0)
22
+ @vis = Rubyvis::Panel.new().
23
+ width(w).
24
+ height(h).
25
+ bottom(50).
26
+ left(0)
27
27
 
28
- mat=@vis.add(Rubyvis::Layout::Arc)
29
- .nodes(net_nodes).links(net_links)
30
- .sort(lambda {|a,b| a.group<=>b.group})
28
+ mat=@vis.add(Rubyvis::Layout::Arc).
29
+ nodes(net_nodes).links(net_links).
30
+ sort(lambda {|a,b| a.group<=>b.group})
31
31
 
32
32
  mat.link.add(Rubyvis::Line).
33
33
  antialias(false).
@@ -15,12 +15,12 @@ describe Rubyvis::Layout::Cluster do
15
15
  w=400
16
16
  h=400
17
17
 
18
- @vis = Rubyvis.Panel.new()
19
- .width(w)
20
- .height(h)
21
- .top(20)
22
- .bottom(10)
23
- .left(10)
18
+ @vis = Rubyvis.Panel.new().
19
+ width(w).
20
+ height(h).
21
+ top(20).
22
+ bottom(10).
23
+ left(10)
24
24
 
25
25
  @cluster = @vis.add(Rubyvis::Layout::Cluster).
26
26
  nodes(hier_nodes_big).
@@ -40,6 +40,7 @@ describe Rubyvis::Layout::Cluster do
40
40
  it "should render correctly 'cluster.html' custom test" do
41
41
  @vis.render
42
42
  @pv_out=fixture_svg_read("layout_cluster.svg")
43
+ File.open("test.svg","w") {|fp| fp.write(@vis.to_svg)}
43
44
  @vis.to_svg.should have_same_svg_elements(@pv_out)
44
45
  end
45
46
  it "should render correctly 'cluster_left_group_2.html' custom test" do
@@ -10,25 +10,25 @@ describe Rubyvis::Layout::Grid do
10
10
  end
11
11
  it "should render equal to protovis 'layout_grid.html' test" do
12
12
 
13
- vis = pv.Panel.new()
14
- .data(["A"])
15
- .width(800)
16
- .height(800)
17
- .margin(10)
18
- .fill_style("#eee")
19
- .stroke_style("#ccc");
13
+ vis = pv.Panel.new().
14
+ data(["A"]).
15
+ width(800).
16
+ height(800).
17
+ margin(10).
18
+ fill_style("#eee").
19
+ stroke_style("#ccc");
20
20
 
21
- vis.add(Rubyvis::Layout::Grid)
22
- .rows(3)
23
- .cols(3)
24
- .cell.add(Rubyvis::Layout::Grid)
25
- .rows(Rubyvis.index)
26
- .cols(Rubyvis.index)
27
- .cell.add(Rubyvis::Bar)
28
- .stroke_style("#fff")
29
- .anchor("center").add(Rubyvis::Label)
30
- .textStyle("rgba(255, 255, 255, .4)")
31
- .font("24px sans");
21
+ vis.add(Rubyvis::Layout::Grid).
22
+ rows(3).
23
+ cols(3).
24
+ cell.add(Rubyvis::Layout::Grid).
25
+ rows(Rubyvis.index).
26
+ cols(Rubyvis.index).
27
+ cell.add(Rubyvis::Bar).
28
+ stroke_style("#fff").
29
+ anchor("center").add(Rubyvis::Label).
30
+ textStyle("rgba(255, 255, 255, .4)").
31
+ font("24px sans");
32
32
 
33
33
  vis.render();
34
34
 
@@ -14,12 +14,12 @@ describe Rubyvis::Layout::Indent do
14
14
  w=200
15
15
  h=200
16
16
 
17
- @vis = pv.Panel.new()
18
- .width(w)
19
- .height(h)
20
- .top(20)
21
- .bottom(10)
22
- .left(10)
17
+ @vis = pv.Panel.new().
18
+ width(w).
19
+ height(h).
20
+ top(20).
21
+ bottom(10).
22
+ left(10)
23
23
 
24
24
  indent = @vis.add(pv.Layout.Indent).
25
25
  nodes(hier_nodes_big).
@@ -12,16 +12,16 @@ describe Rubyvis::Layout::Matrix do
12
12
  h = 700
13
13
 
14
14
  color=Rubyvis::Colors.category19()
15
- @vis = Rubyvis::Panel.new()
16
- .width(w)
17
- .height(h)
18
- .top(50)
19
- .left(50)
15
+ @vis = Rubyvis::Panel.new().
16
+ width(w).
17
+ height(h).
18
+ top(50).
19
+ left(50)
20
20
 
21
- mat=@vis.add(Rubyvis::Layout.Matrix)
22
- .directed(true)
23
- .nodes(net_nodes).links(net_links)
24
- .sort(lambda {|a,b| a.group<=>b.group})
21
+ mat=@vis.add(Rubyvis::Layout.Matrix).
22
+ directed(true).
23
+ nodes(net_nodes).links(net_links).
24
+ sort(lambda {|a,b| a.group<=>b.group})
25
25
 
26
26
  mat.link.add(pv.Bar).
27
27
  fill_style(lambda {|l| l.link_value!=0 ?
@@ -11,12 +11,12 @@ describe Rubyvis::Layout::Pack do
11
11
  w=200
12
12
  h=200
13
13
 
14
- @vis = pv.Panel.new()
15
- .width(w)
16
- .height(h)
17
- .top(20)
18
- .bottom(10)
19
- .left(10)
14
+ @vis = pv.Panel.new().
15
+ width(w).
16
+ height(h).
17
+ top(20).
18
+ bottom(10).
19
+ left(10)
20
20
 
21
21
  pack = @vis.add(pv.Layout.Pack).
22
22
  nodes(hier_nodes_big)
@@ -13,12 +13,12 @@ describe Rubyvis::Layout::Partition do
13
13
  w=400
14
14
  h=400
15
15
 
16
- @vis = pv.Panel.new()
17
- .width(w)
18
- .height(h)
19
- .top(20)
20
- .bottom(10)
21
- .left(10)
16
+ @vis = pv.Panel.new().
17
+ width(w).
18
+ height(h).
19
+ top(20).
20
+ bottom(10).
21
+ left(10)
22
22
 
23
23
  pack = @vis.add(Rubyvis::Layout::Partition::Fill).
24
24
  nodes(hier_nodes_big).
@@ -20,19 +20,19 @@ describe Rubyvis::Layout::Stack do
20
20
 
21
21
  fill=pv.ramp("#ada", "#656").domain(n, 0)
22
22
 
23
- @vis = Rubyvis::Panel.new()
24
- .width(w)
25
- .height(@h)
23
+ @vis = Rubyvis::Panel.new().
24
+ width(w).
25
+ height(@h)
26
26
 
27
27
  dat=waves(n,m)
28
- @stack=@vis.add(Rubyvis::Layout::Stack)
29
- .layers(dat)
30
- .x(lambda {|d| x[self.index]})
31
- .y(lambda {|d| d})
28
+ @stack=@vis.add(Rubyvis::Layout::Stack).
29
+ layers(dat).
30
+ x(lambda {|d| x[self.index]}).
31
+ y(lambda {|d| d})
32
32
 
33
- @stack.layer.add(Rubyvis::Area)
34
- .fill_style(lambda {fill[self.parent.index]})
35
- .stroke_style("#797")
33
+ @stack.layer.add(Rubyvis::Area).
34
+ fill_style(lambda {fill[self.parent.index]}).
35
+ stroke_style("#797")
36
36
  end
37
37
 
38
38
  it "should render 'stack-expand.html' example correctly" do
@@ -11,12 +11,12 @@ describe Rubyvis::Layout::Treemap do
11
11
  w=200
12
12
  h=200
13
13
 
14
- @vis = pv.Panel.new()
15
- .width(w)
16
- .height(h)
17
- .top(20)
18
- .bottom(10)
19
- .left(10)
14
+ @vis = pv.Panel.new().
15
+ width(w).
16
+ height(h).
17
+ top(20).
18
+ bottom(10).
19
+ left(10)
20
20
 
21
21
  @tree= @vis.add(pv.Layout.Tree).
22
22
  nodes(hier_nodes).breadth(40)
@@ -11,9 +11,9 @@ describe Rubyvis::Layout::Treemap do
11
11
  w=200
12
12
  h=200
13
13
 
14
- @vis = pv.Panel.new()
15
- .width(w)
16
- .height(h)
14
+ @vis = pv.Panel.new().
15
+ width(w).
16
+ height(h)
17
17
 
18
18
  treemap = @vis.add(pv.Layout.Treemap).
19
19
  nodes(hier_nodes).
@@ -34,7 +34,7 @@ describe Rubyvis::Layout::Treemap do
34
34
  @pv_out=fixture_svg_read("layout_treemap.svg")
35
35
  end
36
36
 
37
- it "should render equal to protovis version " do
37
+ it "should render equal to protovis version " do
38
38
  @vis.to_svg.should have_same_svg_elements(@pv_out)
39
39
  end
40
40
  end
data/spec/line_spec.rb CHANGED
@@ -28,13 +28,13 @@ describe Rubyvis::Line do
28
28
  interpolations=["linear","step-before","step-after","polar","polar-reverse", "basis", "cardinal"]
29
29
 
30
30
  #/* The root panel. */
31
- vis = pv.Panel.new()
32
- .width(w)
33
- .height(h)
34
- .bottom(20)
35
- .left(20)
36
- .right(10)
37
- .top(5)
31
+ vis = pv.Panel.new().
32
+ width(w).
33
+ height(h).
34
+ bottom(20).
35
+ left(20).
36
+ right(10).
37
+ top(5)
38
38
 
39
39
  interpolations.each_with_index do |inter,i|
40
40
  n=i%2
@@ -78,13 +78,13 @@ describe Rubyvis::Line do
78
78
 
79
79
  interpolations=["linear","step-before","step-after","polar","polar-reverse", "basis", "cardinal","monotone"]
80
80
  #/* The root panel. */
81
- vis = pv.Panel.new()
82
- .width(w)
83
- .height(h)
84
- .bottom(20)
85
- .left(20)
86
- .right(10)
87
- .top(5)
81
+ vis = pv.Panel.new().
82
+ width(w).
83
+ height(h).
84
+ bottom(20).
85
+ left(20).
86
+ right(10).
87
+ top(5)
88
88
 
89
89
  interpolations.each_with_index do |inter,i|
90
90
  n=i%2
data/spec/nest_spec.rb CHANGED
@@ -34,9 +34,9 @@ describe Rubyvis::Nest do
34
34
  Rubyvis::NestedArray.new(:key=>2011, :values=>
35
35
  [
36
36
  Rubyvis::NestedArray.new(:key=>'London', :values=>
37
- [{:year=>2011, :city=>'London',:value=>3}]),
37
+ [{:year=>2011, :city=>'London',:value=>5}]),
38
38
  Rubyvis::NestedArray.new(:key=>'France', :values=>
39
- [{:year=>2011, :city=>'France',:value=>4}])
39
+ [{:year=>2011, :city=>'France',:value=>6}])
40
40
  ])
41
41
  ]
42
42
 
data/spec/rule_spec.rb CHANGED
@@ -9,22 +9,21 @@ describe Rubyvis::Rule do
9
9
  Rubyvis.Rule.should eql Rubyvis::Rule
10
10
  end
11
11
  it "should render equal to protovis 'rule-anchor.html' test" do
12
- vis = Rubyvis::Panel.new()
13
- .width(400)
14
- .height(300)
12
+ vis = Rubyvis::Panel.new().
13
+ width(400).
14
+ height(300)
15
15
 
16
16
 
17
- bar=vis.add(pv.Bar)
18
- .data(["left", "top", "right", "bottom", "center"])
19
- .width(300)
20
- .height(30)
21
- .left(40)
22
- .right(40)
23
- .top(lambda {self.index*60}).fill_style('red')
17
+ bar=vis.add(pv.Bar).
18
+ data(["left", "top", "right", "bottom", "center"]).
19
+ width(300).
20
+ height(30).
21
+ left(40).
22
+ right(40).
23
+ top(lambda {self.index*60}).fill_style('red')
24
24
 
25
25
  rule = bar.add(pv.Rule)
26
- rule.anchor(lambda {|d| d}).add(pv.Label)
27
- .text(lambda {|d| d})
26
+ rule.anchor(lambda {|d| d}).add(pv.Label).text(lambda {|d| d})
28
27
 
29
28
  vis.render();
30
29
  pv_out=fixture_svg_read("rule_anchor.svg")
data/spec/spec_helper.rb CHANGED
@@ -154,8 +154,7 @@ Rspec::Matchers.define :have_same_svg_elements do |exp|
154
154
  }
155
155
 
156
156
  @error={:type=>"Undefined error"}
157
- attrs.each_pair do |key,attrs|
158
-
157
+ attrs.each_pair do |key,attrs|
159
158
  exp_elements=exp_xml.xpath("//#{key}")
160
159
  obs_elements=obs_xml.xpath("//xmlns:#{key}")
161
160
  if exp_elements.size!=obs_elements.size
@@ -163,22 +162,24 @@ Rspec::Matchers.define :have_same_svg_elements do |exp|
163
162
  correct=false
164
163
  break
165
164
  end
165
+
166
166
  exp_elements.each_with_index {|exp_data,i|
167
- obs_data=obs_elements[i]
168
-
167
+ obs_data=obs_elements[i]
169
168
  if obs_data.nil?
170
169
  @error={:type=>"Missing obs", :exp=>exp_data, :i=>i}
171
170
  correct=false
172
171
  break
173
172
  end
173
+ if exp_data.content!=obs_data.content
174
+ @error={:type=>"Content", :exp=>exp_data, :i=>i, :obs=>obs_data, :exp_attr=>exp_data.content, :obs_attr=>obs_data.content}
175
+ correct=false
176
+ break;
177
+ end
174
178
 
175
- exp_data.content.should==obs_data.content
176
179
  attrs.each do |attr,method|
177
-
178
180
  eq=send("equal_#{method}",obs_data[attr],exp_data[attr])
179
181
  if !eq
180
182
  puts "Uneql attr: #{method}->#{attr}"
181
-
182
183
  @error={:type=>"Incorrect data", :exp=>exp_data, :obs=>obs_data, :attr=>attr, :exp_attr=>exp_data[attr], :obs_attr=>obs_data[attr],:i=>i}
183
184
  correct=false
184
185
  break
data/spec/wedge_spec.rb CHANGED
@@ -17,18 +17,18 @@ describe Rubyvis::Wedge do
17
17
  t = 30
18
18
  a = Rubyvis::Scale.linear(0, Rubyvis.sum(data)).range(0, 2 * Math::PI);
19
19
 
20
- vis = Rubyvis::Panel.new()
21
- .width(w)
22
- .height(h)
20
+ vis = Rubyvis::Panel.new().
21
+ width(w).
22
+ height(h)
23
23
 
24
24
  anchors=["outer","inner","start","center","end"]
25
25
 
26
- vis.add(Rubyvis::Wedge)
27
- .data(data)
28
- .outer_radius(r)
29
- .angle(a)
30
- .anchor(lambda {anchors[self.index]}).add(pv.Label)
31
- .text(lambda {anchors[self.index]})
26
+ vis.add(Rubyvis::Wedge).
27
+ data(data).
28
+ outer_radius(r).
29
+ angle(a).
30
+ anchor(lambda {anchors[self.index]}).add(pv.Label).
31
+ text(lambda {anchors[self.index]})
32
32
 
33
33
  vis.render();
34
34
  pv_out=fixture_svg_read("wedge_anchor.svg")
@@ -43,20 +43,20 @@ describe Rubyvis::Wedge do
43
43
  t = 30
44
44
  a = Rubyvis.Scale.linear(0, Rubyvis.sum(data)).range(0, 2 * Math::PI)
45
45
 
46
- @vis = Rubyvis::Panel.new()
47
- .width(w)
48
- .height(h)
46
+ @vis = Rubyvis::Panel.new().
47
+ width(w).
48
+ height(h)
49
49
 
50
- @vis.add(Rubyvis::Wedge)
51
- .data(data)
52
- .inner_radius(r - t)
53
- .outer_radius(r)
54
- .angle(a)
55
- .title(lambda {|d| d})
56
- .anchor("outer").add(Rubyvis::Label)
57
- .visible(lambda {|d| d>0.05})
58
- .text_margin(t + 5)
59
- .text(lambda {|d| "%0.2f" % d})
50
+ @vis.add(Rubyvis::Wedge).
51
+ data(data).
52
+ inner_radius(r - t).
53
+ outer_radius(r).
54
+ angle(a).
55
+ title(lambda {|d| d}).
56
+ anchor("outer").add(Rubyvis::Label).
57
+ visible(lambda {|d| d>0.05}).
58
+ text_margin(t + 5).
59
+ text(lambda {|d| "%0.2f" % d})
60
60
  @vis.render();
61
61
 
62
62
  @pv_out=fixture_svg_read("wedge_donut.svg")