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.
data.tar.gz.sig CHANGED
@@ -1,3 +1 @@
1
- ��!8O���[��S<!͊���tDp
2
- JIcA݃��>�Cr�m�
3
- A{�F��kb]�Q ������t}2ٜ��S�;
1
+ d!FA&{���Ap��O�WC��Q!v���!��a:-�!� N���[5������z\� �譋�LV��?�y��d'ПP}���,u�b�~��p T�$�N%�̗����z��BtP��SX
@@ -1,4 +1,12 @@
1
- === 0.1.3 / 2010-10-08
1
+ === 0.1.4 / 2010-10-20
2
+
3
+ * Bug fix: Order now works on Nest
4
+ * Added log scale spec. domain, range, scale, invert and ticks works like javascript version
5
+ * First stack layout version operational
6
+ * Added grouped and stacked chart examples
7
+
8
+
9
+ === 0.1.3 / 2010-10-08
2
10
 
3
11
  * New Wedge and Dot mark
4
12
  * New Log scale and Nest.
@@ -13,10 +13,13 @@ examples/crimea/crimea_grouped_bar.rb
13
13
  examples/crimea/crimea_line.rb
14
14
  examples/dot.rb
15
15
  examples/first.rb
16
+ examples/grouped_charts.rb
16
17
  examples/line.rb
18
+ examples/line_and_step.rb
17
19
  examples/pie_and_donut.rb
18
20
  examples/scatterplot.rb
19
21
  examples/second.rb
22
+ examples/stacked_charts.rb
20
23
  examples/third.rb
21
24
  lib/rubyvis.rb
22
25
  lib/rubyvis/color/color.rb
@@ -28,6 +31,8 @@ lib/rubyvis/format/number.rb
28
31
  lib/rubyvis/internals.rb
29
32
  lib/rubyvis/javascript_behaviour.rb
30
33
  lib/rubyvis/label.rb
34
+ lib/rubyvis/layout.rb
35
+ lib/rubyvis/layout/stack.rb
31
36
  lib/rubyvis/mark.rb
32
37
  lib/rubyvis/mark/anchor.rb
33
38
  lib/rubyvis/mark/area.rb
data/README.txt CHANGED
@@ -8,13 +8,34 @@ Ruby port of Protovis, a great visualization toolkit
8
8
 
9
9
  == FEATURES/PROBLEMS:
10
10
 
11
- Implemented: Panel, Bar, Rule, Line and Label. Anchor doesn't work yet
12
- I try to maintain, when posible, complete compatibility with Javascript API. Johnson [http://github.com/jbarnette/johnson] - the lovely Javascript wrapper inside Ruby embrace - is our friend.
11
+ Implemented: All marks, except transient, image and transition.
12
+
13
+ Basic protovis examples[http://vis.stanford.edu/protovis/ex/] works exactly like ruby ones with minor sintactic modifications:
14
+ * Area Charts: Ok
15
+ * Bar & Column Charts: Ok
16
+ * Scatterplots: Ok
17
+ * Pie & Donut: Interaction with mouse not implemented
18
+ * Line & Step Charts: Ok
19
+ * Stacked Charts: Ok
20
+ * Grouped Charts: Almost ok. Problems on data stack at third level.
21
+
22
+ Complex examples requires more works:
23
+
24
+ * antibiotics: Almost ok. Missing center labels
25
+ * barley: ok
26
+ * crimea: line and grouped line ok.
27
+
28
+
29
+ I try to maintain, when posible, complete compatibility with Javascript API, including camel case naming of functions. Johnson [http://github.com/jbarnette/johnson] - the lovely Javascript wrapper inside Ruby embrace - is our friend.
13
30
 
14
31
  Until version 0.1.0, lambdas should always should created explicitly for method you may be temted to call it with a block.
32
+
15
33
  On a second stage, traditional block calling could be using maintaining backwards compatibily with Javascript API,
34
+
16
35
  User could use +pv+ freely, cause is defined as a global method which call Rubyvis.
17
36
 
37
+ +self.parent.index+ doesn't work always as expected. +self.index+ works ok. I'm working on it
38
+
18
39
  == CURRENT PROGRESS
19
40
 
20
41
  * pv.js
@@ -25,14 +46,20 @@ User could use +pv+ freely, cause is defined as a global method which call Rubyv
25
46
  * data/Numbers.js
26
47
  * data/Scale.js
27
48
  * data/LinearScale.js
49
+ * data/LogScale.js (incomplete)
50
+ * data/Nest.js
28
51
  * data/QuantitativeScale.js
29
- * data/OrdinalScale.js (not tested)
30
- * mark/Mark.js
52
+ * data/OrdinalScale.js
53
+ * mark/Anchor.js
54
+ * mark/Area.js
31
55
  * mark/Bar.js
32
- * mark/Panel.js
56
+ * mark/Dot.js
33
57
  * mark/Label.js
34
58
  * mark/Line.js
59
+ * mark/Mark.js
60
+ * mark/Panel.js
35
61
  * mark/Rule.js
62
+ * mark/Wedge.js
36
63
  * scene/SvgBar.js
37
64
  * scene/SvgLabel.js
38
65
  * scene/SvgLine.js
@@ -55,7 +82,8 @@ User could use +pv+ freely, cause is defined as a global method which call Rubyv
55
82
  vis.render
56
83
  puts vis.to_svg
57
84
 
58
-
85
+ See examples directory for original protovis examples adaptations.
86
+
59
87
  == REQUIREMENTS:
60
88
 
61
89
  Ruby 1.8.7 or 1.9.1
@@ -5,8 +5,8 @@ load(File.dirname(__FILE__)+"/antibiotics_data.rb")
5
5
  s = 180
6
6
  _p = 20
7
7
  z = pv.Scale.log(0.001, 1000).range(0, s)
8
- color = pv.colors("darkred", "darkblue").by(lambda {|d| d[:gram]})
9
- ticks = pv.range(-2, 3).map {|e| 10**e}
8
+ color = pv.colors("darkred", "darkblue")
9
+ ticks = pv.range(-2, 3).map {|e| (10**e).to_f}
10
10
 
11
11
  #/* Root panel. */
12
12
  vis = Rubyvis::Panel.new
@@ -29,7 +29,7 @@ cell = vis.add(pv.Panel)
29
29
 
30
30
  #/* Label. */
31
31
  cell.anchor("center").add(pv.Label)
32
- .visible(lambda {|d, y, x| x == y})
32
+ .visible(lambda {|d, y, x| puts d,y,x; return x == y})
33
33
  .font("bold 14px sans-serif")
34
34
  .text(lambda {|d, y, x| x});
35
35
 
@@ -37,18 +37,18 @@ cell.anchor("center").add(pv.Label)
37
37
  plot = cell.add(pv.Panel)
38
38
  .data(lambda {|y, x| [x]})
39
39
  .visible(lambda {|x, y| x != y})
40
- .stroke_style(pv.color("#aaa"));
40
+ .stroke_style("#aaa");
41
41
 
42
42
  #/* Ticks. */
43
43
  tick = pv.Rule.new()
44
44
  .visible(lambda {|d, x, y| x != y})
45
45
  .data(ticks)
46
- .stroke_style(pv.color("#ddd"));
46
+ .stroke_style("#ddd");
47
47
 
48
48
  #/* X-axis ticks. */
49
49
  xtick = plot.add(pv.Rule)
50
50
  .extend(tick)
51
- .left(lambda {|d| z.scale(d)});
51
+ .left(z);
52
52
 
53
53
  #/* Bottom and top labels. */
54
54
  xtick.anchor("bottom").add(pv.Label)
@@ -59,7 +59,7 @@ xtick.anchor("top").add(pv.Label)
59
59
  #/* Y-axis ticks. */
60
60
  ytick = plot.add(pv.Rule)
61
61
  .extend(tick)
62
- .bottom(lambda {|d| z.scale(d)});
62
+ .bottom(z);
63
63
 
64
64
  #/* Bottom and top labels. */
65
65
  ytick.anchor("right").add(pv.Label)
@@ -76,10 +76,10 @@ ytick.anchor("left").add(pv.Label)
76
76
  #/* Dot plot. */
77
77
  dot = plot.add(pv.Dot)
78
78
  .data($bacteria)
79
- .stroke_style(pv.color("red"))
80
- .fill_style(lambda {self.stroke_style()})
81
- .left(lambda {|d, x, y| z.scale(d[x])})
82
- .bottom(lambda {|d, x, y| z.scale(d[y])})
79
+ .stroke_style(lambda {|d| color.scale(d[:gram])})
80
+ .fill_style(lambda {|d| color.scale(d[:gram]).alpha(0.2)})
81
+ .left(lambda {|d, x, y| z.scale(d[x.to_sym])})
82
+ .bottom(lambda {|d, x, y| z.scale(d[y.to_sym])})
83
83
  .title(lambda {|d| d[:name]});
84
84
 
85
85
  #/* Legend. */
@@ -27,7 +27,7 @@ c = pv.Colors.category10()
27
27
  # The root panel. */
28
28
  vis = Rubyvis::Panel.new
29
29
  .width(w)
30
- .height(h * pv.keys(site).length)
30
+ .height(h * pv.keys(site).size)
31
31
  .top(15.5)
32
32
  .left(0.5)
33
33
  .right(0.5)
@@ -44,7 +44,7 @@ cell = vis.add(pv.Panel)
44
44
  # Title bar. */
45
45
  cell.add(pv.Bar)
46
46
  .height(14)
47
- .fill_style(pv.color("bisque"))
47
+ .fill_style("bisque")
48
48
  .anchor("center").add(pv.Label)
49
49
  .text(lambda{|site| site.key});
50
50
 
@@ -62,17 +62,17 @@ dot = cell.add(pv.Panel)
62
62
 
63
63
  # A label showing the variety. */
64
64
  dot.anchor("left").add(pv.Label)
65
- .visible(lambda { !self.parent.index})
65
+ .visible(lambda { self.parent.index!=0})
66
66
  .left(-2)
67
67
  .text(lambda {|d| d[:variety]})
68
68
 
69
69
  # X-ticks. */
70
70
  vis.add(pv.Rule)
71
71
  .data(x.ticks())
72
- .left(lambda {|d| x.scale(d)})
72
+ .left(lambda {|d| 90+x.scale(d)})
73
73
  .bottom(-5)
74
74
  .height(5)
75
- .stroke_style(pv.color("#999"))
75
+ .stroke_style("#999")
76
76
  .anchor("bottom").add(pv.Label);
77
77
 
78
78
  # A legend showing the year. */
@@ -0,0 +1,67 @@
1
+ $:.unshift(File.dirname(__FILE__)+"/../lib")
2
+ require 'rubyvis'
3
+
4
+ n = 3
5
+ m = 4
6
+ data = pv.range(n).map {
7
+ pv.range(m).map {
8
+ rand() + 0.1;
9
+ }
10
+ }
11
+
12
+
13
+ w = 400
14
+ h = 250
15
+ x = pv.Scale.linear(0, 1.1).range(0, w)
16
+ y = pv.Scale.ordinal(pv.range(n)).split_banded(0, h, 4/5.0);
17
+
18
+ #/* The root panel. */
19
+ vis = pv.Panel.new()
20
+ .width(w)
21
+ .height(h)
22
+ .bottom(20)
23
+ .left(20)
24
+ .right(10)
25
+ .top(5);
26
+
27
+ #/* The bars. */
28
+
29
+ colors=pv.Colors.category20()
30
+
31
+ bar = vis.add(pv.Panel)
32
+ .data(data)
33
+ .top(lambda {y.scale(self.index)})
34
+ .height(y.range_band)
35
+ .add(pv.Bar)
36
+ .data(lambda {|d| d})
37
+ .top(lambda {self.index * y.range_band / m.to_f})
38
+ .height(y.range_band / m.to_f)
39
+ .left(0)
40
+ .width(x)
41
+ .fillStyle(lambda { colors.scale(self.index)})
42
+
43
+ #/* The value label. */
44
+ bar.anchor("right").add(pv.Label)
45
+ .textStyle("white")
46
+ .text(lambda {|d| "%0.1f" % d});
47
+
48
+ #/* The variable label. */
49
+ bar.parent.anchor("left").add(pv.Label)
50
+ .textAlign("right")
51
+ .textMargin(5)
52
+ .text(lambda {"ABCDEFGHIJK"[self.parent.index,1]});
53
+
54
+ #/* X-axis ticks. */
55
+ vis.add(pv.Rule)
56
+ .data(x.ticks(5))
57
+ .left(x)
58
+ .strokeStyle(lambda {|d| d!=0 ? "rgba(255,255,255,.3)" : "#000"})
59
+ .add(pv.Rule)
60
+ .bottom(0)
61
+ .height(5)
62
+ .strokeStyle("#000")
63
+ .anchor("bottom").add(pv.Label)
64
+ .text(x.tick_format);
65
+
66
+ vis.render();
67
+ puts vis.to_svg
@@ -0,0 +1,61 @@
1
+ $:.unshift(File.dirname(__FILE__)+"/../lib")
2
+ require 'rubyvis'
3
+
4
+ data = pv.range(0, 10, 0.2).map {|x|
5
+ OpenStruct.new({:x=> x, :y=> Math.sin(x) + rand() + 1.5})
6
+ }
7
+
8
+
9
+ vis = pv.Panel.new().width(200).height(200);
10
+
11
+
12
+ w = 400
13
+ h = 200
14
+ x = pv.Scale.linear(data, lambda {|d| d.x}).range(0, w)
15
+
16
+ y = pv.Scale.linear(0, 4).range(0, h);
17
+
18
+ #/* The root panel. */
19
+ vis = pv.Panel.new()
20
+ .width(w)
21
+ .height(h)
22
+ .bottom(20)
23
+ .left(20)
24
+ .right(10)
25
+ .top(5);
26
+
27
+ #/* X-axis ticks. */
28
+ vis.add(pv.Rule)
29
+ .data(x.ticks())
30
+ .visible(lambda {|d| d > 0})
31
+ .left(x)
32
+ .strokeStyle("#eee")
33
+ .add(pv.Rule)
34
+ .bottom(-5)
35
+ .height(5)
36
+ .strokeStyle("#000")
37
+ .anchor("bottom").add(pv.Label)
38
+ .text(x.tick_format)
39
+
40
+ #/* Y-axis ticks. */
41
+ vis.add(pv.Rule)
42
+ .data(y.ticks(5))
43
+ .bottom(y)
44
+ .strokeStyle(lambda {|d| d!=0 ? "#eee" : "#000"})
45
+ .anchor("left").add(pv.Label)
46
+ .text(y.tick_format);
47
+
48
+ #/* The line. */
49
+ vis.add(pv.Line)
50
+ .data(data)
51
+ .interpolate("step-after")
52
+ .left(lambda {|d| x.scale(d.x)})
53
+ .bottom(lambda {|d| y.scale(d.y)})
54
+ .lineWidth(3);
55
+
56
+ vis.render();
57
+
58
+
59
+
60
+
61
+ puts vis.to_svg
@@ -0,0 +1,50 @@
1
+ $:.unshift(File.dirname(__FILE__)+"/../lib")
2
+ require 'rubyvis'
3
+
4
+ data = pv.range(4).map {|i|
5
+ pv.range(0, 10, 1).map {|x|
6
+ OpenStruct.new({:x=> x, :y=> Math.sin(x) + rand() * 0.5 + 2})
7
+ }
8
+ }
9
+
10
+ w = 400
11
+ h = 200
12
+
13
+ x = pv.Scale.linear(0, 9.9).range(0, w)
14
+ y = pv.Scale.linear(0, 14).range(0, h)
15
+
16
+ #/* The root panel. */
17
+ vis = pv.Panel.new()
18
+ .width(w)
19
+ .height(h)
20
+ .bottom(20)
21
+ .left(20)
22
+ .right(10)
23
+ .top(5)
24
+ if(true)
25
+ #/* X-axis and ticks. */
26
+ vis.add(pv.Rule)
27
+ .data(x.ticks())
28
+ .visible(lambda {|d| d!=0})
29
+ .left(x)
30
+ .bottom(-5)
31
+ .height(5)
32
+ .anchor("bottom").add(pv.Label)
33
+ .text(x.tick_format)
34
+ #/* Y-axis and ticks. */
35
+ vis.add(pv.Rule)
36
+ .data(y.ticks(3))
37
+ .bottom(y)
38
+ .strokeStyle(lambda {|d| d!=0 ? "rgba(128,128,128,.2)" : "#000"})
39
+ .anchor("left").add(pv.Label)
40
+ .text(y.tick_format)
41
+ end
42
+ #/* The stack layout. */
43
+ vis.add(pv.Layout.Stack)
44
+ .layers(data)
45
+ .x(lambda {|d| x.scale(d.x)})
46
+ .y(lambda {|d| y.scale(d.y)})
47
+ .layer.add(pv.Area)
48
+
49
+ vis.render();
50
+ puts vis.to_svg
@@ -1,16 +1,20 @@
1
1
  $:.unshift(File.dirname(__FILE__)+"/../lib")
2
2
  require 'rubyvis'
3
3
 
4
- vis = pv.Panel.new().width(300).height(150);
4
+ vis = pv.Panel.new().width(200).height(150);
5
5
 
6
- vis.add(pv.Panel).data([1,2]).add(pv.Bar)
7
- .data([3,4])
6
+ bar= vis.add(pv.Panel).data(["a","b"]).add(pv.Bar)
7
+ .data([1,2])
8
8
  .width(20)
9
- .height(lambda {|d| d * 20})
9
+ .height(60)
10
10
  .bottom(0)
11
- .left(lambda {|d,t| t*60+self.index*30}).add(pv.Label).text(lambda {|d,t| "#{t}-#{d}"})
11
+ .left(lambda {|d,t| self.parent.index*60+self.index*30})
12
+
13
+
14
+ bar.anchor("bottom").add(pv.Label).text(lambda {|d,t| "#{t}-#{d}"})
15
+ bar.anchor("top").add(pv.Label).text(lambda {"#{self.parent.index}-#{index}"})
16
+
12
17
 
13
-
14
18
  vis.render()
15
19
  #puts vis.children_inspect
16
20
  puts vis.to_svg
@@ -17,6 +17,8 @@ require 'rubyvis/scale'
17
17
  require 'rubyvis/color/color'
18
18
  require 'rubyvis/color/colors'
19
19
 
20
+ require 'rubyvis/layout'
21
+
20
22
  require 'rubyvis/scene/svg_scene'
21
23
  require 'rubyvis/transform'
22
24
 
@@ -26,7 +28,7 @@ end
26
28
 
27
29
  module Rubyvis
28
30
  @document=nil
29
- VERSION = '0.1.3'
31
+ VERSION = '0.1.4'
30
32
  API_VERSION='3.3'
31
33
  Infinity=1.0 / 0 # You actually can do it! http://snipplr.com/view/2137/uses-for-infinity-in-ruby/
32
34
  # :section: basic methods
@@ -0,0 +1,25 @@
1
+ module Rubyvis
2
+ def self.Layout
3
+ Rubyvis::Layout
4
+ end
5
+ class Layout < Rubyvis::Panel
6
+ @properties=Mark.properties.dup
7
+ def self.attr_accessor_dsl(*attr)
8
+ attr.each do |sym|
9
+ if sym.is_a? Array
10
+ name,func=sym
11
+ else
12
+ name=sym
13
+ func=nil
14
+ end
15
+ @properties[name]=true
16
+ self.property_method(name,false, func, self)
17
+ define_method(name.to_s+"=") {|v|
18
+ self.send(name,v)
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ #require 'rubyvis/layout/stack'