rubyvis 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +3 -0
- data/Manifest.txt +44 -0
- data/README.txt +64 -0
- data/Rakefile +16 -0
- data/examples/crimea-line.rb +64 -0
- data/examples/first.rb +17 -0
- data/examples/second.rb +14 -0
- data/lib/rubyvis.rb +43 -0
- data/lib/rubyvis/color/color.rb +241 -0
- data/lib/rubyvis/color/colors.rb +40 -0
- data/lib/rubyvis/color/ramp.rb +0 -0
- data/lib/rubyvis/format.rb +19 -0
- data/lib/rubyvis/format/date.rb +18 -0
- data/lib/rubyvis/format/number.rb +31 -0
- data/lib/rubyvis/internals.rb +215 -0
- data/lib/rubyvis/javascript_behaviour.rb +64 -0
- data/lib/rubyvis/label.rb +0 -0
- data/lib/rubyvis/mark.rb +528 -0
- data/lib/rubyvis/mark/anchor.rb +22 -0
- data/lib/rubyvis/mark/area.rb +34 -0
- data/lib/rubyvis/mark/bar.rb +23 -0
- data/lib/rubyvis/mark/label.rb +17 -0
- data/lib/rubyvis/mark/line.rb +14 -0
- data/lib/rubyvis/mark/panel.rb +87 -0
- data/lib/rubyvis/mark/rule.rb +28 -0
- data/lib/rubyvis/scale.rb +34 -0
- data/lib/rubyvis/scale/linear.rb +5 -0
- data/lib/rubyvis/scale/ordinal.rb +52 -0
- data/lib/rubyvis/scale/quantitative.rb +263 -0
- data/lib/rubyvis/scene/svg_bar.rb +31 -0
- data/lib/rubyvis/scene/svg_label.rb +51 -0
- data/lib/rubyvis/scene/svg_panel.rb +117 -0
- data/lib/rubyvis/scene/svg_rule.rb +29 -0
- data/lib/rubyvis/scene/svg_scene.rb +118 -0
- data/lib/rubyvis/sceneelement.rb +44 -0
- data/lib/rubyvis/transform.rb +25 -0
- data/spec/internal_spec.rb +146 -0
- data/spec/javascript_behaviour_spec.rb +64 -0
- data/spec/panel_spec.rb +8 -0
- data/spec/scale_linear_spec.rb +121 -0
- data/spec/scale_spec.rb +8 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +27 -0
- metadata +160 -0
- metadata.gz.sig +2 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__)+"/spec_helper.rb"
|
2
|
+
describe "Javascript compatibility" do
|
3
|
+
it "extends Proc with js_apply and js_call" do
|
4
|
+
f=lambda {|a,b| a+b}
|
5
|
+
f.should respond_to(:js_apply)
|
6
|
+
f.should respond_to(:js_call)
|
7
|
+
end
|
8
|
+
it "lambdas should respond correctly to js_call with same numbers of arguments and parameters" do
|
9
|
+
o=OpenStruct.new :x=>15
|
10
|
+
f=lambda {|m1,m2| "#{m1}-#{m2}-#{self.x}"}
|
11
|
+
f.js_call(o,"a","b").should=="a-b-15"
|
12
|
+
end
|
13
|
+
it "lambdas should respond correctly to js_call without arguments" do
|
14
|
+
o=OpenStruct.new :x=>15
|
15
|
+
f=lambda { self.x.to_s}
|
16
|
+
f.js_call(o).should=="15"
|
17
|
+
end
|
18
|
+
it "lambdas should respond correctly to js_call with different number or arguments" do
|
19
|
+
o=OpenStruct.new :x=>15
|
20
|
+
f=lambda {|a,b,c| [a,b,c]}
|
21
|
+
f.js_call(o,1).should==[1,nil,nil]
|
22
|
+
f.js_call(o,1,2,3,4).should==[1,2,3]
|
23
|
+
end
|
24
|
+
context "js_call using lambda with variable arguments" do
|
25
|
+
before do
|
26
|
+
@o=OpenStruct.new :x=>15
|
27
|
+
@f=lambda {|a,b,*c| {:a=>a, :b=>b, :c=>c}}
|
28
|
+
end
|
29
|
+
it "should work without 0 parameters" do
|
30
|
+
@f.js_call(@o).should=={:a=>nil, :b=>nil, :c=>[]}
|
31
|
+
end
|
32
|
+
it "should work with required parameter and 0 optional" do
|
33
|
+
@f.js_call(@o,1,2).should=={:a=>1, :b=>2, :c=>[]}
|
34
|
+
end
|
35
|
+
it "should work with required and optional parameters" do
|
36
|
+
@f.js_call(@o,1,2,3,4).should=={:a=>1, :b=>2, :c=>[3,4]}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
it "lambdas should respond correctly to js_apply" do
|
40
|
+
o=OpenStruct.new :x=>15
|
41
|
+
f=lambda {|m1,m2| "#{m1}-#{m2}-#{self.x}"}
|
42
|
+
f.js_apply(o, ["a","b"]).should=="a-b-15"
|
43
|
+
end
|
44
|
+
it "lambdas should respond correctly to js_apply with empty arguments" do
|
45
|
+
o=OpenStruct.new :x=>15
|
46
|
+
f=lambda { "#{self.x}"}
|
47
|
+
f.js_apply(o, []).should=="15"
|
48
|
+
f.js_apply(o, [1]).should=="15"
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
it "lambdas should respond correctly to js_call with fewer parameters" do
|
53
|
+
o=OpenStruct.new :x=>15
|
54
|
+
f=lambda {|a,b,c| [a,b,c]}
|
55
|
+
f.js_apply(o,[1]).should==[1,nil,nil]
|
56
|
+
end
|
57
|
+
it "lambdas should respond correctly to js_call with more parameters" do
|
58
|
+
o=OpenStruct.new :x=>15
|
59
|
+
f=lambda {|a,b,c| [a,b,c]}
|
60
|
+
f.js_apply(o,[1,2,3,4]).should==[1,2,3]
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
data/spec/panel_spec.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.dirname(__FILE__)+"/spec_helper.rb"
|
2
|
+
describe Rubyvis::Scale::Linear do
|
3
|
+
if Rubyvis::JohnsonLoader.available?
|
4
|
+
context "direct protovis API comparison" do
|
5
|
+
before(:all) do
|
6
|
+
@rt= Rubyvis::JohnsonLoader.new().runtime
|
7
|
+
end
|
8
|
+
before do
|
9
|
+
@h=280
|
10
|
+
@h_dom=1000
|
11
|
+
@y = Rubyvis.Scale.linear(0, @h_dom).range(0,@h)
|
12
|
+
@rt[:h_dom] = @h_dom
|
13
|
+
@rt[:h] = @h
|
14
|
+
@y_js=@rt.evaluate("y=pv.Scale.linear(0, h_dom).range(0,h)")
|
15
|
+
@v1,@v2,@v3=rand(),rand()+3,rand()+5
|
16
|
+
@rt[:v1]=@v1
|
17
|
+
@rt[:v2]=@v2
|
18
|
+
@rt[:v3]=@v3
|
19
|
+
|
20
|
+
end
|
21
|
+
it "domain() implemented equally" do
|
22
|
+
@y.domain(@v1)
|
23
|
+
@rt.evaluate("y.domain(v1)")
|
24
|
+
@y.domain.should==@rt.evaluate("y.domain()").to_a
|
25
|
+
@y.domain(@v1,@v2,@v3)
|
26
|
+
@rt.evaluate("y.domain(v1,v2,v3)")
|
27
|
+
@y.domain.should==@rt.evaluate("y.domain()").to_a
|
28
|
+
end
|
29
|
+
it "scale() implemented equally for complex domain" do
|
30
|
+
@y.domain(@v1,@v2,@v3)
|
31
|
+
@rt.evaluate("y.domain(v1,v2,v3)")
|
32
|
+
@y.scale(@v1+1).should==@rt.evaluate("y(v1+1)")
|
33
|
+
@y.scale(@v2+1).should==@rt.evaluate("y(v2+1)")
|
34
|
+
@y.scale(@v3+1).should==@rt.evaluate("y(v3+1)")
|
35
|
+
end
|
36
|
+
it "invert() implemented equally" do
|
37
|
+
@y.domain(@v1,@v2,@v3)
|
38
|
+
@rt.evaluate("y.domain(v1,v2,v3)")
|
39
|
+
@y.invert(@v1+1).should==@rt.evaluate("y.invert(v1+1)")
|
40
|
+
@y.invert(@v2+1).should==@rt.evaluate("y.invert(v2+1)")
|
41
|
+
@y.invert(@v3+1).should==@rt.evaluate("y.invert(v3+1)")
|
42
|
+
end
|
43
|
+
it "ticks() implemented equally for numbers" do
|
44
|
+
@y.ticks.should==@rt.evaluate("y.ticks()").to_a
|
45
|
+
(5..20).each {|i|
|
46
|
+
@rt[:i]=i
|
47
|
+
@y.ticks(i).should==@rt.evaluate("y.ticks(i)").to_a
|
48
|
+
}
|
49
|
+
end
|
50
|
+
it "nice() implemented equally" do
|
51
|
+
@y.domain(@v1,@v2)
|
52
|
+
@rt.evaluate("y.domain(v1,v2)")
|
53
|
+
@y.nice
|
54
|
+
@rt.evaluate("y.nice()")
|
55
|
+
@y.domain.should==@rt.evaluate("y.domain()").to_a
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
it "should be created as Javascript" do
|
62
|
+
h=280
|
63
|
+
y = Rubyvis.Scale.linear(0, 1500)
|
64
|
+
end
|
65
|
+
|
66
|
+
before do
|
67
|
+
@h=280
|
68
|
+
@h_dom=1000
|
69
|
+
@y = Rubyvis.Scale.linear(0, @h_dom).range(0,@h)
|
70
|
+
end
|
71
|
+
it "y should be a Scale" do
|
72
|
+
@y.should be_a(Rubyvis::Scale::Linear)
|
73
|
+
end
|
74
|
+
it "should set domain with dates" do
|
75
|
+
pending("Should accept dates as domain values")
|
76
|
+
data= [
|
77
|
+
{ :date=> Date.today, :wounds=> 0, :other=> 110, :disease=> 110 },
|
78
|
+
{ :date=> Date.new, :wounds=> 2, :other=> 130, :disease=> 110 }
|
79
|
+
|
80
|
+
]
|
81
|
+
x=Rubyvis.Scale.linear(data, lambda {|d| d[:date]})
|
82
|
+
|
83
|
+
end
|
84
|
+
it "should respond to domain" do
|
85
|
+
@y.domain.should==[0, 1000]
|
86
|
+
@y.domain(1)
|
87
|
+
@y.domain.should==[1,1]
|
88
|
+
@y.domain(1,100,300)
|
89
|
+
@y.domain.should==[1,100,300]
|
90
|
+
end
|
91
|
+
it "should respond to range" do
|
92
|
+
@y.range.should==[0, 280]
|
93
|
+
@y.range(1)
|
94
|
+
@y.range.should==[1,1]
|
95
|
+
@y.range(1,100,300)
|
96
|
+
@y.range.should==[1,100,300]
|
97
|
+
end
|
98
|
+
it "should returns correct scale" do
|
99
|
+
@y.scale(@h_dom).should==280
|
100
|
+
@y[@h_dom].should==280
|
101
|
+
val=20
|
102
|
+
@y.scale(val).should be_close(val.quo(@h_dom)*@h.to_f, 0.001)
|
103
|
+
end
|
104
|
+
it "should returns correct invert" do
|
105
|
+
@y.invert(100).should be_close(357.1428, 0.001)
|
106
|
+
@y.invert(200).should be_close(714.2857, 0.001)
|
107
|
+
end
|
108
|
+
it "should returns correct ticks" do
|
109
|
+
@y.ticks.should==[0,100,200,300,400,500,600,700,800,900,1000]
|
110
|
+
@y.ticks(13).should==[0,100,200,300,400,500,600,700,800,900,1000]
|
111
|
+
@y.ticks(5).should==[0,200,400,600,800,1000]
|
112
|
+
|
113
|
+
end
|
114
|
+
it "should returns correct tick_format"
|
115
|
+
it "should nice nicely" do
|
116
|
+
@y.domain([0.20147987687960267, 0.996679553296417])
|
117
|
+
@y.nice
|
118
|
+
@y.domain().should==[0.2,1]
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
data/spec/scale_spec.rb
ADDED
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
2
|
+
require 'spec'
|
3
|
+
require 'spec/autorun'
|
4
|
+
require 'rubyvis'
|
5
|
+
require 'pp'
|
6
|
+
$PROTOVIS_DIR=File.dirname(__FILE__)+"/../vendor/protovis/src"
|
7
|
+
module Rubyvis
|
8
|
+
class JohnsonLoader
|
9
|
+
begin
|
10
|
+
require 'johnson'
|
11
|
+
def self.available?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
def self.available?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
attr_accessor :runtime
|
20
|
+
def initialize(*files)
|
21
|
+
files=["/pv.js","/pv-internals.js", "/data/Arrays.js","/data/Numbers.js", "/data/Scale.js", "/data/QuantitativeScale.js", "/data/LinearScale.js","/color/Color.js","/color/Colors.js","/text/Format.js", "/text/DateFormat.js","/text/NumberFormat.js","/text/TimeFormat.js"]+files
|
22
|
+
files.uniq!
|
23
|
+
files=files.map {|v| $PROTOVIS_DIR+v}
|
24
|
+
@runtime = Johnson.load(*files)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyvis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Claudio Bustos
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain:
|
16
|
+
- |
|
17
|
+
-----BEGIN CERTIFICATE-----
|
18
|
+
MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhjbGJ1
|
19
|
+
c3RvczEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
20
|
+
MB4XDTEwMDMyOTIxMzg1NVoXDTExMDMyOTIxMzg1NVowPzERMA8GA1UEAwwIY2xi
|
21
|
+
dXN0b3MxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
22
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf8JVMGqE7m5kYb+PNN
|
23
|
+
neZv2pcXV5fQCi6xkyG8bi2/SIFy/LyxuvLzEeOxBeaz1Be93bayIUquOIqw3dyw
|
24
|
+
/KXWa31FxuNuvAm6CN8fyeRYX/ou4cw3OIUUnIvB7RMNIu4wbgeM6htV/QEsNLrv
|
25
|
+
at1/mh9JpqawPrcjIOVMj4BIp67vmzJCaUf+S/H2uYtSO09F+YQE3tv85TPeRmqU
|
26
|
+
yjyXyTc/oJiw1cXskUL8UtMWZmrwNLHXuZWWIMzkjiz3UNdhJr/t5ROk8S2WPznl
|
27
|
+
0bMy/PMIlAbqWolRn1zl2VFJ3TaXScbqImY8Wf4g62b/1ZSUlGrtnLNsCYXrWiso
|
28
|
+
UPUCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFGu9
|
29
|
+
rrJ1H64qRmNNu3Jj/Qjvh0u5MA0GCSqGSIb3DQEBBQUAA4IBAQCV0Unka5isrhZk
|
30
|
+
GjqSDqY/6hF+G2pbFcbWUpjmC8NWtAxeC+7NGV3ljd0e1SLfoyBj4gnFtFmY8qX4
|
31
|
+
K02tgSZM0eDV8TpgFpWXzK6LzHvoanuahHLZEtk/+Z885lFene+nHadkem1n9iAB
|
32
|
+
cs96JO9/JfFyuXM27wFAwmfHCmJfPF09R4VvGHRAvb8MGzSVgk2i06OJTqkBTwvv
|
33
|
+
JHJdoyw3+8bw9RJ+jLaNoQ+xu+1pQdS2bb3m7xjZpufml/m8zFCtjYM/7qgkKR8z
|
34
|
+
/ZZt8lCiKfFArppRrZayE2FVsps4X6WwBdrKTMZ0CKSXTRctbEj1BAZ67eoTvBBt
|
35
|
+
rpP0jjs0
|
36
|
+
-----END CERTIFICATE-----
|
37
|
+
|
38
|
+
date: 2010-09-30 00:00:00 -04:00
|
39
|
+
default_executable:
|
40
|
+
dependencies:
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubyforge
|
43
|
+
prerelease: false
|
44
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 2
|
50
|
+
- 0
|
51
|
+
- 4
|
52
|
+
version: 2.0.4
|
53
|
+
type: :development
|
54
|
+
version_requirements: *id001
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hoe
|
57
|
+
prerelease: false
|
58
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 6
|
65
|
+
- 2
|
66
|
+
version: 2.6.2
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id002
|
69
|
+
description: Ruby version of Protovis, a great visualization toolkit
|
70
|
+
email:
|
71
|
+
- clbustos_at_gmail.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files:
|
77
|
+
- History.txt
|
78
|
+
- Manifest.txt
|
79
|
+
- README.txt
|
80
|
+
files:
|
81
|
+
- History.txt
|
82
|
+
- Manifest.txt
|
83
|
+
- README.txt
|
84
|
+
- Rakefile
|
85
|
+
- examples/crimea-line.rb
|
86
|
+
- examples/first.rb
|
87
|
+
- examples/second.rb
|
88
|
+
- lib/rubyvis.rb
|
89
|
+
- lib/rubyvis/color/color.rb
|
90
|
+
- lib/rubyvis/color/colors.rb
|
91
|
+
- lib/rubyvis/color/ramp.rb
|
92
|
+
- lib/rubyvis/format.rb
|
93
|
+
- lib/rubyvis/format/date.rb
|
94
|
+
- lib/rubyvis/format/number.rb
|
95
|
+
- lib/rubyvis/internals.rb
|
96
|
+
- lib/rubyvis/javascript_behaviour.rb
|
97
|
+
- lib/rubyvis/label.rb
|
98
|
+
- lib/rubyvis/mark.rb
|
99
|
+
- lib/rubyvis/mark/anchor.rb
|
100
|
+
- lib/rubyvis/mark/area.rb
|
101
|
+
- lib/rubyvis/mark/bar.rb
|
102
|
+
- lib/rubyvis/mark/label.rb
|
103
|
+
- lib/rubyvis/mark/line.rb
|
104
|
+
- lib/rubyvis/mark/panel.rb
|
105
|
+
- lib/rubyvis/mark/rule.rb
|
106
|
+
- lib/rubyvis/scale.rb
|
107
|
+
- lib/rubyvis/scale/linear.rb
|
108
|
+
- lib/rubyvis/scale/ordinal.rb
|
109
|
+
- lib/rubyvis/scale/quantitative.rb
|
110
|
+
- lib/rubyvis/scene/svg_bar.rb
|
111
|
+
- lib/rubyvis/scene/svg_label.rb
|
112
|
+
- lib/rubyvis/scene/svg_panel.rb
|
113
|
+
- lib/rubyvis/scene/svg_rule.rb
|
114
|
+
- lib/rubyvis/scene/svg_scene.rb
|
115
|
+
- lib/rubyvis/sceneelement.rb
|
116
|
+
- lib/rubyvis/transform.rb
|
117
|
+
- spec/internal_spec.rb
|
118
|
+
- spec/javascript_behaviour_spec.rb
|
119
|
+
- spec/panel_spec.rb
|
120
|
+
- spec/scale_linear_spec.rb
|
121
|
+
- spec/scale_spec.rb
|
122
|
+
- spec/spec.opts
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
has_rdoc: true
|
125
|
+
homepage: http://github.com/clbustos/rubyvis
|
126
|
+
licenses: []
|
127
|
+
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options:
|
130
|
+
- --main
|
131
|
+
- README.txt
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
requirements: []
|
149
|
+
|
150
|
+
rubyforge_project: rubyvis
|
151
|
+
rubygems_version: 1.3.6
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: Ruby version of Protovis, a great visualization toolkit
|
155
|
+
test_files:
|
156
|
+
- spec/internal_spec.rb
|
157
|
+
- spec/panel_spec.rb
|
158
|
+
- spec/scale_spec.rb
|
159
|
+
- spec/scale_linear_spec.rb
|
160
|
+
- spec/javascript_behaviour_spec.rb
|
metadata.gz.sig
ADDED