rubyvis 0.2.0 → 0.2.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.
- data.tar.gz.sig +2 -1
- data/History.txt +14 -0
- data/Manifest.txt +5 -2
- data/README.txt +8 -2
- data/examples/antibiotics/{antibiotics.rb → antibiotics_scatter.rb} +1 -0
- data/examples/antibiotics/antibiotics_wedge.rb +121 -0
- data/examples/area.rb +42 -35
- data/examples/area_interpolation.rb +3 -3
- data/examples/barley/barley.rb +6 -2
- data/examples/cars/cars.rb +90 -0
- data/examples/cars/cars_data.rb +409 -0
- data/examples/crimea/crimea_grouped_bar.rb +2 -0
- data/examples/crimea/crimea_line.rb +3 -0
- data/examples/first_protovis_api.rb +2 -2
- data/examples/first_rbp_api.rb +2 -2
- data/lib/rubyvis.rb +1 -2
- data/lib/rubyvis/internals.rb +30 -1
- data/lib/rubyvis/javascript_behaviour.rb +8 -2
- data/lib/rubyvis/layout.rb +7 -1
- data/lib/rubyvis/layout/stack.rb +3 -3
- data/lib/rubyvis/mark.rb +173 -84
- data/lib/rubyvis/mark/area.rb +2 -3
- data/lib/rubyvis/mark/image.rb +1 -1
- data/lib/rubyvis/mark/line.rb +1 -1
- data/lib/rubyvis/mark/shorcut_methods.rb +93 -5
- data/lib/rubyvis/mark/wedge.rb +15 -10
- data/lib/rubyvis/scale/ordinal.rb +19 -0
- data/lib/rubyvis/scale/quantitative.rb +1 -0
- data/lib/rubyvis/scene/svg_line.rb +2 -2
- data/lib/rubyvis/scene/svg_scene.rb +1 -1
- data/spec/anchor_spec.rb +4 -4
- data/spec/internal_spec.rb +5 -0
- data/spec/line_spec.rb +2 -2
- data/spec/readme_spec.rb +38 -0
- data/spec/spec.opts +1 -1
- data/web/Rakefile +6 -5
- data/web/build_site.rb +3 -2
- metadata +9 -5
- metadata.gz.sig +0 -0
- data/examples/image.svg +0 -1
data/lib/rubyvis/mark/area.rb
CHANGED
data/lib/rubyvis/mark/image.rb
CHANGED
@@ -60,7 +60,7 @@ module Rubyvis
|
|
60
60
|
# and <tt>a</tt> attributes. A {@link pv.Color} or string can also be returned,
|
61
61
|
# though this typically results in slower performance.
|
62
62
|
|
63
|
-
def
|
63
|
+
def dynamic_image(f)
|
64
64
|
f,dummy=arguments
|
65
65
|
@_image = lambda {|*args|
|
66
66
|
c=f.js_apply(self,args)
|
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.extend(Mark.defaults).line_join('miter').line_width(1.5).stroke_style( lambda {
|
148
|
+
Line.new.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
|
@@ -20,39 +20,127 @@ class Rubyvis::Mark
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
##
|
23
|
-
# :method: area(opts
|
23
|
+
# :method: area(opts, &block)
|
24
24
|
#
|
25
|
+
# Adds an Area mark to current mark.
|
26
|
+
# If a block is provided, the context will be defined differently if
|
27
|
+
# parameter is provided
|
28
|
+
# * Without parameter: block executed inside context of new mark
|
29
|
+
# * With paramenter: block executed inside context of current mark.
|
30
|
+
# Paramenter references new mark
|
31
|
+
#
|
32
|
+
# See Mark for examples of use
|
33
|
+
|
25
34
|
mark_method :area, Rubyvis::Area
|
26
35
|
##
|
27
36
|
# :method: bar(opts,&block)
|
28
37
|
#
|
38
|
+
# Adds a Bar mark to current mark.
|
39
|
+
# If a block is provided, the context will be defined differently if
|
40
|
+
# parameter is provided
|
41
|
+
# * Without parameter: block executed inside context of new mark
|
42
|
+
# * With paramenter: block executed inside context of current mark.
|
43
|
+
# Paramenter references new mark
|
44
|
+
#
|
45
|
+
# See Mark for examples of use
|
46
|
+
|
29
47
|
mark_method :bar, Rubyvis::Bar
|
30
48
|
##
|
31
49
|
# :method: dot(opts,&block)
|
32
50
|
#
|
51
|
+
# Adds a Dot mark to current mark.
|
52
|
+
# If a block is provided, the context will be defined differently if
|
53
|
+
# parameter is provided
|
54
|
+
# * Without parameter: block executed inside context of new mark
|
55
|
+
# * With paramenter: block executed inside context of current mark.
|
56
|
+
# Paramenter references new mark
|
57
|
+
#
|
58
|
+
# See Mark for examples of use
|
59
|
+
|
33
60
|
mark_method :dot, Rubyvis::Dot
|
34
61
|
##
|
35
|
-
# :method:
|
62
|
+
# :method: image(opts,&block)
|
63
|
+
#
|
64
|
+
# Adds an Image mark to current mark.
|
65
|
+
# If a block is provided, the context will be defined differently if
|
66
|
+
# parameter is provided
|
67
|
+
# * Without parameter: block executed inside context of new mark
|
68
|
+
# * With paramenter: block executed inside context of current mark.
|
69
|
+
# Paramenter references new mark
|
70
|
+
#
|
71
|
+
# See Mark for examples of use
|
36
72
|
#
|
37
|
-
mark_method :
|
73
|
+
mark_method :image, Rubyvis::Image
|
74
|
+
|
38
75
|
##
|
39
76
|
# :method: label(opts,&block)
|
40
77
|
#
|
78
|
+
# Adds a Label mark to current mark.
|
79
|
+
#
|
80
|
+
# If a block is provided, the context will be defined differently if
|
81
|
+
# parameter is provided
|
82
|
+
# * Without parameter: block executed inside context of new mark
|
83
|
+
# * With paramenter: block executed inside context of current mark.
|
84
|
+
# Paramenter references new mark
|
85
|
+
#
|
86
|
+
# See Mark for examples of use
|
87
|
+
|
41
88
|
mark_method :label, Rubyvis::Label
|
42
89
|
##
|
43
90
|
# :method: line(opts,&block)
|
44
91
|
#
|
92
|
+
# Adds a Line mark to current mark.
|
93
|
+
#
|
94
|
+
# If a block is provided, the context will be defined differently if
|
95
|
+
# parameter is provided
|
96
|
+
# * Without parameter: block executed inside context of new mark
|
97
|
+
# * With paramenter: block executed inside context of current mark.
|
98
|
+
# Paramenter references new mark
|
99
|
+
#
|
100
|
+
# See Mark for examples of use
|
101
|
+
#
|
45
102
|
mark_method :line, Rubyvis::Line
|
46
103
|
##
|
47
104
|
# :method: panel(opts,&block)
|
48
105
|
#
|
106
|
+
# Adds a Panel mark to current mark.
|
107
|
+
#
|
108
|
+
# If a block is provided, the context will be defined differently if
|
109
|
+
# parameter is provided
|
110
|
+
# * Without parameter: block executed inside context of new mark
|
111
|
+
# * With paramenter: block executed inside context of current mark.
|
112
|
+
# Paramenter references new mark
|
113
|
+
#
|
114
|
+
# See Mark for examples of use
|
115
|
+
#
|
49
116
|
mark_method :panel, Rubyvis::Panel
|
50
|
-
##
|
117
|
+
##
|
51
118
|
# :method: rule(opts,&block)
|
119
|
+
#
|
120
|
+
# Adds a Rule mark to current mark.
|
121
|
+
#
|
122
|
+
# If a block is provided, the context will be defined differently if
|
123
|
+
# parameter is provided
|
124
|
+
# * Without parameter: block executed inside context of new mark
|
125
|
+
# * With paramenter: block executed inside context of current mark.
|
126
|
+
# Paramenter references new mark
|
127
|
+
#
|
128
|
+
# See Mark for examples of use
|
52
129
|
#
|
53
130
|
mark_method :rule, Rubyvis::Rule
|
54
131
|
##
|
55
|
-
# :method: wedge(opts,&block)
|
132
|
+
# :method: wedge(opts,&block)
|
133
|
+
#
|
134
|
+
# Adds a Wedge mark to current mark.
|
135
|
+
#
|
136
|
+
# If a block is provided, the context will be defined differently if
|
137
|
+
# parameter is provided
|
138
|
+
# * Without parameter: block executed inside context of new mark
|
139
|
+
# * With paramenter: block executed inside context of current mark.
|
140
|
+
# Paramenter references new mark
|
141
|
+
#
|
142
|
+
# See Mark for examples of use
|
143
|
+
|
56
144
|
#
|
57
145
|
mark_method :wedge, Rubyvis::Rule
|
58
146
|
end
|
data/lib/rubyvis/mark/wedge.rb
CHANGED
@@ -8,7 +8,9 @@ module Rubyvis
|
|
8
8
|
"wedge"
|
9
9
|
end
|
10
10
|
@properties=Mark.properties.dup
|
11
|
+
|
11
12
|
attr_accessor_dsl :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :line_width, [:stroke_style, lambda {|d| Rubyvis.color(d)}], [:fill_style, lambda {|d| Rubyvis.color(d)}]
|
13
|
+
|
12
14
|
def self.defaults
|
13
15
|
a=Rubyvis.Colors.category20()
|
14
16
|
Wedge.new.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)})
|
@@ -21,7 +23,8 @@ module Rubyvis
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def anchor(name)
|
24
|
-
|
26
|
+
that=self
|
27
|
+
partial=lambda {|s| s.inner_radius!=0 ? true : s.angle < 2*Math::PI}
|
25
28
|
mid_radius=lambda {|s| (s.inner_radius+s.outer_radius) / 2.0}
|
26
29
|
mid_angle=lambda {|s| (s.start_angle+s.end_angle) / 2.0 }
|
27
30
|
|
@@ -66,9 +69,9 @@ module Rubyvis
|
|
66
69
|
if (partial.call(s))
|
67
70
|
case (self.name())
|
68
71
|
when 'outer'
|
69
|
-
return
|
72
|
+
return that.upright(mid_angle.call(s)) ? 'right':'left'
|
70
73
|
when 'inner'
|
71
|
-
return
|
74
|
+
return that.upright(mid_angle.call(s)) ? 'left':'right'
|
72
75
|
|
73
76
|
end
|
74
77
|
end
|
@@ -78,9 +81,9 @@ module Rubyvis
|
|
78
81
|
if (partial.call(s))
|
79
82
|
case (self.name())
|
80
83
|
when 'start'
|
81
|
-
return
|
84
|
+
return that.upright(s.start_angle) ? 'top':'bottom'
|
82
85
|
when 'end'
|
83
|
-
return
|
86
|
+
return that.upright(s.end_angle) ? 'bottom':'top'
|
84
87
|
|
85
88
|
end
|
86
89
|
end
|
@@ -102,24 +105,26 @@ module Rubyvis
|
|
102
105
|
a=s.end_angle
|
103
106
|
end
|
104
107
|
end
|
105
|
-
|
108
|
+
that.upright(a) ? a: (a+Math::PI)
|
106
109
|
})
|
107
110
|
|
108
111
|
end
|
109
112
|
|
110
113
|
|
111
|
-
def
|
114
|
+
def upright(angle)
|
112
115
|
angle=angle % (2*Math::PI)
|
113
116
|
angle=(angle<0) ? (2*Math::PI+angle) : angle
|
114
117
|
(angle < Math::PI/2.0) or (angle>=3*Math::PI / 2.0)
|
115
118
|
|
116
119
|
end
|
117
120
|
def build_implied(s)
|
118
|
-
|
119
|
-
|
121
|
+
|
122
|
+
if s.angle.nil?
|
123
|
+
s.angle = s.end_angle - s.start_angle
|
120
124
|
elsif s.end_angle.nil?
|
121
|
-
s.end_angle=s.start_angle+s.angle
|
125
|
+
s.end_angle = s.start_angle + s.angle
|
122
126
|
end
|
127
|
+
|
123
128
|
mark_build_implied(s)
|
124
129
|
end
|
125
130
|
end
|
@@ -177,6 +177,25 @@ module Rubyvis
|
|
177
177
|
@r=Rubyvis.range(min+step.quo(2),max,step)
|
178
178
|
self
|
179
179
|
end
|
180
|
+
|
181
|
+
# Sets the range from the given continuous interval. The interval
|
182
|
+
# [<i>min</i>, <i>max</i>] is subdivided into <i>n</i> equispaced points,
|
183
|
+
# where <i>n</i> is the number of (unique) values in the domain. The first
|
184
|
+
# and last point are exactly on the edge of the range.
|
185
|
+
#
|
186
|
+
# <p>This method must be called <i>after</i> the domain is set.
|
187
|
+
#
|
188
|
+
# * @param {number} min minimum value of the output range.
|
189
|
+
# * @param {number} max maximum value of the output range.
|
190
|
+
# * @returns {pv.Scale.ordinal} <tt>this</tt>.
|
191
|
+
# * @see Ordinal.split
|
192
|
+
|
193
|
+
def split_flush(min,max)
|
194
|
+
n = self.domain().size
|
195
|
+
step = (max - min) / (n - 1).to_f
|
196
|
+
@r = (n == 1) ? [(min + max) / 2.0] : Rubyvis.range(min, max + step/2.0, step)
|
197
|
+
self
|
198
|
+
end
|
180
199
|
def by(f)
|
181
200
|
that=self
|
182
201
|
lambda {|*args|
|
@@ -105,9 +105,9 @@ module Rubyvis
|
|
105
105
|
return e
|
106
106
|
end
|
107
107
|
|
108
|
-
|
108
|
+
# Returns the path segment for the specified points. */
|
109
109
|
|
110
|
-
def self.path_segment(s1, s2)
|
110
|
+
def self.path_segment(s1, s2)
|
111
111
|
l = 1; # sweep-flag
|
112
112
|
l = 0 if s1.interpolate=='polar-reverse'
|
113
113
|
|
data/spec/anchor_spec.rb
CHANGED
@@ -11,10 +11,10 @@ describe Rubyvis::Anchor do
|
|
11
11
|
@expected_p2=[]
|
12
12
|
vis = pv.Panel.new().width(w).height(h)
|
13
13
|
cell=vis.add(pv.Panel).
|
14
|
-
data([1,2]).top(lambda {|*args| data_p1.push(args);
|
15
|
-
add(pv.Panel). data(['a','b']).top(lambda {|*args| data_p2.push(args);
|
14
|
+
data([1,2]).top(lambda {|*args| data_p1.push(args); 100}).
|
15
|
+
add(pv.Panel). data(['a','b']).top(lambda {|*args| data_p2.push(args); 100;})
|
16
16
|
|
17
|
-
cell.anchor('center').add(pv.Bar).top(lambda {|*args| data_l.push args;
|
17
|
+
cell.anchor('center').add(pv.Bar).top(lambda {|*args| data_l.push args; 1})
|
18
18
|
|
19
19
|
[1,2].each {|a| %w{a b}.each {|b|
|
20
20
|
@expected_l.push([b,b,a,nil])
|
@@ -123,4 +123,4 @@ describe Rubyvis::Anchor do
|
|
123
123
|
datas.should==expected
|
124
124
|
end
|
125
125
|
end
|
126
|
-
end
|
126
|
+
end
|
data/spec/internal_spec.rb
CHANGED
@@ -141,6 +141,11 @@ describe "Rubyvis module methods" do
|
|
141
141
|
it "method log_ceil" do
|
142
142
|
Rubyvis.log_ceil(-5,4).should be_close(-4, 0.001)
|
143
143
|
end
|
144
|
+
it "method dict" do
|
145
|
+
Rubyvis.dict(["one", "three", "seventeen"], lambda {|s| s.size}).should=={"one"=> 3, "three"=> 5, "seventeen"=> 9}
|
146
|
+
Rubyvis.dict(["one", "three", nil, "seventeen"], lambda {|s| s.size}).should=={"one"=> 3, "three"=> 5, "seventeen"=> 9}
|
147
|
+
|
148
|
+
end
|
144
149
|
end
|
145
150
|
|
146
151
|
end
|
data/spec/line_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__)+"/spec_helper.rb"
|
2
2
|
describe Rubyvis::Line do
|
3
3
|
it "should have correct properties" do
|
4
|
-
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]
|
5
|
-
Rubyvis::Line.properties.
|
4
|
+
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
|
+
Rubyvis::Line.properties.should==props
|
6
6
|
end
|
7
7
|
context "rendered" do
|
8
8
|
before do
|
data/spec/readme_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__)+"/spec_helper.rb"
|
2
|
+
describe "Rubyvis Readme" do
|
3
|
+
it "should work with RBP API" do
|
4
|
+
vis=nil
|
5
|
+
lambda {
|
6
|
+
vis = Rubyvis::Panel.new do
|
7
|
+
width 150
|
8
|
+
height 150
|
9
|
+
bar do
|
10
|
+
data [1, 1.2, 1.7, 1.5, 0.7, 0.3]
|
11
|
+
width 20
|
12
|
+
height {|d| d * 80}
|
13
|
+
bottom(0)
|
14
|
+
left {index * 25}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
vis.render}.should_not raise_exception
|
19
|
+
vis.to_svg.size.should>0
|
20
|
+
end
|
21
|
+
it "should work with Protovis API" do
|
22
|
+
vis=nil
|
23
|
+
lambda {
|
24
|
+
vis = Rubyvis::Panel.new.width(150).height(150);
|
25
|
+
|
26
|
+
vis.add(pv.Bar).
|
27
|
+
data([1, 1.2, 1.7, 1.5, 0.7, 0.3]).
|
28
|
+
width(20).
|
29
|
+
height(lambda {|d| d * 80}).
|
30
|
+
bottom(0).
|
31
|
+
left(lambda {self.index * 25});
|
32
|
+
|
33
|
+
vis.render
|
34
|
+
}.should_not raise_exception
|
35
|
+
vis.to_svg.size.should>0
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/spec.opts
CHANGED
data/web/Rakefile
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
require 'rake'
|
3
|
+
|
4
|
+
directory "examples"
|
5
|
+
|
3
6
|
def get_base(f)
|
4
7
|
f.sub(File.dirname(__FILE__)+"/../examples/","").gsub("/","_").gsub(".rb","")
|
5
8
|
end
|
6
|
-
directory "examples"
|
7
9
|
EXAMPLES=Dir.glob(File.dirname(__FILE__)+"/../examples/**/*.rb").map {|v| [v,get_base(v)]
|
8
10
|
}.find_all{|v| !v[0].include?"_data"}
|
9
11
|
|
10
12
|
EXAMPLES_BASE=EXAMPLES.map {|v| v[1]}
|
11
13
|
|
12
14
|
|
13
|
-
|
15
|
+
desc "Build all html and svg files"
|
14
16
|
task :build_site do
|
15
17
|
ruby "build_site.rb"
|
16
18
|
end
|
17
19
|
|
18
|
-
task :default=>["index.html","../lib/rubyvis.rb"]+EXAMPLES_BASE.map {|v| "examples/#{v}.html"}
|
19
|
-
|
20
|
+
task :default=>["examples", "index.html", "../lib/rubyvis.rb"]+EXAMPLES_BASE.map {|v| "examples/#{v}.html"}
|
20
21
|
|
21
22
|
file "index.html"=>["index.haml", :build_site]+EXAMPLES_BASE.map {|v| "examples/#{v}.png"}
|
22
23
|
|
@@ -26,7 +27,7 @@ EXAMPLES.each do |v|
|
|
26
27
|
file "examples/#{e}.svg"=>[v[0]] do |t|
|
27
28
|
system "ruby1.9 #{v[0]} > #{t.name}"
|
28
29
|
end
|
29
|
-
file "examples/#{e}.png"=>"examples/#{e}.svg" do |t|
|
30
|
+
file "examples/#{e}.png"=>["examples/#{e}.svg"] do |t|
|
30
31
|
system "rsvg -w 200 -h 200 -f png examples/#{e}.svg #{t.name}"
|
31
32
|
end
|
32
33
|
end
|
data/web/build_site.rb
CHANGED
@@ -21,7 +21,8 @@ pages={}
|
|
21
21
|
prev_page=nil
|
22
22
|
next_page=nil
|
23
23
|
|
24
|
-
Dir.glob(File.dirname(__FILE__)+"/../examples/**/*.rb")
|
24
|
+
files=Dir.glob(File.dirname(__FILE__)+"/../examples/**/*.rb").sort{|a,b| puts "#{a}, #{b}"; a<=>b}
|
25
|
+
files.each do |f|
|
25
26
|
|
26
27
|
next if f.include? "_data.rb"
|
27
28
|
fn=get_base(f)
|
@@ -84,7 +85,7 @@ Dir.glob(File.dirname(__FILE__)+"/../examples/**/*.rb") do |f|
|
|
84
85
|
|
85
86
|
end
|
86
87
|
|
87
|
-
pages.each do |name,page|
|
88
|
+
pages.each do |name, page|
|
88
89
|
html_file="examples/#{page.name}.html"
|
89
90
|
File.open(html_file,"w") {|fp|
|
90
91
|
fp.write(haml_template.render(page, :pages=>pages))
|