rubyvis 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +16 -0
  3. data/Manifest.txt +61 -0
  4. data/README.txt +9 -7
  5. data/Rakefile +1 -1
  6. data/lib/rubyvis.rb +3 -17
  7. data/lib/rubyvis/color/color.rb +11 -13
  8. data/lib/rubyvis/flatten.rb +5 -7
  9. data/lib/rubyvis/layout/stack.rb +15 -10
  10. data/lib/rubyvis/mark.rb +10 -2
  11. data/lib/rubyvis/mark/area.rb +5 -3
  12. data/lib/rubyvis/mark/line.rb +4 -3
  13. data/lib/rubyvis/mark/panel.rb +8 -3
  14. data/lib/rubyvis/mark/rule.rb +1 -0
  15. data/lib/rubyvis/scene/svg_area.rb +17 -17
  16. data/lib/rubyvis/scene/svg_curve.rb +8 -5
  17. data/lib/rubyvis/scene/svg_line.rb +32 -29
  18. data/lib/rubyvis/scene/svg_scene.rb +3 -5
  19. data/lib/rubyvis/scene/svg_wedge.rb +4 -3
  20. data/lib/rubyvis/vector.rb +104 -0
  21. data/spec/anchor_spec.rb +29 -0
  22. data/spec/area_spec.rb +83 -0
  23. data/spec/bar_spec.rb +3 -0
  24. data/spec/color_spec.rb +13 -1
  25. data/spec/dot_spec.rb +41 -0
  26. data/spec/fixtures/anchor.html +25 -0
  27. data/spec/fixtures/anchor.svg +1 -0
  28. data/spec/fixtures/area-segmented.html +29 -0
  29. data/spec/fixtures/area_interpolation.html +66 -0
  30. data/spec/fixtures/area_interpolation.svg +1 -0
  31. data/spec/fixtures/area_segmented.svg +1 -0
  32. data/spec/fixtures/dot-anchor.html +33 -0
  33. data/spec/fixtures/dot_anchor.svg +1 -0
  34. data/spec/fixtures/layers.js +28 -0
  35. data/spec/fixtures/layout_arc.svg +1 -0
  36. data/spec/fixtures/layout_cluster.html +39 -0
  37. data/spec/fixtures/layout_cluster.svg +1 -0
  38. data/spec/fixtures/layout_cluster_left_group_2.html +39 -0
  39. data/spec/fixtures/layout_cluster_left_group_2.svg +1 -0
  40. data/spec/fixtures/layout_grid.html +34 -0
  41. data/spec/fixtures/layout_grid.svg +1 -0
  42. data/spec/fixtures/layout_horizon.svg +24 -0
  43. data/spec/fixtures/layout_indent.html +39 -0
  44. data/spec/fixtures/layout_indent.svg +1 -0
  45. data/spec/fixtures/layout_matrix.svg +1 -0
  46. data/spec/fixtures/layout_pack.html +38 -0
  47. data/spec/fixtures/layout_pack.svg +1 -0
  48. data/spec/fixtures/layout_partition_fill.html +40 -0
  49. data/spec/fixtures/layout_partition_fill.svg +32 -0
  50. data/spec/fixtures/layout_tree_orient_left.html +36 -0
  51. data/spec/fixtures/layout_tree_orient_left.svg +1 -0
  52. data/spec/fixtures/layout_tree_orient_radial_breadth_20.html +39 -0
  53. data/spec/fixtures/layout_tree_orient_radial_breadth_20.svg +1 -0
  54. data/spec/fixtures/layout_tree_orient_top.svg +1 -0
  55. data/spec/fixtures/layout_treemap.svg +1 -0
  56. data/spec/fixtures/line_interpolation.html +63 -0
  57. data/spec/fixtures/line_interpolation.svg +1 -0
  58. data/spec/fixtures/line_interpolation_segmented.html +65 -0
  59. data/spec/fixtures/line_interpolation_segmented.svg +1 -0
  60. data/spec/fixtures/protovis-r3.3.js +287 -0
  61. data/spec/fixtures/rule-anchor.html +33 -0
  62. data/spec/fixtures/rule_anchor.svg +1 -0
  63. data/spec/fixtures/stack-expand.html +41 -0
  64. data/spec/fixtures/stack-silohouette.html +41 -0
  65. data/spec/fixtures/stack-wiggle.html +41 -0
  66. data/spec/fixtures/stack_expand.svg +1 -0
  67. data/spec/fixtures/stack_silohouette.svg +1 -0
  68. data/spec/fixtures/stack_wiggle.svg +1 -0
  69. data/spec/fixtures/svgscene.html +26 -0
  70. data/spec/fixtures/wedge-anchor.html +33 -0
  71. data/spec/fixtures/wedge-donut.html +35 -0
  72. data/spec/fixtures/wedge_anchor.svg +1 -0
  73. data/spec/fixtures/wedge_donut.svg +1 -0
  74. data/spec/flatten_spec.rb +47 -0
  75. data/spec/layout_arc_spec.rb +7 -26
  76. data/spec/layout_cluster_spec.rb +52 -0
  77. data/spec/layout_grid_spec.rb +40 -0
  78. data/spec/layout_horizon_spec.rb +6 -25
  79. data/spec/layout_indent_spec.rb +53 -0
  80. data/spec/layout_matrix_spec.rb +25 -52
  81. data/spec/layout_pack_spec.rb +49 -0
  82. data/spec/layout_partition_spec.rb +45 -0
  83. data/spec/layout_stack_spec.rb +60 -0
  84. data/spec/layout_tree_spec.rb +56 -0
  85. data/spec/layout_treemap_spec.rb +41 -0
  86. data/spec/line_spec.rb +118 -0
  87. data/spec/mark_spec.rb +4 -0
  88. data/spec/panel_spec.rb +12 -1
  89. data/spec/rule_spec.rb +34 -0
  90. data/spec/spec_helper.rb +158 -3
  91. data/spec/vector_spec.rb +36 -0
  92. data/spec/wedge_spec.rb +66 -0
  93. metadata +67 -14
  94. metadata.gz.sig +0 -0
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
+ describe Rubyvis::Layout::Pack do
3
+ include Rubyvis::LayoutSpec
4
+ it "should have correct properties" do
5
+ props=[:antialias, :bottom, :canvas, :cursor, :data, :events, :fill_style, :height, :id, :left, :line_width, :links, :nodes, :order, :overflow, :reverse, :right, :spacing, :stroke_style, :title, :top, :transform, :visible, :width].inject({}) {|ac, v| ac[v]=true; ac}
6
+ Rubyvis::Layout::Pack.properties.should==props
7
+ end
8
+ describe "rendered" do
9
+ before do
10
+ color=pv.Colors.category19
11
+ w=200
12
+ h=200
13
+
14
+ @vis = pv.Panel.new()
15
+ .width(w)
16
+ .height(h)
17
+ .top(20)
18
+ .bottom(10)
19
+ .left(10)
20
+
21
+ pack = @vis.add(pv.Layout.Pack).
22
+ nodes(hier_nodes_big)
23
+
24
+ pack.node.add(pv.Dot).
25
+ fill_style(lambda {|d| color[d.node_value]}).
26
+ stroke_style("black").
27
+ line_width(1).
28
+ antialias(false)
29
+
30
+ pack.node_label.add(pv.Label).
31
+ text(lambda {|d| d.node_value})
32
+
33
+
34
+ @vis.render
35
+
36
+ html_out=fixture_svg_read("layout_pack.svg")
37
+ @rv_svg=Nokogiri::XML(@vis.to_svg)
38
+ @pv_svg=Nokogiri::XML(html_out)
39
+ end
40
+
41
+ it "should render equal nodes (circles)" do
42
+ pv_rects=@pv_svg.xpath("//circle")
43
+ @rv_svg.xpath("//xmlns:circle").each_with_index {|rv_rect,i|
44
+ rv_rect.should have_same_position pv_rects[i]
45
+ }
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
+ describe Rubyvis::Layout::Partition do
3
+ include Rubyvis::LayoutSpec
4
+ it "subclass Fill should have correct properties" do
5
+ props=[:antialias, :bottom, :canvas, :cursor, :data, :events, :fill_style, :height, :id, :inner_radius, :left, :line_width, :links, :nodes, :order, :orient, :outer_radius, :overflow, :reverse, :right, :stroke_style, :title, :top, :transform, :visible, :width].inject({}) {|ac, v| ac[v]=true; ac}
6
+ Rubyvis::Layout::Partition::Fill.properties.should==props
7
+ end
8
+ it "should be called using Rubyvis.Layout.Partition" do
9
+ Rubyvis.Layout.Partition.should eql Rubyvis::Layout::Partition
10
+ end
11
+ it "should render correctly 'partition_fill' custom test" do
12
+ color=pv.Colors.category19
13
+ w=400
14
+ h=400
15
+
16
+ @vis = pv.Panel.new()
17
+ .width(w)
18
+ .height(h)
19
+ .top(20)
20
+ .bottom(10)
21
+ .left(10)
22
+
23
+ pack = @vis.add(Rubyvis::Layout::Partition::Fill).
24
+ nodes(hier_nodes_big).
25
+ orient("left").
26
+ size(lambda {|d|
27
+ d.node_value
28
+ })
29
+
30
+ pack.node.add(pv.Bar).
31
+ fill_style(lambda {|d| color[d.node_value]}).
32
+ stroke_style("black").
33
+ line_width(1).
34
+ antialias(false)
35
+
36
+ pack.node_label.add(pv.Label).
37
+ text(lambda {|d| d.node_name})
38
+
39
+
40
+ @vis.render
41
+ @pv_out=fixture_svg_read("layout_partition_fill.svg")
42
+ @vis.to_svg.should have_same_svg_elements(@pv_out)
43
+ end
44
+
45
+ end
@@ -1,9 +1,69 @@
1
1
  require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
2
  describe Rubyvis::Layout::Stack do
3
+ include Rubyvis::LayoutSpec
3
4
  it "should have correct properties" do
4
5
  props=[:antialias, :bottom, :canvas, :cursor, :data, :events, :fill_style, :height, :id, :layers, :left, :line_width, :offset, :order, :orient, :overflow, :reverse, :right, :stroke_style, :title, :top, :transform, :visible, :width].inject({}) {|ac, v| ac[v]=true; ac}
5
6
  Rubyvis::Layout::Stack.properties.should==props
6
7
  end
8
+ it "Rubyvis.Dot be the same as Rubyvis::Dot" do
9
+ Rubyvis.Layout.Stack.should eql Rubyvis::Layout::Stack
10
+ end
11
+ describe "html examples" do
12
+ before do
13
+ w = 300
14
+ @h = 300
15
+
16
+ n = 20 # // number of layers
17
+ m = 75 # // number of samples per layer
18
+ x = pv.Scale.linear(2, m - 1).range(0, w)
19
+ @y = pv.Scale.linear(0, 20).range(0, @h/2.0)
20
+
21
+ fill=pv.ramp("#ada", "#656").domain(n, 0)
22
+
23
+ @vis = Rubyvis::Panel.new()
24
+ .width(w)
25
+ .height(@h)
26
+
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})
32
+
33
+ @stack.layer.add(Rubyvis::Area)
34
+ .fill_style(lambda {fill[self.parent.index]})
35
+ .stroke_style("#797")
36
+ end
37
+
38
+ it "should render 'stack-expand.html' example correctly" do
39
+ @stack.order("inside-out").
40
+ offset("expand")
41
+ @vis.render()
42
+ pv_out=fixture_svg_read("stack_expand.svg")
43
+ @vis.to_svg.should have_same_svg_elements(pv_out)
44
+ end
45
+ it "should render 'stack-silohouette.html' example correctly" do
46
+ y=@y
47
+ @stack.order("reverse").
48
+ offset("silohouette").
49
+ y(lambda {|d| y[d]})
50
+
51
+ @vis.render()
52
+ pv_out=fixture_svg_read("stack_silohouette.svg")
53
+ @vis.to_svg.should have_same_svg_elements(pv_out)
54
+ end
55
+ it "should render 'stack-wiggle.html' example correctly" do
56
+ y=@y
57
+ @stack.order("reverse").
58
+ offset("wiggle").
59
+ y(lambda {|d| y[d]})
60
+
61
+ @vis.render()
62
+ pv_out=fixture_svg_read("stack_wiggle.svg")
63
+ @vis.to_svg.should have_same_svg_elements(pv_out)
64
+ end
65
+
66
+ end
7
67
  describe "rendered" do
8
68
  before do
9
69
  @h=200
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
+ describe Rubyvis::Layout::Treemap do
3
+ include Rubyvis::LayoutSpec
4
+ it "should have correct properties" do
5
+ props=[:antialias, :bottom, :canvas, :cursor, :data, :events, :fill_style, :height, :id, :left, :line_width, :links, :mode, :nodes, :order, :overflow, :padding_bottom, :padding_left, :padding_right, :padding_top, :reverse, :right, :round, :stroke_style, :title, :top, :transform, :visible, :width].inject({}) {|ac, v| ac[v]=true; ac}
6
+ Rubyvis::Layout::Treemap.properties.should==props
7
+ end
8
+ describe "rendered" do
9
+ before do
10
+ color=pv.Colors.category19
11
+ w=200
12
+ h=200
13
+
14
+ @vis = pv.Panel.new()
15
+ .width(w)
16
+ .height(h)
17
+ .top(20)
18
+ .bottom(10)
19
+ .left(10)
20
+
21
+ @tree= @vis.add(pv.Layout.Tree).
22
+ nodes(hier_nodes).breadth(40)
23
+
24
+ @tree.node.add(pv.Dot).
25
+ fill_style(lambda {|d| color[d.node_value]}).
26
+ stroke_style("black").
27
+ line_width(1).
28
+ antialias(false)
29
+
30
+ @tree.link.add(Rubyvis::Line)
31
+
32
+ @tree.node_label.add(Rubyvis::Label).text(lambda {|d| d.node_name})
33
+
34
+ end
35
+ it "should render equal to protovis with orient 'top'" do
36
+ @tree.orient("top")
37
+ @vis.render
38
+ pv_out=fixture_svg_read("layout_tree_orient_top.svg")
39
+ @vis.to_svg.should have_same_svg_elements(pv_out)
40
+ end
41
+
42
+ it "should render correctly orient('left')" do
43
+ @tree.orient("left")
44
+ @vis.render
45
+ pv_out=fixture_svg_read("layout_tree_orient_left.svg")
46
+ @vis.to_svg.should have_same_svg_elements(pv_out)
47
+ end
48
+
49
+ it "should render equal to pv with orient('radial') and breadth(20)" do
50
+ @tree.nodes(hier_nodes_big).orient("radial").breadth(20)
51
+ @vis.render
52
+ pv_out=fixture_svg_read("layout_tree_orient_radial_breadth_20.svg")
53
+ @vis.to_svg.should have_same_svg_elements(pv_out)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
+ describe Rubyvis::Layout::Treemap do
3
+ include Rubyvis::LayoutSpec
4
+ it "should have correct properties" do
5
+ props=[:antialias, :bottom, :canvas, :cursor, :data, :events, :fill_style, :height, :id, :left, :line_width, :links, :mode, :nodes, :order, :overflow, :padding_bottom, :padding_left, :padding_right, :padding_top, :reverse, :right, :round, :stroke_style, :title, :top, :transform, :visible, :width].inject({}) {|ac, v| ac[v]=true; ac}
6
+ Rubyvis::Layout::Treemap.properties.should==props
7
+ end
8
+ describe "rendered" do
9
+ before do
10
+ color=pv.Colors.category19
11
+ w=200
12
+ h=200
13
+
14
+ @vis = pv.Panel.new()
15
+ .width(w)
16
+ .height(h)
17
+
18
+ treemap = @vis.add(pv.Layout.Treemap).
19
+ nodes(hier_nodes).
20
+ size(lambda {|d| d.node_value})
21
+
22
+ treemap.leaf.add(pv.Panel).
23
+ fill_style(lambda {|d| color[d.node_value]}).
24
+ stroke_style("black").
25
+ line_width(1).
26
+ antialias(false)
27
+
28
+ treemap.node_label.add(pv.Label).
29
+ text(lambda {|d| d.node_value})
30
+
31
+
32
+ @vis.render
33
+
34
+ @pv_out=fixture_svg_read("layout_treemap.svg")
35
+ end
36
+
37
+ it "should render equal to protovis version " do
38
+ @vis.to_svg.should have_same_svg_elements(@pv_out)
39
+ end
40
+ end
41
+ end
data/spec/line_spec.rb CHANGED
@@ -1,8 +1,126 @@
1
1
  require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
2
  describe Rubyvis::Line do
3
+ include Rubyvis::GeneralSpec
3
4
  it "should have correct properties" do
4
5
  props=[:antialias, :bottom, :cursor, :data, :eccentricity, :events, :fill_style, :id, :interpolate, :left, :line_join, :line_width, :reverse, :right, :segmented, :stroke_style, :tension, :title, :top, :visible].inject({}) {|ac, v| ac[v]=true; ac}
5
6
  Rubyvis::Line.properties.should==props
7
+ end
8
+ it "should render correctly 'line_interpolation.html' example" do
9
+ data = pv.range(0, 10, 0.2).map {|x|
10
+ OpenStruct.new({:x=>x, :y=>Math.sin(x) + 2})}
11
+
12
+ p_w=200
13
+ p_h=150
14
+ w = 20+p_w*2
15
+ h = 20+p_h*4
16
+
17
+ p_w=200
18
+ p_h=150
19
+ #p data
20
+ w = 20+p_w*2
21
+ h = 20+p_h*4
22
+
23
+ x = pv.Scale.linear(data, lambda {|d| d.x}).range(0, p_w-30)
24
+
25
+
26
+ y = pv.Scale.linear(data, lambda {|d| d.y}).range(0, p_h-20);
27
+
28
+ interpolations=["linear","step-before","step-after","polar","polar-reverse", "basis", "cardinal"]
29
+
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)
38
+
39
+ interpolations.each_with_index do |inter,i|
40
+ n=i%2
41
+ m=(i/2).floor
42
+ panel=vis.add(Rubyvis::Panel).
43
+ left(n*(p_w+10)).
44
+ top(m*(p_h+10)).
45
+ width(p_w).
46
+ height(p_h)
47
+ panel.anchor('top').add(Rubyvis::Label).text(inter)
48
+ panel.add(Rubyvis::Line).data(data).
49
+ line_width(2).
50
+ left(lambda {|d| x.scale(d.x)}).
51
+ bottom(lambda {|d| y.scale(d.y)}).
52
+ interpolate(inter)
53
+
54
+ end
55
+ vis.render()
56
+ pv_out=fixture_svg_read("line_interpolation.svg")
57
+ vis.to_svg.should have_same_svg_elements(pv_out)
58
+ end
59
+ it "should render correctly 'line_interpolation_segmented.html' example" do
60
+ data = pv.range(0, 10, 0.2).map {|x|
61
+ OpenStruct.new({:x=>x, :y=>Math.sin(x) + 2})}
62
+
63
+ p_w=200
64
+ p_h=150
65
+ w = 20+p_w*2
66
+ h = 20+p_h*4
67
+
68
+ p_w=200
69
+ p_h=150
70
+ #p data
71
+ w = 20+p_w*2
72
+ h = 20+p_h*4
73
+
74
+ x = pv.Scale.linear(data, lambda {|d| d.x}).range(0, p_w-30)
75
+
76
+
77
+ y = pv.Scale.linear(data, lambda {|d| d.y}).range(0, p_h-20);
78
+
79
+ interpolations=["linear","step-before","step-after","polar","polar-reverse", "basis", "cardinal","monotone"]
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)
88
+
89
+ interpolations.each_with_index do |inter,i|
90
+ n=i%2
91
+ m=(i/2).floor
92
+ panel=vis.add(Rubyvis::Panel).
93
+ left(n*(p_w+10)).
94
+ top(m*(p_h+10)).
95
+ width(p_w).
96
+ height(p_h)
97
+
98
+ panel.anchor('top').add(Rubyvis::Label).text(inter)
99
+
100
+ panel.add(Rubyvis::Line).data(data).
101
+ segmented(true).
102
+ line_width(lambda {|d|d.y*2.0+self.index*0.5}).
103
+ left(lambda {|d| x.scale(d.x)}).
104
+ bottom(lambda {|d| y.scale(d.y)}).
105
+ interpolate(inter)
106
+ end
107
+ vis.render()
108
+ pv_out=fixture_svg_read("line_interpolation_segmented.svg")
109
+ vis.to_svg.should have_same_svg_elements(pv_out)
110
+ end
111
+ it "SvgScene.path_join should return correct value" do
112
+ s0=OpenStruct.new({:left=>1,:top=>2,:visible=>true, :line_width=>2.5})
113
+ s1=OpenStruct.new({:left=>3,:top=>4,:visible=>true, :line_width=>2.5})
114
+ s2=OpenStruct.new({:left=>5,:top=>6,:visible=>true, :line_width=>2.5})
115
+ s3=OpenStruct.new({:left=>7,:top=>8,:visible=>true, :line_width=>2.5})
116
+ Rubyvis::SvgScene.path_join(s0,s1,s2,s3).should=="M2.1161165235168156,4.883883476483184L4.116116523516816,6.883883476483184 5.883883476483184,5.116116523516816 3.8838834764831844,3.1161165235168156"
117
+ s0=OpenStruct.new({:left=>1.5,:top=>2,:visible=>true, :line_width=>3})
118
+ s1=OpenStruct.new({:left=>3.5,:top=>4,:visible=>true, :line_width=>3.5})
119
+ s2=OpenStruct.new({:left=>5.5,:top=>6,:visible=>true, :line_width=>4.0})
120
+ s3=OpenStruct.new({:left=>7.5,:top=>8,:visible=>true, :line_width=>4.5})
121
+
122
+ Rubyvis::SvgScene.path_join(s0,s1,s2,s3).should=="M2.2625631329235425,5.2374368670764575L4.2625631329235425,7.2374368670764575 6.7374368670764575,4.7625631329235425 4.7374368670764575,2.7625631329235425"
123
+
6
124
  end
7
125
  context "rendered" do
8
126
  before do
data/spec/mark_spec.rb CHANGED
@@ -12,5 +12,9 @@ describe Rubyvis::Mark do
12
12
  props[0].name.should==:antialias
13
13
  props[2].name.should==:events
14
14
  end
15
+ it "should have 'mark' as type" do
16
+ m=Rubyvis::Mark.new
17
+ m.type.should eql "mark"
18
+ end
15
19
 
16
20
  end
data/spec/panel_spec.rb CHANGED
@@ -20,5 +20,16 @@ describe Rubyvis::Panel do
20
20
  doc=Nokogiri::XML(@vis.to_svg)
21
21
  doc.at_xpath("//xmlns:svg").should have_svg_attributes({"font-size"=>"10px", "font-family"=>"sans-serif", "fill"=>"none", "stroke"=>"none", "stroke-width"=>"1.5", "width"=>"200.0", "height"=>"200.0"})
22
22
  end
23
-
23
+ it "should allow multiple panel definitions" do
24
+ vis2 = Rubyvis.Panel.new.width(@w+100).height(@h+100)
25
+ @vis.render
26
+ vis2.render
27
+ doc1=Nokogiri::XML(@vis.to_svg)
28
+ doc2=Nokogiri::XML(vis2.to_svg)
29
+
30
+ doc1.at_xpath("//xmlns:svg").should have_svg_attributes({"font-size"=>"10px", "font-family"=>"sans-serif", "fill"=>"none", "stroke"=>"none", "stroke-width"=>"1.5", "width"=>"200.0", "height"=>"200.0"})
31
+
32
+ doc2.at_xpath("//xmlns:svg").should have_svg_attributes({"font-size"=>"10px", "font-family"=>"sans-serif", "fill"=>"none", "stroke"=>"none", "stroke-width"=>"1.5", "width"=>"300.0", "height"=>"300.0"})
33
+
34
+ end
24
35
  end
data/spec/rule_spec.rb ADDED
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
+ describe Rubyvis::Rule do
3
+ include Rubyvis::GeneralSpec
4
+ it "should have correct properties" do
5
+ props=[:antialias, :bottom, :cursor, :data, :events, :height, :id, :left, :line_width, :reverse, :right, :stroke_style, :title, :top, :visible, :width].inject({}) {|ac, v| ac[v]=true; ac}
6
+ Rubyvis::Rule.properties.should==props
7
+ end
8
+ it "Rubyvis.Rule be the same as Rubyvis::Rule" do
9
+ Rubyvis.Rule.should eql Rubyvis::Rule
10
+ end
11
+ it "should render equal to protovis 'rule-anchor.html' test" do
12
+ vis = Rubyvis::Panel.new()
13
+ .width(400)
14
+ .height(300)
15
+
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')
24
+
25
+ rule = bar.add(pv.Rule)
26
+ rule.anchor(lambda {|d| d}).add(pv.Label)
27
+ .text(lambda {|d| d})
28
+
29
+ vis.render();
30
+ pv_out=fixture_svg_read("rule_anchor.svg")
31
+ vis.to_svg.should have_same_svg_elements(pv_out)
32
+ end
33
+
34
+ end