rubyvis 0.1.3 → 0.1.4

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.
@@ -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(lambda{|x| x}).font("10px sans-serif").text_angle(0).text_style(pv.color('black')).text_align('left').text_baseline('bottom').text_margin(3)
13
+ Label.new.extend(Mark.defaults).events('none').text(lambda{|x| x}).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
@@ -31,7 +31,8 @@ module Rubyvis
31
31
  area_build_instance(*args)
32
32
  end
33
33
  def self.defaults
34
- Line.new.extend(Mark.defaults).line_join('miter').line_width(1.5).stroke_style( lambda {return Rubyvis::Colors.category10().scale(self.parent.index)}).interpolate('linear').eccentricity(0).tension(7)
34
+ a=Rubyvis::Colors.category10()
35
+ Line.new.extend(Mark.defaults).line_join('miter').line_width(1.5).stroke_style( lambda {return a.scale(self.parent.index)}).interpolate('linear').eccentricity(0).tension(7)
35
36
  end
36
37
  end
37
38
  end
@@ -50,7 +50,7 @@ module Rubyvis
50
50
  super(s)
51
51
  return if !s.visible
52
52
  s.children=[] if !s.children
53
- scale=self.scale*s.transform.k
53
+ scale=self.scale * s.transform.k
54
54
  n=self.children.size
55
55
  Mark.index=-1
56
56
  n.times {|i|
@@ -77,12 +77,14 @@ module Rubyvis
77
77
  }.join
78
78
  end
79
79
  def build_implied(s)
80
+ panel_build_implied(s)
81
+ end
82
+ def panel_build_implied(s)
80
83
  if(!self.parent)
81
84
  c=s.canvas
82
85
  if(c)
83
86
  if(c._panel!=self)
84
87
  c._panel=self
85
- p "hola"
86
88
  c.delete_if? {true}
87
89
  end
88
90
  if s.width.nil?
@@ -103,10 +105,8 @@ module Rubyvis
103
105
  end
104
106
  s.canvas=c
105
107
  end
106
-
107
108
  s.transform=Rubyvis.Transform.identity if (s.transform.nil?)
108
- super(s)
109
-
109
+ mark_build_implied(s)
110
110
  end
111
111
 
112
112
  end
@@ -9,7 +9,8 @@ module Rubyvis
9
9
  @properties=Mark.properties.dup
10
10
  attr_accessor_dsl :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :line_width, [:stroke_style, lambda {|d| pv.color(d)}], [:fill_style, lambda {|d| pv.color(d)}]
11
11
  def self.defaults
12
- 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 {Rubyvis.Colors.category20().scale(self.parent.index)})
12
+ a=Rubyvis.Colors.category20()
13
+ 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)})
13
14
  end
14
15
  def mid_radius
15
16
  (inner_radius+outer_radius) / 2.0
@@ -83,7 +83,7 @@ module Rubyvis
83
83
  return self
84
84
  end
85
85
  def sort_keys(order=nil)
86
- #keys[keys.size-1].order = order.nil? ? pv.natural_order : order
86
+ keys[keys.size-1].order = order.nil? ? pv.natural_order : order
87
87
  return self
88
88
  end
89
89
  def sort_values(order=nil)
@@ -91,7 +91,7 @@ module Rubyvis
91
91
  return self
92
92
  end
93
93
  def map
94
- i=0
94
+ #i=0
95
95
  map={}
96
96
  values=[]
97
97
  @array.each_with_index {|x,j|
@@ -111,7 +111,7 @@ module Rubyvis
111
111
  }
112
112
  if(self.order)
113
113
  values.each_with_index {|v,vi|
114
- values[vi].sort(&self.order)
114
+ values[vi].sort!(&self.order)
115
115
  }
116
116
  end
117
117
  map
@@ -129,16 +129,15 @@ module Rubyvis
129
129
  def entries_sort(array,i)
130
130
  o=keys[i].order
131
131
  if o
132
- array.sort {|a,b| o(a.key, b.key)}
132
+ array.sort! {|a,b| o.call(a.key, b.key)}
133
133
  end
134
134
  i+=1
135
135
  if (i<keys.size)
136
136
  array.each {|v|
137
137
  entries_sort(v, i)
138
138
  }
139
-
140
139
  end
141
- return array
140
+ array
142
141
 
143
142
  end
144
143
  def rollup_rollup(map,f)
@@ -9,8 +9,7 @@ module Rubyvis
9
9
  base(10)
10
10
  end
11
11
  def log(x)
12
-
13
- Math.log(x+1e15) / @_p
12
+ Math.log(x) / @_p.to_f
14
13
  end
15
14
  def pow(y)
16
15
  @b**y
@@ -24,32 +23,39 @@ module Rubyvis
24
23
  end
25
24
  return @b
26
25
  end
26
+ def nice
27
+ d=domain
28
+ domain(pv.log_floor(d[0],@b), pv.log_ceil(d[1],@b))
29
+ end
27
30
  def ticks
28
31
  d = domain
29
- n = d[0] < 0,
32
+ n = d[0] < 0
33
+
34
+ # puts "dom: #{d[0]} -> #{n}"
35
+
30
36
  i = (n ? -log(-d[0]) : log(d[0])).floor
31
37
  j = (n ? -log(-d[1]) : log(d[1])).ceil
32
38
  ticks = [];
33
- if n
39
+ if n
34
40
  ticks.push(-pow(-i))
35
41
  (i..j).each {|ii|
36
- ((b-1)...0).each {|k|
42
+ ((@b-1)...0).each {|k|
37
43
  ticks.push(-pow(-ii) * k)
38
44
  }
39
45
  }
40
46
  else
41
47
  (i...j).each {|ii|
42
- (1...b).each {|k|
43
- ticks.push(pow(i) * k)
48
+ (1...@b).each {|k|
49
+ ticks.push(pow(ii) * k)
44
50
  }
45
51
  }
46
- ticks.push(pow(i));
52
+ ticks.push(pow(j));
47
53
  end
48
54
 
49
55
  #for (i = 0; ticks[i] < d[0]; i++); // strip small values
50
56
  #for (j = ticks.length; ticks[j - 1] > d[1]; j--); // strip big values
51
57
  #return ticks.slice(i, j);
52
- ticks
58
+ ticks.find_all {|v| v>=d[0] and v<=d[1]}
53
59
  end
54
60
  end
55
61
  end
@@ -15,11 +15,11 @@ module Rubyvis
15
15
 
16
16
  return e if (fill.opacity==0 and stroke.opacity==0)
17
17
  # /** @private Computes the straight path for the range [i, j]. */
18
- path=lambda {|i,j|
18
+ path=lambda {|ii,j|
19
19
  p1 = []
20
20
  p2 = [];
21
21
  k=j
22
- (i..k).each {|i|
22
+ (ii..k).each {|i|
23
23
  si = scenes[i]
24
24
  sj = scenes[j]
25
25
  pi = "#{si.left},#{si.top}"
@@ -48,7 +48,7 @@ module Rubyvis
48
48
  }
49
49
 
50
50
  # @private Computes the curved path for the range [i, j]. */
51
- path_curve=lambda {|i, j|
51
+ path_curve=lambda {|ii, j|
52
52
  pointsT = []
53
53
  pointsB = []
54
54
  pathT=nil
@@ -56,7 +56,7 @@ module Rubyvis
56
56
 
57
57
 
58
58
  k=j
59
- (i..k).each {|i|
59
+ (ii..k).each {|i|
60
60
  sj = scenes[j];
61
61
  pointsT.push(scenes[i])
62
62
  pointsB.push(OpenStruct.new({:left=> sj.left + sj.width, :top=> sj.top + sj.height}))
@@ -112,9 +112,9 @@ module Rubyvis
112
112
  "stroke-width"=> stroke.opacity!=0 ? s.line_width / self.scale : nil
113
113
  });
114
114
  return self.append(e, scenes, 0);
115
- end
115
+ end
116
116
 
117
- def self.area_segment(scenes)
117
+ def self.area_segment(scenes)
118
118
 
119
119
  e = scenes._g.elements[1]
120
120
  s = scenes[0]
@@ -191,7 +191,7 @@ module Rubyvis
191
191
  e = self.append(e, scenes, i);
192
192
  }
193
193
  return e;
194
- end
195
- end
194
+ end
195
+ end
196
196
  end
197
197
 
@@ -118,14 +118,14 @@ module Rubyvis
118
118
  e = 1 - s1.eccentricity
119
119
  r = Math.sqrt(dx * dx + dy * dy) / (2 * e)
120
120
  if !((e<=0) and (e>1))
121
- return "A" + r + "," + r + " 0 0," + l + " " + s2.left + "," + s2.top
121
+ return "A#{r},#{r} 0 0,#{l} #{s2.left},#{s2.top}"
122
122
  end
123
123
  when "step-before"
124
- return "V" + s2.top + "H" + s2.left
124
+ return "V#{s2.top}H#{s2.left}"
125
125
  when "step-after"
126
- return "H" + s2.left + "V" + s2.top
126
+ return "H#{s2.left}V#{s2.top}"
127
127
  end
128
- return "L" + s2.left.to_s + "," + s2.top.to_s
128
+ return "L#{s2.left},#{s2.top}"
129
129
  end
130
130
 
131
131
  #/** @private Line-line intersection, per Akenine-Moller 16.16.1. */
@@ -5,7 +5,7 @@ module Rubyvis
5
5
  end
6
6
  include Enumerable
7
7
  attr_accessor :visible
8
- 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
8
+ 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
9
9
 
10
10
  def []=(v,i)
11
11
  if v.is_a? Numeric
@@ -0,0 +1,105 @@
1
+ require File.dirname(__FILE__)+"/spec_helper.rb"
2
+ describe Rubyvis::Scale::Log do
3
+ if Rubyvis::JohnsonLoader.available?
4
+ context "direct protovis API comparison" do
5
+ before(:all) do
6
+ @rt= Rubyvis::JohnsonLoader.new("/data/LogScale.js").runtime
7
+ end
8
+ before do
9
+ @h=280
10
+ @h_dom=1000
11
+ @y = Rubyvis.Scale.log(1, @h_dom).range(1,@h)
12
+ @rt[:h_dom] = @h_dom
13
+ @rt[:h] = @h
14
+ @y_js=@rt.evaluate("y=pv.Scale.log(1, h_dom).range(1,h)")
15
+ @v1,@v2,@v3=rand()+1,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
+
46
+ end
47
+ it "nice() implemented equally" do
48
+ @y.domain(@v1,@v2)
49
+ @rt.evaluate("y.domain(v1,v2)")
50
+ @y.nice
51
+ @rt.evaluate("y.nice()")
52
+ @y.domain.should==@rt.evaluate("y.domain()").to_a
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ it "should be created as Javascript" do
59
+ h=280
60
+ y = Rubyvis.Scale.log(1, 1500)
61
+ end
62
+
63
+ before do
64
+ @h=280
65
+ @h_dom=1000
66
+ @y = Rubyvis.Scale.log(1, @h_dom).range(1,@h)
67
+ end
68
+ it "y should be a Scale" do
69
+ @y.should be_a(Rubyvis::Scale::Log)
70
+ end
71
+ it "should respond to domain" do
72
+ @y.domain.should==[1, 1000]
73
+ @y.domain(1)
74
+ @y.domain.should==[1,1]
75
+ @y.domain(1,100,300)
76
+ @y.domain.should==[1,100,300]
77
+ end
78
+ it "should respond to range" do
79
+ @y.range.should==[1, 280]
80
+ @y.range(1)
81
+ @y.range.should==[1,1]
82
+ @y.range(1,100,300)
83
+ @y.range.should==[1,100,300]
84
+ end
85
+ it "should returns correct scale" do
86
+ @y.scale(@h_dom).should==280
87
+ @y[@h_dom].should==280
88
+ val=20
89
+ @y.scale(val).should be_close(121.995, 0.001)
90
+ end
91
+ it "should returns correct invert" do
92
+ @y.invert(100).should be_close(11.601, 0.001)
93
+ @y.invert(200).should be_close(137.970, 0.001)
94
+ end
95
+ it "should returns correct ticks" do
96
+ t=1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900,1000
97
+ @y.ticks.should==t
98
+
99
+ end
100
+ it "should nice nicely" do
101
+ @y.domain([0.20147987687960267, 0.996679553296417])
102
+ @y.nice
103
+ @y.domain().should==[0.1,1]
104
+ end
105
+ end
@@ -1,2 +1,3 @@
1
1
  --color
2
- -f s
2
+ -f s
3
+ -b
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
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-08 00:00:00 -04:00
38
+ date: 2010-10-20 00:00:00 -03:00
39
39
  default_executable:
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
@@ -93,10 +93,13 @@ files:
93
93
  - examples/crimea/crimea_line.rb
94
94
  - examples/dot.rb
95
95
  - examples/first.rb
96
+ - examples/grouped_charts.rb
96
97
  - examples/line.rb
98
+ - examples/line_and_step.rb
97
99
  - examples/pie_and_donut.rb
98
100
  - examples/scatterplot.rb
99
101
  - examples/second.rb
102
+ - examples/stacked_charts.rb
100
103
  - examples/third.rb
101
104
  - lib/rubyvis.rb
102
105
  - lib/rubyvis/color/color.rb
@@ -108,6 +111,8 @@ files:
108
111
  - lib/rubyvis/internals.rb
109
112
  - lib/rubyvis/javascript_behaviour.rb
110
113
  - lib/rubyvis/label.rb
114
+ - lib/rubyvis/layout.rb
115
+ - lib/rubyvis/layout/stack.rb
111
116
  - lib/rubyvis/mark.rb
112
117
  - lib/rubyvis/mark/anchor.rb
113
118
  - lib/rubyvis/mark/area.rb
@@ -282,6 +287,7 @@ test_files:
282
287
  - spec/scale_ordinal_spec.rb
283
288
  - spec/internal_spec.rb
284
289
  - spec/panel_spec.rb
290
+ - spec/scale_log_spec.rb
285
291
  - spec/scale_linear_datetime_spec.rb
286
292
  - spec/scale_spec.rb
287
293
  - spec/scale_linear_spec.rb
metadata.gz.sig CHANGED
Binary file