rubyvis 0.2.2 → 0.3.0
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.
- data.tar.gz.sig +0 -0
- data/History.txt +10 -0
- data/Manifest.txt +7 -0
- data/Rakefile +2 -10
- data/examples/antibiotics/antibiotics_scatter.rb +4 -5
- data/examples/antibiotics/antibiotics_wedge.rb +0 -1
- data/examples/treemap/treemap.rb +29 -0
- data/examples/treemap/treemap_data.rb +285 -0
- data/lib/rubyvis.rb +2 -1
- data/lib/rubyvis/dom.rb +313 -0
- data/lib/rubyvis/layout.rb +8 -0
- data/lib/rubyvis/layout/hierarchy.rb +247 -0
- data/lib/rubyvis/layout/network.rb +228 -0
- data/lib/rubyvis/layout/stack.rb +2 -2
- data/lib/rubyvis/layout/treemap.rb +357 -0
- data/lib/rubyvis/mark.rb +10 -8
- data/lib/rubyvis/mark/anchor.rb +1 -1
- data/lib/rubyvis/mark/area.rb +1 -1
- data/lib/rubyvis/mark/bar.rb +1 -1
- data/lib/rubyvis/mark/dot.rb +1 -1
- data/lib/rubyvis/mark/image.rb +1 -1
- data/lib/rubyvis/mark/label.rb +1 -1
- data/lib/rubyvis/mark/line.rb +1 -1
- data/lib/rubyvis/mark/panel.rb +1 -1
- data/lib/rubyvis/mark/rule.rb +1 -1
- data/lib/rubyvis/mark/wedge.rb +1 -1
- data/lib/rubyvis/scene/svg_curve.rb +0 -1
- data/lib/rubyvis/sceneelement.rb +1 -1
- data/spec/dom_spec.rb +218 -0
- data/web/Rakefile +1 -1
- metadata +16 -25
- metadata.gz.sig +0 -0
data/lib/rubyvis/mark/dot.rb
CHANGED
@@ -79,7 +79,7 @@ module Rubyvis
|
|
79
79
|
# style is a categorical color. The default shape is "circle" with radius 4.5.
|
80
80
|
def self.defaults()
|
81
81
|
a=Rubyvis::Colors.category10
|
82
|
-
Dot.new().
|
82
|
+
Dot.new().mark_extend(Mark.defaults).shape("circle"). line_width(1.5). stroke_style(lambda {a.scale(self.parent.index)})
|
83
83
|
end
|
84
84
|
# Constructs a new dot anchor with default properties. Dots support five
|
85
85
|
# different anchors:<ul>
|
data/lib/rubyvis/mark/image.rb
CHANGED
@@ -36,7 +36,7 @@ module Rubyvis
|
|
36
36
|
|
37
37
|
# Default properties for images. By default, there is no stroke or fill style.
|
38
38
|
def self.defaults
|
39
|
-
Image.new.
|
39
|
+
Image.new.mark_extend(Bar.defaults).fill_style(nil)
|
40
40
|
end
|
41
41
|
|
42
42
|
# @TODO: NOT IMPLEMENTED YET
|
data/lib/rubyvis/mark/label.rb
CHANGED
@@ -101,7 +101,7 @@ module Rubyvis
|
|
101
101
|
end
|
102
102
|
# Default properties for labels. See the individual properties for the default values.
|
103
103
|
def self.defaults
|
104
|
-
Label.new.
|
104
|
+
Label.new.mark_extend(Mark.defaults).events('none').text(Rubyvis.identity).font("10px sans-serif" ).text_angle( 0 ).text_style( 'black' ).text_align( 'left' ).text_baseline( 'bottom' ).text_margin(3)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
data/lib/rubyvis/mark/line.rb
CHANGED
@@ -145,7 +145,7 @@ module Rubyvis
|
|
145
145
|
|
146
146
|
def self.defaults
|
147
147
|
a=Rubyvis::Colors.category10()
|
148
|
-
Line.new.
|
148
|
+
Line.new.mark_extend(Mark.defaults).line_join('miter').line_width(1.5).stroke_style( lambda { a.scale(parent.index)}).interpolate('linear').eccentricity(0).tension(0.7)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
data/lib/rubyvis/mark/panel.rb
CHANGED
data/lib/rubyvis/mark/rule.rb
CHANGED
@@ -8,7 +8,7 @@ module Rubyvis
|
|
8
8
|
@properties=Mark.properties.dup
|
9
9
|
attr_accessor_dsl :width, :height, :line_width, [:stroke_style, lambda {|d| Rubyvis.color(d)}]
|
10
10
|
def self.defaults
|
11
|
-
Rule.new.
|
11
|
+
Rule.new.mark_extend(Mark.defaults).line_width(1).stroke_style('black').antialias(false)
|
12
12
|
end
|
13
13
|
def type
|
14
14
|
'rule'
|
data/lib/rubyvis/mark/wedge.rb
CHANGED
@@ -13,7 +13,7 @@ module Rubyvis
|
|
13
13
|
|
14
14
|
def self.defaults
|
15
15
|
a=Rubyvis.Colors.category20()
|
16
|
-
Wedge.new.
|
16
|
+
Wedge.new.mark_extend(Mark.defaults).start_angle(lambda {s=self.sibling; s ? s.end_angle: -Math::PI.quo(2) } ).inner_radius( 0 ).line_width( 1.5 ).stroke_style( nil ).fill_style( lambda {a.scale(self.index)})
|
17
17
|
end
|
18
18
|
def mid_radius
|
19
19
|
(inner_radius+outer_radius) / 2.0
|
data/lib/rubyvis/sceneelement.rb
CHANGED
@@ -8,7 +8,7 @@ module Rubyvis
|
|
8
8
|
end
|
9
9
|
include Enumerable
|
10
10
|
attr_accessor :visible
|
11
|
-
attr_accessor :mark, :type, :child_index, :parent, :parent_index, :target, :defs, :data, :antialias, :line_width, :fill_style, :overflow, :width, :height, :top, :bottom, :left, :right, :title, :reverse, :stroke_style, :transform, :canvas, :_g, :events, :cursor, :children, :id, :segmented, :interpolate, :tension, :name, :text_baseline, :text_align, :text, :font, :text_angle, :text_style, :text_margin, :text_decoration, :text_shadow, :line_join, :eccentricity, :shape_size, :shape, :shape_angle, :shape_radius, :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :layers, :orient, :offset, :order,:url, :image_width, :image_height, :image
|
11
|
+
attr_accessor :mark, :type, :child_index, :parent, :parent_index, :target, :defs, :data, :antialias, :line_width, :fill_style, :overflow, :width, :height, :top, :bottom, :left, :right, :title, :reverse, :stroke_style, :transform, :canvas, :_g, :events, :cursor, :children, :id, :segmented, :interpolate, :tension, :name, :text_baseline, :text_align, :text, :font, :text_angle, :text_style, :text_margin, :text_decoration, :text_shadow, :line_join, :eccentricity, :shape_size, :shape, :shape_angle, :shape_radius, :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :layers, :orient, :offset, :order,:url, :image_width, :image_height, :image, :_id, :nodes, :round, :links, :padding_left, :padding_right, :padding_top, :padding_bottom, :mode
|
12
12
|
|
13
13
|
def []=(v,i)
|
14
14
|
if v.is_a? Numeric
|
data/spec/dom_spec.rb
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
|
2
|
+
describe Rubyvis::Dom do
|
3
|
+
it "should map correctly" do
|
4
|
+
map={
|
5
|
+
:a=>{:aa=>1,
|
6
|
+
:ab=>{:aba=>2}
|
7
|
+
},
|
8
|
+
:b=>4,
|
9
|
+
:c=>{:ca=>5}
|
10
|
+
}
|
11
|
+
dom_map=Rubyvis::Dom.new(map)
|
12
|
+
|
13
|
+
root=dom_map.root.sort {|a,b| a.node_name.to_s<=>b.node_name.to_s}
|
14
|
+
root.nodes.should be_instance_of Array
|
15
|
+
root.nodes.size.should eq 8
|
16
|
+
ar=root.nodes.map do |n|
|
17
|
+
[n.node_name, n.node_value]
|
18
|
+
end
|
19
|
+
ar.should eq [[nil, nil], [:a, nil], [:aa, 1], [:ab, nil], [:aba, 2], [:b, 4], [:c, nil], [:ca, 5]]
|
20
|
+
end
|
21
|
+
it "should treemap example works right" do
|
22
|
+
flare={:a=>{:aa=>1,:ab=>1,:ac=>1},:b=>{:ba=>1,:bb=>1},:c=>3}
|
23
|
+
dom_map=Rubyvis::Dom.new(flare)
|
24
|
+
nodes = dom_map.root("flare").nodes
|
25
|
+
root = nodes[0]
|
26
|
+
root.visit_after {|nn,i|
|
27
|
+
if nn.first_child
|
28
|
+
nn.size=Rubyvis.sum(nn.child_nodes, lambda {|v| v.size})
|
29
|
+
else
|
30
|
+
nn.size=nn.node_value.to_f
|
31
|
+
end
|
32
|
+
}
|
33
|
+
root.sort(lambda {|a,b|
|
34
|
+
if a.size!=b.size
|
35
|
+
a.size<=>b.size
|
36
|
+
else
|
37
|
+
a.node_name.to_s<=>b.node_name.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
})
|
41
|
+
ar=[]
|
42
|
+
root.visit_before {|n,i|
|
43
|
+
ar.push [n.node_name, n.size]
|
44
|
+
}
|
45
|
+
ar.should eq [["flare", 8.0], [:b, 2.0], [:ba, 1.0], [:bb, 1.0], [:a, 3.0], [:aa, 1.0], [:ab, 1.0], [:ac, 1.0], [:c, 3.0]]
|
46
|
+
end
|
47
|
+
describe Rubyvis::Dom::Node do
|
48
|
+
before do
|
49
|
+
@n =Rubyvis::Dom::Node.new(:a)
|
50
|
+
@n2=Rubyvis::Dom::Node.new(:b)
|
51
|
+
@n3=Rubyvis::Dom::Node.new(:c)
|
52
|
+
@n4=Rubyvis::Dom::Node.new(:d)
|
53
|
+
@n5=Rubyvis::Dom::Node.new(:e)
|
54
|
+
|
55
|
+
end
|
56
|
+
subject {@n}
|
57
|
+
it "should have node_value" do
|
58
|
+
@n.node_value.should eq :a
|
59
|
+
end
|
60
|
+
it {should respond_to :parent_node}
|
61
|
+
it {should respond_to :first_child}
|
62
|
+
it {should respond_to :last_child}
|
63
|
+
it {should respond_to :previous_sibling}
|
64
|
+
it {should respond_to :next_sibling}
|
65
|
+
it {should respond_to :node_name}
|
66
|
+
it {should respond_to :child_nodes}
|
67
|
+
it "should child_nodes be empty" do
|
68
|
+
@n.child_nodes.size==0
|
69
|
+
end
|
70
|
+
it "method append_child" do
|
71
|
+
@n.append_child(@n2).should eq @n2
|
72
|
+
@n.child_nodes.should eq [@n2]
|
73
|
+
@n2.parent_node.should eq @n
|
74
|
+
@n.first_child.should eq @n2
|
75
|
+
@n.last_child.should eq @n2
|
76
|
+
|
77
|
+
@n.append_child(@n3)
|
78
|
+
@n.child_nodes.should eq [@n2,@n3]
|
79
|
+
@n3.parent_node.should eq @n
|
80
|
+
@n.first_child.should eq @n2
|
81
|
+
@n.last_child.should eq @n3
|
82
|
+
@n2.previous_sibling.should be_nil
|
83
|
+
@n2.next_sibling.should eq @n3
|
84
|
+
@n3.previous_sibling.should eq @n2
|
85
|
+
@n3.next_sibling.should be_nil
|
86
|
+
|
87
|
+
@n.append_child(@n4)
|
88
|
+
@n.last_child.should eq @n4
|
89
|
+
@n2.next_sibling.should eq @n3
|
90
|
+
@n3.next_sibling.should eq @n4
|
91
|
+
@n4.next_sibling.should be_nil
|
92
|
+
|
93
|
+
@n4.previous_sibling.should eq @n3
|
94
|
+
@n3.previous_sibling.should eq @n2
|
95
|
+
@n2.previous_sibling.should be_nil
|
96
|
+
|
97
|
+
end
|
98
|
+
it "method remove_child" do
|
99
|
+
@n.append_child(@n2)
|
100
|
+
@n.append_child(@n3)
|
101
|
+
@n.append_child(@n4)
|
102
|
+
|
103
|
+
@n.remove_child(@n3).should eq @n3
|
104
|
+
|
105
|
+
@n3.next_sibling.should be_nil
|
106
|
+
@n3.previous_sibling.should be_nil
|
107
|
+
@n3.parent_node.should be_nil
|
108
|
+
|
109
|
+
@n2.next_sibling.should eq @n4
|
110
|
+
@n4.previous_sibling.should eq @n2
|
111
|
+
|
112
|
+
@n.remove_child(@n4)
|
113
|
+
@n2.next_sibling.should be_nil
|
114
|
+
@n.first_child.should eq @n2
|
115
|
+
@n.last_child.should eq @n2
|
116
|
+
end
|
117
|
+
|
118
|
+
it "method insert_before" do
|
119
|
+
@n.append_child(@n2)
|
120
|
+
@n.append_child(@n4)
|
121
|
+
@n.insert_before(@n3,@n4)
|
122
|
+
@n.child_nodes.size.should eq 3
|
123
|
+
|
124
|
+
@n.first_child.should eq @n2
|
125
|
+
@n.last_child.should eq @n4
|
126
|
+
@n2.next_sibling.should eq @n3
|
127
|
+
@n3.next_sibling.should eq @n4
|
128
|
+
@n4.next_sibling.should be_nil
|
129
|
+
|
130
|
+
@n2.previous_sibling.should be_nil
|
131
|
+
@n3.previous_sibling.should eq @n2
|
132
|
+
@n4.previous_sibling.should eq @n3
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
@n.child_nodes[0].should eq @n2
|
137
|
+
@n.child_nodes[1].should eq @n3
|
138
|
+
@n.child_nodes[2].should eq @n4
|
139
|
+
|
140
|
+
end
|
141
|
+
it "method replace_child" do
|
142
|
+
@n.append_child(@n2)
|
143
|
+
@n.append_child(@n3)
|
144
|
+
@n.replace_child(@n4,@n3)
|
145
|
+
|
146
|
+
@n.child_nodes.size.should eq 2
|
147
|
+
|
148
|
+
@n.child_nodes[0].should eq @n2
|
149
|
+
@n.child_nodes[1].should eq @n4
|
150
|
+
|
151
|
+
@n2.next_sibling.should eq @n4
|
152
|
+
@n4.next_sibling.should eq nil
|
153
|
+
|
154
|
+
@n2.previous_sibling.should be_nil
|
155
|
+
@n4.previous_sibling.should eq @n2
|
156
|
+
|
157
|
+
|
158
|
+
@n.first_child.should eq @n2
|
159
|
+
@n.last_child.should eq @n4
|
160
|
+
end
|
161
|
+
describe "visit methods" do
|
162
|
+
before do
|
163
|
+
@n.append_child(@n2)
|
164
|
+
@n2.append_child(@n5)
|
165
|
+
|
166
|
+
@n.append_child(@n3)
|
167
|
+
@n3.append_child(@n4)
|
168
|
+
@a=[]
|
169
|
+
end
|
170
|
+
|
171
|
+
it "method visit_before" do
|
172
|
+
@n.visit_before {|n,d|
|
173
|
+
@a.push([n.node_value,d])
|
174
|
+
}
|
175
|
+
@a.should eq [[:a, 0], [:b, 1], [:e, 2], [:c, 1], [:d, 2]]
|
176
|
+
end
|
177
|
+
|
178
|
+
it "method visit_after" do
|
179
|
+
@n.visit_after {|n,d|
|
180
|
+
@a.push([n.node_value,d])
|
181
|
+
}
|
182
|
+
@a.should eq [[:e, 2], [:b, 1], [:d, 2], [:c, 1], [:a, 0]]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
it "should sort correctly" do
|
186
|
+
@n.append_child(@n5)
|
187
|
+
@n.append_child(@n4)
|
188
|
+
@n.append_child(@n3)
|
189
|
+
@n.append_child(@n2)
|
190
|
+
|
191
|
+
@n.sort {|a,b| a.node_value.to_s<=>b.node_value.to_s}
|
192
|
+
|
193
|
+
@n.child_nodes.should eq [@n2,@n3,@n4,@n5]
|
194
|
+
|
195
|
+
@n.first_child.should eq @n2
|
196
|
+
@n.last_child.should eq @n5
|
197
|
+
|
198
|
+
@n2.next_sibling.should eq @n3
|
199
|
+
@n3.next_sibling.should eq @n4
|
200
|
+
@n4.next_sibling.should eq @n5
|
201
|
+
@n5.next_sibling.should be_nil
|
202
|
+
|
203
|
+
@n2.previous_sibling.should be_nil
|
204
|
+
@n3.previous_sibling.should eq @n2
|
205
|
+
@n4.previous_sibling.should eq @n3
|
206
|
+
@n5.previous_sibling.should eq @n4
|
207
|
+
end
|
208
|
+
it "should reverse correctly" do
|
209
|
+
@n.append_child(@n3)
|
210
|
+
@n.append_child(@n5)
|
211
|
+
@n.append_child(@n2)
|
212
|
+
@n.append_child(@n4)
|
213
|
+
@n.reverse
|
214
|
+
@n.child_nodes.should eq [@n4,@n2,@n5,@n3]
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
data/web/Rakefile
CHANGED
@@ -25,7 +25,7 @@ EXAMPLES.each do |v|
|
|
25
25
|
e=v[1]
|
26
26
|
file "examples/#{e}.html"=>["examples.haml", "examples/#{e}.svg", :build_site, v[0]]
|
27
27
|
file "examples/#{e}.svg"=>[v[0]] do |t|
|
28
|
-
system "
|
28
|
+
system "ruby #{v[0]} > #{t.name}"
|
29
29
|
end
|
30
30
|
file "examples/#{e}.png"=>["examples/#{e}.svg"] do |t|
|
31
31
|
system "rsvg -w 200 -h 200 -f png examples/#{e}.svg #{t.name}"
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Claudio Bustos
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
rpP0jjs0
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2010-11-
|
39
|
+
date: 2010-11-17 00:00:00 -03:00
|
40
40
|
default_executable:
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
@@ -123,9 +123,9 @@ dependencies:
|
|
123
123
|
hash: 19
|
124
124
|
segments:
|
125
125
|
- 2
|
126
|
-
-
|
127
|
-
-
|
128
|
-
version: 2.
|
126
|
+
- 7
|
127
|
+
- 0
|
128
|
+
version: 2.7.0
|
129
129
|
type: :development
|
130
130
|
version_requirements: *id006
|
131
131
|
description: Ruby port of Protovis[http://vis.stanford.edu/protovis/], a great visualization toolkit
|
@@ -172,16 +172,22 @@ files:
|
|
172
172
|
- examples/second.rb
|
173
173
|
- examples/stacked_charts.rb
|
174
174
|
- examples/third.rb
|
175
|
+
- examples/treemap/treemap.rb
|
176
|
+
- examples/treemap/treemap_data.rb
|
175
177
|
- lib/rubyvis.rb
|
176
178
|
- lib/rubyvis/color/color.rb
|
177
179
|
- lib/rubyvis/color/colors.rb
|
180
|
+
- lib/rubyvis/dom.rb
|
178
181
|
- lib/rubyvis/format.rb
|
179
182
|
- lib/rubyvis/format/date.rb
|
180
183
|
- lib/rubyvis/format/number.rb
|
181
184
|
- lib/rubyvis/internals.rb
|
182
185
|
- lib/rubyvis/javascript_behaviour.rb
|
183
186
|
- lib/rubyvis/layout.rb
|
187
|
+
- lib/rubyvis/layout/hierarchy.rb
|
188
|
+
- lib/rubyvis/layout/network.rb
|
184
189
|
- lib/rubyvis/layout/stack.rb
|
190
|
+
- lib/rubyvis/layout/treemap.rb
|
185
191
|
- lib/rubyvis/mark.rb
|
186
192
|
- lib/rubyvis/mark/anchor.rb
|
187
193
|
- lib/rubyvis/mark/area.rb
|
@@ -217,6 +223,7 @@ files:
|
|
217
223
|
- spec/anchor_spec.rb
|
218
224
|
- spec/area_spec.rb
|
219
225
|
- spec/bar_spec.rb
|
226
|
+
- spec/dom_spec.rb
|
220
227
|
- spec/internal_spec.rb
|
221
228
|
- spec/javascript_behaviour_spec.rb
|
222
229
|
- spec/label_spec.rb
|
@@ -367,21 +374,5 @@ rubygems_version: 1.3.7
|
|
367
374
|
signing_key:
|
368
375
|
specification_version: 3
|
369
376
|
summary: Ruby port of Protovis[http://vis.stanford.edu/protovis/], a great visualization toolkit
|
370
|
-
test_files:
|
371
|
-
|
372
|
-
- spec/nest_spec.rb
|
373
|
-
- spec/scale_ordinal_spec.rb
|
374
|
-
- spec/internal_spec.rb
|
375
|
-
- spec/panel_spec.rb
|
376
|
-
- spec/scale_log_spec.rb
|
377
|
-
- spec/scale_linear_datetime_spec.rb
|
378
|
-
- spec/anchor_spec.rb
|
379
|
-
- spec/readme_spec.rb
|
380
|
-
- spec/scale_spec.rb
|
381
|
-
- spec/scale_linear_spec.rb
|
382
|
-
- spec/ruby_api_spec.rb
|
383
|
-
- spec/label_spec.rb
|
384
|
-
- spec/mark_spec.rb
|
385
|
-
- spec/area_spec.rb
|
386
|
-
- spec/javascript_behaviour_spec.rb
|
387
|
-
- spec/line_spec.rb
|
377
|
+
test_files: []
|
378
|
+
|
metadata.gz.sig
CHANGED
Binary file
|