rubyvis 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -121,7 +121,7 @@ module Rubyvis
121
121
 
122
122
 
123
123
  def _link # :nodoc:
124
- that=self
124
+ #that=self
125
125
  l=Mark.new().
126
126
  mark_extend(@node).
127
127
  data(lambda {|d| [d.source_node, d.target_node] }).
@@ -135,7 +135,7 @@ module Rubyvis
135
135
 
136
136
 
137
137
  def _node_label #:nodoc:
138
- that=self
138
+ #that=self
139
139
  nl=Mark.new().
140
140
  mark_extend(@node).
141
141
  text_margin(7).
@@ -185,7 +185,7 @@ module Rubyvis
185
185
 
186
186
 
187
187
  attr_accessor_dsl [:links, lambda {|v|
188
- out=[]
188
+ # out=[]
189
189
  v.map {|d|
190
190
  if !d.link_value.is_a? Numeric
191
191
  d.link_value = !d.value.is_a?(Numeric) ? 1 : d.value
data/lib/rubyvis/mark.rb CHANGED
@@ -184,7 +184,8 @@ module Rubyvis
184
184
  def self.property_method(name, _def, func=nil, klass=nil)
185
185
  return if klass.method_defined? name
186
186
  klass.send(:define_method, name) do |*arguments,&block|
187
- v,dummy = arguments
187
+ v=arguments[0]
188
+ #v,dummy = arguments
188
189
  if block
189
190
  v=block
190
191
  end
@@ -803,8 +804,8 @@ module Rubyvis
803
804
  stack.shift
804
805
  else
805
806
  mark.build
806
- Rubyvis.Scene.scale = scale;
807
- Rubyvis.Scene.update_all(mark.scene);
807
+ Rubyvis::SvgScene.scale = scale;
808
+ Rubyvis::SvgScene.update_all(mark.scene);
808
809
  end
809
810
  mark.scale=nil
810
811
  end
@@ -947,7 +948,7 @@ module Rubyvis
947
948
  end while(mark=mark.parent)
948
949
  end
949
950
  def context(scene, index, f) # :nodoc:
950
- proto=Mark
951
+ #proto=Mark
951
952
  stack=Mark.stack
952
953
  oscene=Mark.scene
953
954
  oindex=Mark.index
@@ -88,7 +88,7 @@ module Rubyvis
88
88
 
89
89
 
90
90
  def area_anchor(name)
91
- scene=nil
91
+ #scene=nil
92
92
  anchor=mark_anchor(name)
93
93
  anchor.interpolate(lambda {
94
94
  self.scene.target[self.index].interpolate
@@ -61,7 +61,7 @@ module Rubyvis
61
61
  # though this typically results in slower performance.
62
62
 
63
63
  def dynamic_image(f)
64
- f,dummy=arguments
64
+ #f,dummy=arguments
65
65
  @_image = lambda {|*args|
66
66
  c=f.js_apply(self,args)
67
67
  c.nil? ? pv.Color.transparent : (c.is_a?(String) ? Rubyvis.color(c) : c )
@@ -21,8 +21,8 @@ module Rubyvis
21
21
  def build_implied(s)
22
22
  l=s.left
23
23
  r=s.right
24
- t=s.top
25
- b=s.bottom
24
+ #t=s.top
25
+ #b=s.bottom
26
26
 
27
27
  if((!s.width.nil?) or ((l.nil?) and (r.nil?)) or ((!r.nil?) and (!l.nil?)))
28
28
  s.height=0
@@ -17,6 +17,7 @@ class Rubyvis::Mark
17
17
  if block
18
18
  block.arity<1 ? a.instance_eval(&block) : block.call(a)
19
19
  end
20
+ a
20
21
  end
21
22
  end
22
23
  ##
@@ -31,63 +31,72 @@ module Rubyvis
31
31
  mark_anchor(name).left(lambda {
32
32
  s = self.scene.target[self.index];
33
33
  if (partial.call(s))
34
-
35
34
  case (self.name())
36
35
  when "outer"
37
- return s.left + s.outer_radius * Math.cos(mid_angle.call(s))
36
+ s.left + s.outer_radius * Math.cos(mid_angle.call(s))
38
37
  when "inner"
39
- return s.left + s.inner_radius * Math.cos(mid_angle.call(s))
38
+ s.left + s.inner_radius * Math.cos(mid_angle.call(s))
40
39
  when "start"
41
- return s.left + mid_radius.call(s) * Math.cos(s.start_angle)
40
+ s.left + mid_radius.call(s) * Math.cos(s.start_angle)
42
41
  when "center"
43
- return s.left + mid_radius.call(s) * Math.cos(mid_angle.call(s))
42
+ s.left + mid_radius.call(s) * Math.cos(mid_angle.call(s))
44
43
  when "end"
45
- return s.left + mid_radius.call(s) * Math.cos(s.end_angle)
44
+ s.left + mid_radius.call(s) * Math.cos(s.end_angle)
45
+ else
46
+ s.left
46
47
  end
47
- end
48
- return s.left;
48
+ else
49
+ s.left
50
+ end
49
51
  }).top(lambda {
50
52
  s = self.scene.target[self.index];
51
53
  if (partial.call(s))
52
54
  case (self.name())
53
55
  when "outer"
54
- return s.top + s.outer_radius * Math.sin(mid_angle.call(s))
56
+ s.top + s.outer_radius * Math.sin(mid_angle.call(s))
55
57
  when "inner"
56
- return s.top + s.inner_radius * Math.sin(mid_angle.call(s))
58
+ s.top + s.inner_radius * Math.sin(mid_angle.call(s))
57
59
  when "start"
58
- return s.top + mid_radius.call(s) * Math.sin(s.start_angle)
60
+ s.top + mid_radius.call(s) * Math.sin(s.start_angle)
59
61
  when "center"
60
- return s.top + mid_radius.call(s) * Math.sin(mid_angle.call(s))
62
+ s.top + mid_radius.call(s) * Math.sin(mid_angle.call(s))
61
63
  when "end"
62
- return s.top + mid_radius.call(s) * Math.sin(s.end_angle)
64
+ s.top + mid_radius.call(s) * Math.sin(s.end_angle)
65
+ else
66
+ s.top
63
67
  end
68
+ else
69
+ s.top
64
70
  end
65
- return s.top;
66
71
 
67
72
  }).text_align(lambda {
68
73
  s = self.scene.target[self.index];
69
74
  if (partial.call(s))
70
75
  case (self.name())
71
76
  when 'outer'
72
- return that.upright(mid_angle.call(s)) ? 'right':'left'
77
+ that.upright(mid_angle.call(s)) ? 'right':'left'
73
78
  when 'inner'
74
- return that.upright(mid_angle.call(s)) ? 'left':'right'
75
-
79
+ that.upright(mid_angle.call(s)) ? 'left':'right'
80
+ else
81
+ 'center'
76
82
  end
83
+ else
84
+ 'center'
77
85
  end
78
- return 'center'
79
86
  }).text_baseline(lambda {
80
87
  s = self.scene.target[self.index];
81
88
  if (partial.call(s))
82
89
  case (self.name())
83
90
  when 'start'
84
- return that.upright(s.start_angle) ? 'top':'bottom'
91
+ that.upright(s.start_angle) ? 'top':'bottom'
85
92
  when 'end'
86
- return that.upright(s.end_angle) ? 'bottom':'top'
87
-
93
+ that.upright(s.end_angle) ? 'bottom':'top'
94
+ else
95
+ 'middle'
88
96
  end
97
+ else
98
+ 'middle'
89
99
  end
90
- return 'middle'
91
100
  }).text_angle(lambda {
92
101
  s = self.scene.target[self.index];
93
102
  a=0
data/lib/rubyvis/nest.rb CHANGED
@@ -18,7 +18,7 @@ module Rubyvis
18
18
  @values=opts[:values]
19
19
  end
20
20
  def ==(var)
21
- key==var.key and values=var.values
21
+ key==var.key and values==var.values
22
22
  end
23
23
  end
24
24
  # :startdoc:
@@ -82,7 +82,7 @@ module Rubyvis
82
82
  end
83
83
  @r[@i[x] % @r.size]
84
84
  end
85
- alias :[] :scale
85
+ alias :[] :scale
86
86
  # Sets or gets the input domain. This method can be invoked several ways:
87
87
  #
88
88
  # <p>1. <tt>domain(values...)</tt>
@@ -393,7 +393,8 @@ module Rubyvis
393
393
 
394
394
  @tick_format= Rubyvis.Format.number.fraction_digits([0, -(Rubyvis.log(step, 10) + 0.01).floor].max).to_proc
395
395
 
396
- ticks = Rubyvis.range(start, _end + step, step);
396
+ ticks = Rubyvis.range(start, _end + step, step)
397
+
397
398
  return reverse ? ticks.reverse() : ticks;
398
399
  end
399
400
 
@@ -258,11 +258,14 @@ module Rubyvis::SvgScene
258
258
  d = []
259
259
  m = []
260
260
  dx = []
261
- k=0
261
+ #k=0
262
262
 
263
263
  #/* Compute the slopes of the secant lines between successive points. */
264
264
 
265
- while(k < points.size-1) do
265
+
266
+ 0.upto(points.size-2) do |k|
267
+
268
+ # while(k < points.size-1) do
266
269
  d[k] = (points[k+1].top - points[k].top) / (points[k+1].left - points[k].left).to_f
267
270
  k+=1
268
271
  end
@@ -270,31 +273,38 @@ module Rubyvis::SvgScene
270
273
  #/* Initialize the tangents at every point as the average of the secants. */
271
274
  m[0] = d[0]
272
275
  dx[0] = points[1].left - points[0].left
276
+
277
+
273
278
  1.upto(points.size-2) {|k|
274
279
  m[k] = (d[k-1]+d[k]) / 2.0
275
280
  dx[k] = (points[k+1].left - points[k-1].left) / 2.0
276
281
  }
282
+
283
+ k=points.size-1
284
+
277
285
  m[k] = d[k-1];
278
286
  dx[k] = (points[k].left - points[k-1].left);
279
287
 
280
288
  # /* Step 3. Very important, step 3. Yep. Wouldn't miss it. */
281
- (points.size-1).times {|k|
282
- if d[k] == 0
283
- m[ k ] = 0;
284
- m[k+1] = 0;
289
+ (points.size-1).times {|kk|
290
+ if d[kk] == 0
291
+ m[ kk ] = 0;
292
+ m[kk + 1] = 0;
285
293
  end
286
294
  }
287
295
 
288
296
  # /* Step 4 + 5. Out of 5 or more steps. */
289
- (points.size-1).times {|k|
290
- next if ((m[k].abs < 1e-5) or (m[k+1].abs < 1e-5))
291
- ak = m[k] / d[k].to_f
292
- bk = m[k + 1] / d[k].to_f
293
- s = ak * ak + bk * bk; # monotone constant (?)
297
+
298
+
299
+ (points.size-1).times {|kk|
300
+ next if ((m[kk].abs < 1e-5) or (m[kk+1].abs < 1e-5))
301
+ akk = m[kk] / d[kk].to_f
302
+ bkk = m[kk + 1] / d[kk].to_f
303
+ s = akk * akk + bkk * bkk; # monotone constant (?)
294
304
  if (s > 9)
295
- tk = 3.0 / Math.sqrt(s)
296
- m[k] = tk * ak * d[k]
297
- m[k + 1] = tk * bk * d[k]
305
+ tkk = 3.0 / Math.sqrt(s)
306
+ m[kk] = tkk * akk * d[kk]
307
+ m[kk + 1] = tkk * bkk * d[kk]
298
308
  end
299
309
  }
300
310
  len=nil;
@@ -39,7 +39,7 @@ module Rubyvis
39
39
  "pointer-events"=> s.events,
40
40
  "cursor"=> s.cursor,
41
41
  "fill"=> fill.color,
42
- "fill-opacity"=> (fill.opacity==0) ? nil :fill.opacity,
42
+ "fill-opacity"=> (fill.opacity==0) ? nil : fill.opacity,
43
43
  "stroke"=> stroke.color,
44
44
  "stroke-opacity"=> (stroke.opacity==0) ? nil : stroke.opacity,
45
45
  "stroke-width"=> (stroke.opacity!=0) ? s.line_width / self.scale : nil
@@ -40,8 +40,9 @@ module Rubyvis
40
40
  "fill-opacity"=> fill.opacity==0 ? nil : fill.opacity,
41
41
  "text-anchor"=> anchor
42
42
  }, {
43
- "font"=> s.font, "text-shadow"=> s.text_shadow, "text-decoration"=> s.text_decoration })
44
- e.text=s.text
43
+ "font"=> s.font, "text-shadow"=> s.text_shadow, "text-decoration"=> s.text_decoration})
44
+
45
+ e.text=s.text.frozen? ? s.text.dup : s.text
45
46
 
46
47
 
47
48
  e=SvgScene.append(e,scenes,i)
@@ -14,9 +14,6 @@ class REXML::Element #:nodoc:
14
14
  end
15
15
 
16
16
  module Rubyvis
17
- def self.Scene # :nodoc:
18
- Rubyvis::SvgScene
19
- end
20
17
  module SvgScene # :nodoc:
21
18
  #include REXML
22
19
  def self.svg
@@ -38,8 +35,7 @@ module Rubyvis
38
35
  def self.scale=(v)
39
36
  @scale=v
40
37
  end
41
- def self.implicit
42
- svg={
38
+ IMPLICIT={:svg=>{
43
39
  "shape-rendering"=> "auto",
44
40
  "pointer-events"=> "painted",
45
41
  "x"=> 0,
@@ -53,11 +49,9 @@ module Rubyvis
53
49
  "stroke-opacity"=> 1,
54
50
  "stroke-width"=> 1.5,
55
51
  "stroke-linejoin"=> "miter"
56
- }
57
- css={"font"=>"10px sans-serif"}
58
-
59
- {:svg=>svg,:css=>css}
60
- end
52
+ },:css=>{"font"=>"10px sans-serif"}
53
+ }
54
+
61
55
  def self.update_all(scenes)
62
56
  puts "update_all: #{scenes.inspect}" if $DEBUG
63
57
  if (scenes.size>0 and scenes[0].reverse and scenes.type!='line' and scenes.type!='area')
@@ -130,7 +124,7 @@ module Rubyvis
130
124
  e = self.create(type)
131
125
  end
132
126
  attributes.each {|name,value|
133
- value = nil if (value == self.implicit[:svg][name])
127
+ value = nil if (value == IMPLICIT[:svg][name])
134
128
  if (value.nil?)
135
129
  e.delete_attribute(name)
136
130
  else
@@ -147,7 +141,7 @@ module Rubyvis
147
141
  array_styles[$1]=$2
148
142
  }
149
143
  style.each {|name,value|
150
- value=nil if value==self.implicit[:css][name]
144
+ value=nil if value==IMPLICIT[:css][name]
151
145
  if (value.nil?)
152
146
  array_styles.delete(name)
153
147
  else
data/spec/anchor_spec.rb CHANGED
@@ -107,9 +107,9 @@ describe Rubyvis::Anchor do
107
107
  end
108
108
  end
109
109
  it "should render equal to protovis 'anchor.html' example" do
110
- @vis = Rubyvis::Panel.new()
111
- .width(200)
112
- .height(200)
110
+ @vis = Rubyvis::Panel.new().
111
+ width(200).
112
+ height(200)
113
113
 
114
114
  @vis.add(Rubyvis::Bar).
115
115
  fill_style("#ccc").
data/spec/area_spec.rb CHANGED
@@ -10,21 +10,21 @@ describe Rubyvis::Area do
10
10
  end
11
11
  it "should render equal to protovis 'area-segmented.html' test" do
12
12
  data=Rubyvis.range(0, 6, 0.1).map {|x| Math.sin(x)}
13
- vis = Rubyvis.Panel.new()
14
- .width(500)
15
- .height(200)
16
- .top(50)
17
- .bottom(50)
18
- .left(10)
19
- .right(10)
13
+ vis = Rubyvis.Panel.new().
14
+ width(500).
15
+ height(200).
16
+ top(50).
17
+ bottom(50).
18
+ left(10).
19
+ right(10)
20
20
 
21
- vis.add(Rubyvis::Area)
22
- .segmented(true)
23
- .data(data)
24
- .bottom(0)
25
- .left(lambda {self.index / 59.0 * 500})
26
- .height(lambda {|d| (d + 1) / 2.0 * 200 + 50})
27
- .fill_style(lambda {|d| "hsl(#{(d + 1) * 180.0},50,50)"})
21
+ vis.add(Rubyvis::Area).
22
+ segmented(true).
23
+ data(data).
24
+ bottom(0).
25
+ left(lambda {self.index / 59.0 * 500}).
26
+ height(lambda {|d| (d + 1) / 2.0 * 200 + 50}).
27
+ fill_style(lambda {|d| "hsl(#{(d + 1) * 180.0},50,50)"})
28
28
  vis.render()
29
29
  pv_out=fixture_svg_read("area_segmented.svg")
30
30
  vis.to_svg.should have_same_svg_elements(pv_out)
@@ -53,13 +53,13 @@ describe Rubyvis::Area do
53
53
  interpolations=["linear","step-before","step-after", "basis", "cardinal", "monotone"]
54
54
 
55
55
  #/* The root panel. */
56
- vis = pv.Panel.new()
57
- .width(w)
58
- .height(h)
59
- .bottom(20)
60
- .left(20)
61
- .right(10)
62
- .top(5)
56
+ vis = pv.Panel.new().
57
+ width(w).
58
+ height(h).
59
+ bottom(20).
60
+ left(20).
61
+ right(10).
62
+ top(5)
63
63
 
64
64
  interpolations.each_with_index do |inter,i|
65
65
  n=i%2
@@ -74,7 +74,7 @@ describe Rubyvis::Area do
74
74
  panel.add(Rubyvis::Area).data(data).
75
75
  bottom(0).
76
76
  segmented(true).
77
- fill_style(lambda {return color[self.index]}).
77
+ fill_style(lambda {color[self.index]}).
78
78
  left(lambda {|d| x.scale(d.x)}).
79
79
  height(lambda {|d| y.scale(d.y)}).
80
80
  interpolate(inter)