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
data.tar.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- du��*��xdI]h1m��%���k(��|)v!�Q�
2
- J(���7��8���im&�u��R��z�X;�z�,�8�m
1
+ ���œ(����l��W�3w����r.�$�mP_ ��>/�t[R�XP1q�]�����QF'bVp�<:f�����>��q4�ĊD��v ��H$��To�i4�G@������DCl"MzH�+9���94������`�ꩂCW#bBq+�{Ώt��,��t�y9 6
2
+ ����g�^]q�S�U=*^!^-/9�q� ��F���
3
+ ��r���G�%�V2�}g�����Ѿ���Ül
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.4.1 / 2011-01-26
2
+ * All tests run on ruby 1.8.7. Not all pass, because on ruby<1.9 hash order are not preserved
3
+ * Removed warnings for Ruby 1.9+
4
+ * Changed SvgScene.implicit and Color.names with constants
5
+ * Bug gix: Examples crashes on Ruby 1.9.3 because names of files are freezed and REXML try to change it
6
+
1
7
  === 0.4.0 / 2011-01-03
2
8
 
3
9
  Massive bug fix. Please, update ASAP
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ h=Hoe.spec 'rubyvis' do
16
16
  self.rspec_options << "-c" << "-b"
17
17
  self.developer('Claudio Bustos', 'clbustos_at_gmail.com')
18
18
  self.version=Rubyvis::VERSION
19
- self.extra_dev_deps << ["coderay",">=0"] << ["haml",">=0"] << ["nokogiri", ">=0"] << ["rspec",">=2.0"]
19
+ self.extra_dev_deps << ["coderay",">=0"] << ["haml",">=0"] << ["nokogiri", ">=0"] << ["rspec",">=2.0"] << ["RedCloth",">=0"]
20
20
  end
21
21
  desc "Publicar docs en rubyforge"
22
22
  task :publicar_docs => [:clean, :docs] do
@@ -18,7 +18,7 @@ def get_files(path)
18
18
  h
19
19
  end
20
20
 
21
- files=get_files(File.dirname(__FILE__)+"/../../lib")
21
+ files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../lib/"))
22
22
 
23
23
  classes = Rubyvis.nodes(Rubyvis.flatten(files).leaf(lambda {|v| v.is_a? Numeric}).array)
24
24
 
@@ -49,7 +49,7 @@ vis = pv.Panel.new()
49
49
  visible( lambda {|n| n.parent_node}).
50
50
  fill_style(lambda {|n|
51
51
  colors20.scale(n.parent_node).
52
- lighter((n.node_value) / 5.0)
52
+ brighter((n.node_value) / 5.0)
53
53
  }).
54
54
  stroke_style(c20)
55
55
 
@@ -22,7 +22,7 @@ def get_files(path)
22
22
  h
23
23
  end
24
24
 
25
- files=get_files(File.dirname(__FILE__)+"/../../lib/")
25
+ files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../lib/"))
26
26
 
27
27
  format = Rubyvis::Format.number();
28
28
 
@@ -19,7 +19,7 @@ def get_files(path)
19
19
  h
20
20
  end
21
21
 
22
- files=get_files(File.dirname(__FILE__)+"/../../lib/")
22
+ files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../lib/"))
23
23
 
24
24
 
25
25
  vis = Rubyvis::Panel.new do
@@ -18,7 +18,7 @@ def get_files(path)
18
18
  h
19
19
  end
20
20
 
21
- files=get_files(File.dirname(__FILE__)+"/../../")
21
+ files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../lib/"))
22
22
 
23
23
  colors=Rubyvis::Colors.category19
24
24
  vis = Rubyvis::Panel.new.
@@ -21,7 +21,7 @@ def get_files(path)
21
21
  h
22
22
  end
23
23
 
24
- files=get_files(File.dirname(__FILE__)+"/../../")
24
+ files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../lib/"))
25
25
 
26
26
 
27
27
  root = Rubyvis.dom(files)
@@ -20,7 +20,7 @@ end
20
20
 
21
21
 
22
22
 
23
- files=get_files(File.dirname(__FILE__)+"/../../")
23
+ files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../"))
24
24
  #files={:b=>{:c=>1,:d=>2}}
25
25
 
26
26
 
@@ -19,7 +19,7 @@ def get_files(path)
19
19
  h
20
20
  end
21
21
 
22
- files=get_files(File.dirname(__FILE__)+"/../../lib/rubyvis/")
22
+ files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../lib/rubyvis/"))
23
23
 
24
24
  #load(File.dirname(__FILE__)+"/treemap/treemap_data.rb")
25
25
 
@@ -19,7 +19,7 @@ def get_files(path)
19
19
  h
20
20
  end
21
21
 
22
- files=get_files(File.dirname(__FILE__)+"/../../")
22
+ files=get_files(File.expand_path(File.dirname(__FILE__)+"/../../lib/"))
23
23
 
24
24
  format=Rubyvis::Format.number
25
25
  color = pv.Colors.category20
data/lib/rubyvis.rb CHANGED
@@ -32,7 +32,7 @@ require 'rubyvis/mark/shorcut_methods'
32
32
  module Rubyvis
33
33
  @document=nil
34
34
  # Rubyvis version
35
- VERSION = '0.4.0'
35
+ VERSION = '0.4.1'
36
36
  # Protovis API on which current Rubyvis is based
37
37
  PROTOVIS_API_VERSION='3.3'
38
38
  # You actually can do it! http://snipplr.com/view/2137/uses-for-infinity-in-ruby/
@@ -53,7 +53,7 @@ module Rubyvis
53
53
  end
54
54
  end
55
55
 
56
- named = Rubyvis::Color.names[format.to_sym]
56
+ named = Rubyvis::Color::NAMES[format.to_sym]
57
57
 
58
58
 
59
59
  return Rubyvis.color(named) if (named)
@@ -88,41 +88,9 @@ module Rubyvis
88
88
  # space is dependent on the implementing class; all colors support the
89
89
  # Color.rgb() method to convert to RGB color space for interpolation.
90
90
  class Color
91
- # An opaque color format string, such as "#f00".
92
- attr_reader :color
93
- # The opacity, a float in [0, 1].
94
- attr_reader :opacity
95
-
96
- # Constructs a color with the specified color format string and opacity. This
97
- # constructor should not be invoked directly; use Rubyvis.color instead.
98
- def initialize(color,opacity)
99
- @color=color
100
- @opacity=opacity
101
- end
102
- # Returns a new color that is a brighter version of this color. The behavior of
103
- # this method may vary slightly depending on the underlying color space.
104
- # Although brighter and darker are inverse operations, the results of a series
105
- # of invocations of these two methods might be inconsistent because of rounding
106
- # errors.
107
- # * @param [k] {number} an optional scale factor; defaults to 1.
108
- def brighter(k)
109
- self.rgb.brighter(k)
110
- end
111
-
112
- # Returns a new color that is a brighter version of this color. The behavior of
113
- # this method may vary slightly depending on the underlying color space.
114
- # Although brighter and darker are inverse operations, the results of a series
115
- # of invocations of these two methods might be inconsistent because of rounding
116
- # errors.
117
- #
118
- # * @param [k] {number} an optional scale factor; defaults to 1.
119
- def darker(k)
120
- self.rgb.darker(k)
121
- end
122
91
 
123
92
  # Association between names and colors
124
- def self.names # :nodoc:
125
- {
93
+ NAMES={
126
94
  :aliceblue=>"#f0f8ff",
127
95
  :antiquewhite=>"#faebd7",
128
96
  :aqua=>"#00ffff",
@@ -271,7 +239,40 @@ module Rubyvis
271
239
  :yellow=>"#ffff00",
272
240
  :yellowgreen=>"#9acd32",
273
241
  }
242
+
243
+
244
+ # An opaque color format string, such as "#f00".
245
+ attr_reader :color
246
+ # The opacity, a float in [0, 1].
247
+ attr_reader :opacity
248
+
249
+ # Constructs a color with the specified color format string and opacity. This
250
+ # constructor should not be invoked directly; use Rubyvis.color instead.
251
+ def initialize(color,opacity)
252
+ @color=color
253
+ @opacity=opacity
254
+ end
255
+ # Returns a new color that is a brighter version of this color. The behavior of
256
+ # this method may vary slightly depending on the underlying color space.
257
+ # Although brighter and darker are inverse operations, the results of a series
258
+ # of invocations of these two methods might be inconsistent because of rounding
259
+ # errors.
260
+ # * @param [k] {number} an optional scale factor; defaults to 1.
261
+ def brighter(k)
262
+ self.rgb.brighter(k)
263
+ end
264
+
265
+ # Returns a new color that is a brighter version of this color. The behavior of
266
+ # this method may vary slightly depending on the underlying color space.
267
+ # Although brighter and darker are inverse operations, the results of a series
268
+ # of invocations of these two methods might be inconsistent because of rounding
269
+ # errors.
270
+ #
271
+ # * @param [k] {number} an optional scale factor; defaults to 1.
272
+ def darker(k)
273
+ self.rgb.darker(k)
274
274
  end
275
+
275
276
  def self.transparent
276
277
  Rubyvis.rgb(0,0,0,0)
277
278
  end
@@ -9,7 +9,7 @@ module Rubyvis
9
9
  #
10
10
  # <pre> pv.Scale.linear().domain(0, 1).range(...)</pre>
11
11
  def self.ramp(*arguments)
12
- start, _end, dummy = arguments
12
+ #start, _end, dummy = arguments
13
13
  scale = Rubyvis.Scale.linear
14
14
  scale.range(*arguments)
15
15
  scale
@@ -70,7 +70,7 @@ module Rubyvis
70
70
  norm.map {|x| x.quo(sum)}
71
71
  end
72
72
  def self.o_index(i)
73
- o=OpenStruct.new :index=>i
73
+ OpenStruct.new :index=>i
74
74
  end
75
75
  def self.permute(array,indexes, f=nil)
76
76
  f=Rubyvis.identity if f.nil?
@@ -127,7 +127,7 @@ module Rubyvis
127
127
  start = 0
128
128
  end
129
129
  step||= 1
130
- raise "range must be finite" if ((stop - start) / step.to_f).infinite?
130
+ raise "range must be finite" if ((stop.to_f - start.to_f) / step.to_f).infinite?
131
131
  array = []
132
132
  i = 0
133
133
  stop = stop- (stop - start) * 1e-10 #// floating point precision!
@@ -22,7 +22,10 @@ module Rubyvis
22
22
  func=nil
23
23
  end
24
24
  @properties[name]=true
25
- self.property_method(name,false, func, self)
25
+ self.property_method(name,false, func, self)
26
+
27
+ remove_method(name.to_s+"=") if public_method_defined? name.to_s+"="
28
+
26
29
  define_method(name.to_s + "=") {|v|
27
30
  self.send(name,v)
28
31
  }
@@ -1,6 +1,6 @@
1
1
  module Rubyvis
2
2
  class Layout
3
- # Alias for Rubyvis::Layout::Matrix
3
+ # Alias for Rubyvis::Layout::Matrix
4
4
  def self.Matrix
5
5
  Rubyvis::Layout::Matrix
6
6
  end
@@ -53,16 +53,16 @@ module Rubyvis
53
53
  end
54
54
  # Deletes special add from network
55
55
  def _link # :nodoc:
56
- that=self
56
+ #that=self
57
57
  l=Mark.new().
58
- mark_extend(@node).
59
- data(lambda {|d| [d.source_node, d.target_node] }).
60
- fill_style(nil).
61
- line_width(lambda {|d,_p| _p.link_value * 1.5 }).
62
- stroke_style("rgba(0,0,0,.2)")
58
+ mark_extend(@node).
59
+ data(lambda {|d| [d.source_node, d.target_node] }).
60
+ fill_style(nil).
61
+ line_width(lambda {|d,_p| _p.link_value * 1.5 }).
62
+ stroke_style("rgba(0,0,0,.2)")
63
63
  l
64
64
  end
65
-
65
+
66
66
  def initialize
67
67
  super
68
68
  @_n=nil, # cached matrix size
@@ -72,117 +72,117 @@ module Rubyvis
72
72
  @_pairs=nil, # cached pairs (array of links)
73
73
  that=self
74
74
  #/* Links are all pairs of nodes. */
75
- @link.data(lambda {that._pairs})
76
- .left(lambda { that._dx * (self.index % that._n) })
77
- .top(lambda { that._dy * (self.index / that._n.to_f).floor })
78
- .width(lambda { that._dx })
79
- .height(lambda { that._dy })
80
- .line_width(1.5)
81
- .stroke_style("#fff")
82
- .fill_style(lambda {|l| l.link_value!=0 ? "#555" : "#eee" })
83
-
75
+ @link.data(lambda {that._pairs}).
76
+ left(lambda { that._dx * (self.index % that._n) }).
77
+ top(lambda { that._dy * (self.index / that._n.to_f).floor }).
78
+ width(lambda { that._dx }).
79
+ height(lambda { that._dy }).
80
+ line_width(1.5).
81
+ stroke_style("#fff").
82
+ fill_style(lambda {|l| l.link_value!=0 ? "#555" : "#eee" })
83
+
84
84
  @link.parent = self
85
85
  #/* No special add for links! */
86
-
86
+
87
87
  # delete this.link.add;
88
88
 
89
89
  #/* Labels are duplicated for top & left. */
90
90
  @node_label.
91
- data(lambda { that._labels }).
92
- left(lambda { (self.index & 1)!=0 ? that._dx * ((self.index >> 1) + 0.5) : 0 }).
93
- top(lambda { (self.index & 1)!=0 ? 0 : that._dy * ((self.index >> 1) + 0.5) }).
94
- text_margin(4).text_align(lambda { (self.index & 1)!=0 ? "left" : "right"; }).
95
- text_angle(lambda { (self.index & 1)!=0 ? -Math::PI / 2.0 : 0; });
96
- @node=nil
97
- end
98
- def self.defaults
99
- Matrix.new.mark_extend(Network.defaults).
100
- directed(true)
101
- end
102
- ##
103
- # :attr: directed
104
- #
105
- # Whether this matrix visualization is directed (bidirectional). By default,
106
- # the graph is assumed to be undirected, such that the visualization is
107
- # symmetric across the matrix diagonal. If the network is directed, then
108
- # forward links are drawn above the diagonal, while reverse links are drawn
109
- # below.
110
- #
111
- # @type boolean
112
- # @name pv.Layout.Matrix.prototype.directed
113
- #/
114
-
115
- attr_accessor_dsl :directed
116
-
91
+ data(lambda { that._labels }).
92
+ left(lambda { (self.index & 1)!=0 ? that._dx * ((self.index >> 1) + 0.5) : 0 }).
93
+ top(lambda { (self.index & 1)!=0 ? 0 : that._dy * ((self.index >> 1) + 0.5) }).
94
+ text_margin(4).text_align(lambda { (self.index & 1)!=0 ? "left" : "right"; }).
95
+ text_angle(lambda { (self.index & 1)!=0 ? -Math::PI / 2.0 : 0; });
96
+ @node=nil
97
+ end
98
+ def self.defaults
99
+ Matrix.new.mark_extend(Network.defaults).
100
+ directed(true)
101
+ end
102
+ ##
103
+ # :attr: directed
104
+ #
105
+ # Whether this matrix visualization is directed (bidirectional). By default,
106
+ # the graph is assumed to be undirected, such that the visualization is
107
+ # symmetric across the matrix diagonal. If the network is directed, then
108
+ # forward links are drawn above the diagonal, while reverse links are drawn
109
+ # below.
110
+ #
111
+ # @type boolean
112
+ # @name pv.Layout.Matrix.prototype.directed
113
+ #/
114
+
115
+ attr_accessor_dsl :directed
116
+
117
117
 
118
- # Specifies an optional sort function. The sort function follows the same
119
- # comparator contract required by {@link pv.Dom.Node#sort}. Specifying a sort
120
- # function provides an alternative to sort the nodes as they are specified by
121
- # the <tt>nodes</tt> property; the main advantage of doing this is that the
122
- # comparator function can access implicit fields populated by the network
123
- # layout, such as the <tt>linkDegree</tt>.
124
- #
125
- # <p>Note that matrix visualizations are particularly sensitive to order. This
126
- # is referred to as the seriation problem, and many different techniques exist
127
- # to find good node orders that emphasize clusters, such as spectral layout and
128
- # simulated annealing.
129
- #
130
- # @param {function} f comparator function for nodes.
131
- # @returns {pv.Layout.Matrix} this.
132
- #/
133
- def sort(f=nil,&block)
134
- f||=block
135
- @sort=f
136
- self
118
+ # Specifies an optional sort function. The sort function follows the same
119
+ # comparator contract required by {@link pv.Dom.Node#sort}. Specifying a sort
120
+ # function provides an alternative to sort the nodes as they are specified by
121
+ # the <tt>nodes</tt> property; the main advantage of doing this is that the
122
+ # comparator function can access implicit fields populated by the network
123
+ # layout, such as the <tt>linkDegree</tt>.
124
+ #
125
+ # <p>Note that matrix visualizations are particularly sensitive to order. This
126
+ # is referred to as the seriation problem, and many different techniques exist
127
+ # to find good node orders that emphasize clusters, such as spectral layout and
128
+ # simulated annealing.
129
+ #
130
+ # @param {function} f comparator function for nodes.
131
+ # @returns {pv.Layout.Matrix} this.
132
+ #/
133
+ def sort(f=nil,&block)
134
+ f||=block
135
+ @sort=f
136
+ self
137
+ end
138
+ def build_implied(s) # :nodoc:
139
+ return nil if network_build_implied(s)
140
+ nodes = s.nodes
141
+ links = s.links
142
+ sort = @sort
143
+
144
+ n = nodes.size
145
+ index = Rubyvis.range(n)
146
+ labels = []
147
+ pairs = []
148
+ map = {}
149
+
150
+ s._matrix = OpenStruct.new({:labels=> labels, :pairs=> pairs})
151
+
152
+ #/* Sort the nodes. */
153
+ if sort
154
+ index.sort! {|a,b| sort.call(nodes[a],nodes[b])}
137
155
  end
138
- def build_implied(s) # :nodoc:
139
- return nil if network_build_implied(s)
140
- nodes = s.nodes
141
- links = s.links
142
- sort = @sort
143
-
144
- n = nodes.size
145
- index = Rubyvis.range(n)
146
- labels = []
147
- pairs = []
148
- map = {}
149
-
150
- s._matrix = OpenStruct.new({:labels=> labels, :pairs=> pairs})
151
-
152
- #/* Sort the nodes. */
153
- if sort
154
- index.sort! {|a,b| sort.call(nodes[a],nodes[b])}
155
- end
156
- #/* Create pairs. */
157
- n.times {|i|
158
- n.times {|j|
156
+ #/* Create pairs. */
157
+ n.times {|i|
158
+ n.times {|j|
159
159
  a = index[i]
160
160
  b = index[j]
161
161
  _p = OpenStruct.new({
162
- :row=> i,
163
- :col=> j,
164
- :source_node=> nodes[a],
165
- :target_node=> nodes[b],
166
- :link_value=> 0})
162
+ :row=> i,
163
+ :col=> j,
164
+ :source_node=> nodes[a],
165
+ :target_node=> nodes[b],
166
+ :link_value=> 0})
167
167
  map["#{a}.#{b}"] = _p
168
168
  pairs.push(map["#{a}.#{b}"])
169
- }
170
169
  }
171
- #/* Create labels. */
172
- n.times {|i|
173
- a = index[i]
174
- labels.push(nodes[a], nodes[a])
175
- }
176
- #/* Accumulate link values. */
177
- links.each_with_index {|l,i|
178
- source = l.source_node.index
179
- target = l.target_node.index
180
- value = l.link_value
181
- map["#{source}.#{target}"].link_value += value
182
- map["#{target}.#{source}"].link_value += value if (!s.directed)
183
- }
184
- build_implied_post(s)
185
- end
170
+ }
171
+ #/* Create labels. */
172
+ n.times {|i|
173
+ a = index[i]
174
+ labels.push(nodes[a], nodes[a])
175
+ }
176
+ #/* Accumulate link values. */
177
+ links.each_with_index {|l,i|
178
+ source = l.source_node.index
179
+ target = l.target_node.index
180
+ value = l.link_value
181
+ map["#{source}.#{target}"].link_value += value
182
+ map["#{target}.#{source}"].link_value += value if (!s.directed)
183
+ }
184
+ build_implied_post(s)
186
185
  end
187
186
  end
188
187
  end
188
+ end