rubyvis 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +1 -1
- data/History.txt +6 -1
- data/examples/antibiotics/antibiotics.rb +2 -2
- data/examples/bar_column_chart.rb +1 -1
- data/examples/scatterplot.rb +1 -1
- data/lib/rubyvis.rb +1 -1
- data/lib/rubyvis/layout.rb +1 -1
- data/lib/rubyvis/mark.rb +47 -21
- data/lib/rubyvis/mark/anchor.rb +1 -1
- data/lib/rubyvis/mark/bar.rb +1 -0
- data/lib/rubyvis/mark/label.rb +1 -1
- data/lib/rubyvis/mark/panel.rb +5 -0
- data/lib/rubyvis/scene/svg_scene.rb +14 -2
- data/spec/anchor_spec.rb +126 -0
- metadata +4 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
O�Ly���N^
|
data/History.txt
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
=== 0.1.
|
1
|
+
=== 0.1.5 / 2010-10-22
|
2
|
+
|
3
|
+
* Bug fix: styles considered properly, so font attribute works right now.
|
4
|
+
* Bug fix: anchors have proper parent assignation.
|
5
|
+
|
6
|
+
=== 0.1.4 / 2010-10-20
|
2
7
|
|
3
8
|
* Bug fix: Order now works on Nest
|
4
9
|
* Added log scale spec. domain, range, scale, invert and ticks works like javascript version
|
@@ -29,9 +29,9 @@ cell = vis.add(pv.Panel)
|
|
29
29
|
|
30
30
|
#/* Label. */
|
31
31
|
cell.anchor("center").add(pv.Label)
|
32
|
-
|
32
|
+
.visible(lambda {|d,y, x| return x == y})
|
33
33
|
.font("bold 14px sans-serif")
|
34
|
-
.text(lambda {|d, y, x|
|
34
|
+
.text(lambda {|d, y, x| x});
|
35
35
|
|
36
36
|
#/* Dot plot and frame. */
|
37
37
|
plot = cell.add(pv.Panel)
|
data/examples/scatterplot.rb
CHANGED
data/lib/rubyvis.rb
CHANGED
data/lib/rubyvis/layout.rb
CHANGED
data/lib/rubyvis/mark.rb
CHANGED
@@ -59,7 +59,24 @@ module Rubyvis
|
|
59
59
|
}
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
|
+
def delete_index
|
64
|
+
@index=nil
|
65
|
+
@index_defined=false
|
66
|
+
end
|
67
|
+
def index
|
68
|
+
@index
|
69
|
+
end
|
70
|
+
|
71
|
+
def index_defined?
|
72
|
+
@index_defined
|
73
|
+
end
|
74
|
+
def index=(v)
|
75
|
+
@index_defined=true
|
76
|
+
@index=v
|
77
|
+
v
|
78
|
+
end
|
79
|
+
|
63
80
|
|
64
81
|
def property_value(name,v)
|
65
82
|
prop=Property.new({:name=>name, :id=>Rubyvis.id, :value=>v})
|
@@ -74,15 +91,15 @@ module Rubyvis
|
|
74
91
|
def instance(default_index=nil)
|
75
92
|
scene=self.scene
|
76
93
|
scene||=self.parent.instance(-1).children[self.child_index]
|
77
|
-
|
78
|
-
index =
|
79
|
-
#
|
80
|
-
scene[index<0 ? scene.
|
94
|
+
|
95
|
+
index = index_defined? ? self.index : default_index
|
96
|
+
# "defined?: #{index_defined?} : type: #{type}, self.index: #{self.index}, index:#{index}"
|
97
|
+
scene[index<0 ? scene.size-1: index]
|
81
98
|
end
|
82
99
|
|
83
100
|
|
84
101
|
|
85
|
-
attr_accessor :parent, :root, :
|
102
|
+
attr_accessor :parent, :root, :child_index, :scene, :proto, :target, :scale
|
86
103
|
attr_reader :_properties
|
87
104
|
|
88
105
|
|
@@ -91,6 +108,7 @@ module Rubyvis
|
|
91
108
|
@scene=nil
|
92
109
|
@stack=[]
|
93
110
|
@index=nil
|
111
|
+
|
94
112
|
def self.properties
|
95
113
|
@properties
|
96
114
|
end
|
@@ -127,6 +145,7 @@ module Rubyvis
|
|
127
145
|
@defs={}
|
128
146
|
@child_index=-1
|
129
147
|
@index=-1
|
148
|
+
@index_defined = true
|
130
149
|
@scale=1
|
131
150
|
@scene=nil
|
132
151
|
|
@@ -144,18 +163,18 @@ module Rubyvis
|
|
144
163
|
end
|
145
164
|
|
146
165
|
def instances(source)
|
147
|
-
|
148
166
|
mark = self
|
149
|
-
|
167
|
+
_index = []
|
150
168
|
scene=nil
|
169
|
+
|
151
170
|
while (!(scene = mark.scene)) do
|
152
171
|
source = source.parent;
|
153
|
-
|
172
|
+
_index.push(OpenStruct.new({:index=>source.index, :child_index=>mark.child_index}))
|
154
173
|
mark = mark.parent
|
155
174
|
end
|
156
175
|
|
157
|
-
while (
|
158
|
-
i =
|
176
|
+
while (_index.size>0) do
|
177
|
+
i = _index.pop()
|
159
178
|
scene = scene[i.index].children[i.child_index]
|
160
179
|
end
|
161
180
|
#
|
@@ -163,8 +182,8 @@ module Rubyvis
|
|
163
182
|
# to a panel anchor, only generate one instance per panel. Also, set
|
164
183
|
# the margins to zero, since they are offset by the enclosing panel.
|
165
184
|
# /
|
166
|
-
|
167
|
-
|
185
|
+
|
186
|
+
if (index_defined?)
|
168
187
|
s = scene[self.index].dup
|
169
188
|
s.right = s.top = s.left = s.bottom = 0;
|
170
189
|
return [s];
|
@@ -186,9 +205,12 @@ module Rubyvis
|
|
186
205
|
mark_anchor(name)
|
187
206
|
end
|
188
207
|
def mark_anchor(name="center")
|
189
|
-
|
190
208
|
anchor=Rubyvis::Anchor.new(self).name(name).data(lambda {
|
191
|
-
|
209
|
+
pp self.scene.target if $DEBUG
|
210
|
+
a=self.scene.target.map {|s| puts "s:#{s.data}" if $DEBUG; s.data}
|
211
|
+
p a if $DEBUG
|
212
|
+
a
|
213
|
+
}).visible(lambda {
|
192
214
|
self.scene.target[self.index].visible
|
193
215
|
}).id(lambda {self.scene.target[self.index].id}).left(lambda {
|
194
216
|
s = self.scene.target[self.index]
|
@@ -333,14 +355,14 @@ module Rubyvis
|
|
333
355
|
mark.scale=scale
|
334
356
|
if (depth < @indexes.size)
|
335
357
|
@stack.unshift(nil)
|
336
|
-
if (mark.
|
358
|
+
if (mark.index_defined?)
|
337
359
|
render_instance(mark, depth, scale);
|
338
360
|
else
|
339
361
|
mark.scene.size.times {|i|
|
340
362
|
mark.index = i;
|
341
363
|
render_instance(mark, depth, scale);
|
342
364
|
}
|
343
|
-
mark.
|
365
|
+
mark.delete_index
|
344
366
|
end
|
345
367
|
stack.shift
|
346
368
|
else
|
@@ -350,6 +372,8 @@ module Rubyvis
|
|
350
372
|
end
|
351
373
|
mark.scale=nil
|
352
374
|
end
|
375
|
+
|
376
|
+
|
353
377
|
def render_instance(mark,depth,scale)
|
354
378
|
s=mark.scene[mark.index]
|
355
379
|
if s.visible
|
@@ -471,7 +495,7 @@ module Rubyvis
|
|
471
495
|
mark=that
|
472
496
|
begin
|
473
497
|
Mark.stack.pop
|
474
|
-
if(mark.parent)
|
498
|
+
if(mark.parent)
|
475
499
|
mark.scene=nil
|
476
500
|
mark.scale=nil
|
477
501
|
end
|
@@ -524,7 +548,8 @@ module Rubyvis
|
|
524
548
|
stack.unshift(nil)
|
525
549
|
scene.size=data.size
|
526
550
|
data.each_with_index {|d, i|
|
527
|
-
Mark.index=
|
551
|
+
Mark.index=i
|
552
|
+
self.index=i
|
528
553
|
s=scene[i]
|
529
554
|
if !s
|
530
555
|
scene[i]=s=SceneElement.new
|
@@ -534,10 +559,11 @@ module Rubyvis
|
|
534
559
|
build_instance(s)
|
535
560
|
}
|
536
561
|
Mark.index=-1
|
537
|
-
|
562
|
+
delete_index
|
538
563
|
stack.shift()
|
539
|
-
|
564
|
+
self
|
540
565
|
end
|
566
|
+
|
541
567
|
def build_instance(s)
|
542
568
|
mark_build_instance(s)
|
543
569
|
end
|
data/lib/rubyvis/mark/anchor.rb
CHANGED
data/lib/rubyvis/mark/bar.rb
CHANGED
@@ -9,6 +9,7 @@ module Rubyvis
|
|
9
9
|
|
10
10
|
@properties=Mark.properties.dup
|
11
11
|
attr_accessor_dsl :width, :height, :line_width, [:stroke_style, lambda {|d| pv.color(d)}], [:fill_style, lambda {|d| pv.color(d)}]
|
12
|
+
|
12
13
|
def self.defaults
|
13
14
|
a=Rubyvis.Colors.category20()
|
14
15
|
Bar.new.extend(Mark.defaults).line_width(1.5).fill_style( lambda {
|
data/lib/rubyvis/mark/label.rb
CHANGED
@@ -10,7 +10,7 @@ module Rubyvis
|
|
10
10
|
'label'
|
11
11
|
end
|
12
12
|
def self.defaults
|
13
|
-
Label.new.extend(Mark.defaults).events('none').text(
|
13
|
+
Label.new.extend(Mark.defaults).events('none').text(pv.identity).font("10px sans-serif" ).text_angle( 0 ).text_style( 'black' ).text_align( 'left' ).text_baseline( 'bottom' ).text_margin(3)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/rubyvis/mark/panel.rb
CHANGED
@@ -112,15 +112,27 @@ module Rubyvis
|
|
112
112
|
e.attributes[name]=value
|
113
113
|
end
|
114
114
|
}
|
115
|
+
|
115
116
|
if(style)
|
117
|
+
base_style=e.attributes['style']
|
118
|
+
base_style||=""
|
119
|
+
array_styles={}
|
120
|
+
base_style.split(";").each {|v|
|
121
|
+
v=~/\s*(.+)\s*:\s*(.+)/
|
122
|
+
array_styles[$1]=$2
|
123
|
+
}
|
116
124
|
style.each {|name,value|
|
117
125
|
value=nil if value==self.implicit[:css][name]
|
118
126
|
if (value.nil?)
|
119
|
-
|
127
|
+
array_styles.delete(name)
|
120
128
|
else
|
121
|
-
|
129
|
+
|
130
|
+
array_styles[name]=value
|
122
131
|
end
|
123
132
|
}
|
133
|
+
if array_styles.size>0
|
134
|
+
e.attributes["style"]=array_styles.map {|k,v| "#{k}:#{v}"}.join(";")
|
135
|
+
end
|
124
136
|
end
|
125
137
|
e
|
126
138
|
end
|
data/spec/anchor_spec.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.dirname(__FILE__)+"/spec_helper.rb"
|
2
|
+
describe Rubyvis::Anchor do
|
3
|
+
describe "inner anchor data should work fine" do
|
4
|
+
before do
|
5
|
+
w=200
|
6
|
+
h=200
|
7
|
+
data_p1=[]
|
8
|
+
data_p2=[]
|
9
|
+
data_l=[]
|
10
|
+
@expected_l=[]
|
11
|
+
@expected_p2=[]
|
12
|
+
vis = pv.Panel.new().width(w).height(h)
|
13
|
+
cell=vis.add(pv.Panel).
|
14
|
+
data([1,2]).top(lambda {|*args| data_p1.push(args); return 100}).
|
15
|
+
add(pv.Panel). data(['a','b']).top(lambda {|*args| data_p2.push(args); return 100;})
|
16
|
+
|
17
|
+
cell.anchor('center').add(pv.Bar).top(lambda {|*args| data_l.push args; return 1})
|
18
|
+
|
19
|
+
[1,2].each {|a| %w{a b}.each {|b|
|
20
|
+
@expected_l.push([b,b,a,nil])
|
21
|
+
@expected_p2.push([b,a,nil])
|
22
|
+
}}
|
23
|
+
@expected_p1=[[1,nil],[2,nil]]
|
24
|
+
@data_p1=data_p1
|
25
|
+
@data_p2=data_p2
|
26
|
+
@data_l=data_l
|
27
|
+
vis.render
|
28
|
+
|
29
|
+
end
|
30
|
+
if(true)
|
31
|
+
it "first loop correct" do
|
32
|
+
@data_p1.should==@expected_p1
|
33
|
+
end
|
34
|
+
it "second loop correct" do
|
35
|
+
@data_p2.should==@expected_p2
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "label loop correct" do
|
40
|
+
@data_l.should==@expected_l
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "antibiotics example should render correct data" do
|
45
|
+
|
46
|
+
a1=['a','b','c']
|
47
|
+
a2=[1,2,3]
|
48
|
+
antibiotics=["penicillin", "streptomycin", "neomycin"]
|
49
|
+
adatas=[]
|
50
|
+
s = 180
|
51
|
+
_p = 20
|
52
|
+
vis = pv.Panel.new()
|
53
|
+
.height(s * antibiotics.size + _p * (antibiotics.size - 1))
|
54
|
+
.width(s * antibiotics.size + _p * (antibiotics.size - 1))
|
55
|
+
.top(14.5)
|
56
|
+
.left(14.5)
|
57
|
+
.bottom(44)
|
58
|
+
.right(14)
|
59
|
+
|
60
|
+
cell = vis.add(pv.Panel)
|
61
|
+
.data(a1)
|
62
|
+
.width(s)
|
63
|
+
.left(lambda {(s + _p) * self.index})
|
64
|
+
.add(pv.Panel)
|
65
|
+
.data(a2)
|
66
|
+
.height(s)
|
67
|
+
.top(lambda {(s + _p) * self.index});
|
68
|
+
|
69
|
+
|
70
|
+
cell.anchor("center").add(pv.Label).text(lambda {|*args| adatas.push args})
|
71
|
+
|
72
|
+
expected=[]
|
73
|
+
a1.each {|a| a2.each {|b| expected.push([b,b,a,nil])}}
|
74
|
+
vis.render
|
75
|
+
adatas.should==expected
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
context "Panel-Panel-label assigment" do
|
80
|
+
before do
|
81
|
+
@h=200
|
82
|
+
@w=200
|
83
|
+
@values=["a","b","c"]
|
84
|
+
@vis = Rubyvis.Panel.new.width(@w).height(@h). add(pv.Panel).data(@values). add(pv.Panel).data(@values)
|
85
|
+
@anchor=@vis.anchor('center')
|
86
|
+
@label=@vis.add(pv.Label)
|
87
|
+
end
|
88
|
+
it "should have correct data" do
|
89
|
+
datas=[]
|
90
|
+
@label.text(lambda {|*args| datas.push args})
|
91
|
+
@vis.render
|
92
|
+
expected=[]
|
93
|
+
@values.each {|a| @values.each {|b| expected.push([b,b,a,nil])}}
|
94
|
+
datas.should==expected
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context "Panel-bar assigment" do
|
98
|
+
before do
|
99
|
+
@h=200
|
100
|
+
@w=200
|
101
|
+
@vis = Rubyvis.Panel.new.width(@w).height(@h)
|
102
|
+
@bar = @vis.add(Rubyvis::Bar).data([1,2,3])
|
103
|
+
@anchor=@bar.anchor('center')
|
104
|
+
@label=@anchor.add(Rubyvis::Label)
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should have correct data for direct asigment" do
|
109
|
+
datas=[]
|
110
|
+
expected=[[1,nil],[2,nil],[3,nil]]
|
111
|
+
@label.text(lambda {|*args| datas.push args})
|
112
|
+
@vis.render
|
113
|
+
datas.should==expected
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should have correct data for two levels of data" do
|
117
|
+
datas=[]
|
118
|
+
@vis.data(%w{a b c})
|
119
|
+
expected=[]
|
120
|
+
%w{a b c}.each {|a| [1,2,3].each {|b| expected.push([b,a])}}
|
121
|
+
@label.text(lambda {|*args| datas.push args})
|
122
|
+
@vis.render
|
123
|
+
datas.should==expected
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Claudio Bustos
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
rpP0jjs0
|
36
36
|
-----END CERTIFICATE-----
|
37
37
|
|
38
|
-
date: 2010-10-
|
38
|
+
date: 2010-10-22 00:00:00 -03:00
|
39
39
|
default_executable:
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -289,6 +289,7 @@ test_files:
|
|
289
289
|
- spec/panel_spec.rb
|
290
290
|
- spec/scale_log_spec.rb
|
291
291
|
- spec/scale_linear_datetime_spec.rb
|
292
|
+
- spec/anchor_spec.rb
|
292
293
|
- spec/scale_spec.rb
|
293
294
|
- spec/scale_linear_spec.rb
|
294
295
|
- spec/label_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|