rubyvis 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.7 / 2010-10-31
2
+
3
+ * Added image support
4
+
1
5
  === 0.1.6 / 2010-10-30
2
6
 
3
7
  * Improved documentation for examples. Added description from protovis site on the one borrowed from it and added commentary on new ones.
data/Manifest.txt CHANGED
@@ -13,7 +13,10 @@ 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/fixtures/tipsy.gif
16
17
  examples/grouped_charts.rb
18
+ examples/image.rb
19
+ examples/image.svg
17
20
  examples/line.rb
18
21
  examples/line_and_step.rb
19
22
  examples/nested_grid.rb
@@ -38,6 +41,7 @@ lib/rubyvis/mark/anchor.rb
38
41
  lib/rubyvis/mark/area.rb
39
42
  lib/rubyvis/mark/bar.rb
40
43
  lib/rubyvis/mark/dot.rb
44
+ lib/rubyvis/mark/image.rb
41
45
  lib/rubyvis/mark/label.rb
42
46
  lib/rubyvis/mark/line.rb
43
47
  lib/rubyvis/mark/panel.rb
@@ -53,6 +57,7 @@ lib/rubyvis/scale/quantitative.rb
53
57
  lib/rubyvis/scene/svg_area.rb
54
58
  lib/rubyvis/scene/svg_bar.rb
55
59
  lib/rubyvis/scene/svg_dot.rb
60
+ lib/rubyvis/scene/svg_image.rb
56
61
  lib/rubyvis/scene/svg_label.rb
57
62
  lib/rubyvis/scene/svg_line.rb
58
63
  lib/rubyvis/scene/svg_panel.rb
Binary file
data/examples/image.rb ADDED
@@ -0,0 +1,20 @@
1
+ # = Image
2
+ # This example shows how to include an image
3
+ $:.unshift(File.dirname(__FILE__)+"/../lib")
4
+ require 'rubyvis'
5
+
6
+ img_url="fixtures/tipsy.gif"
7
+
8
+ vis = pv.Panel.new().width(200).height(200);
9
+
10
+ dot=vis.add(pv.Image)
11
+ .data([1,2,3,4,5,6])
12
+ .bottom(lambda {|d| d*30})
13
+ .left(lambda {|d| d*30} )
14
+ .width(9)
15
+ .height(9)
16
+ .url(img_url)
17
+
18
+ vis.render()
19
+ #puts vis.children_inspect
20
+ puts vis.to_svg
@@ -0,0 +1 @@
1
+ <svg fill='none' font-family='sans-serif' font-size='10px' height='200.0' stroke='none' stroke-width='1.5' width='200.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns='http://www.w3.org/2000/svg'><g transform='translate(0.0,0.0)'><image height='9' xlink:href='fixtures/tipsy.gif' preserveAspectRatio='none' width='9' x='20' y='161'/><image height='9' xlink:href='fixtures/tipsy.gif' preserveAspectRatio='none' width='9' x='60' y='131'/><image height='9' xlink:href='fixtures/tipsy.gif' preserveAspectRatio='none' width='9' x='100' y='101'/><image height='9' xlink:href='fixtures/tipsy.gif' preserveAspectRatio='none' width='9' x='140' y='71'/><image height='9' xlink:href='fixtures/tipsy.gif' preserveAspectRatio='none' width='9' x='180' y='41'/><image height='9' xlink:href='fixtures/tipsy.gif' preserveAspectRatio='none' width='9' x='220' y='11'/></g></svg>
data/lib/rubyvis.rb CHANGED
@@ -25,7 +25,7 @@ require 'rubyvis/transform'
25
25
  module Rubyvis
26
26
  @document=nil
27
27
  # Rubyvis version
28
- VERSION = '0.1.6'
28
+ VERSION = '0.1.7'
29
29
  # Protovis API on which current Rubyvis is based
30
30
  API_VERSION='3.3'
31
31
  # You actually can do it! http://snipplr.com/view/2137/uses-for-infinity-in-ruby/
data/lib/rubyvis/mark.rb CHANGED
@@ -961,6 +961,7 @@ end
961
961
 
962
962
  require 'rubyvis/mark/anchor'
963
963
  require 'rubyvis/mark/bar'
964
+ require 'rubyvis/mark/image'
964
965
  require 'rubyvis/mark/panel'
965
966
  require 'rubyvis/mark/area'
966
967
  require 'rubyvis/mark/line'
@@ -0,0 +1,96 @@
1
+ module Rubyvis
2
+ def self.Image
3
+ Rubyvis::Image
4
+ end
5
+ class Image < Bar
6
+ def type
7
+ "image"
8
+ end
9
+ @properties=Bar.properties.dup
10
+ attr_accessor :_image
11
+ def initialize(opts=Hash.new)
12
+ super(opts)
13
+ @_image=nil
14
+ end
15
+ ##
16
+ # :attr: url
17
+ # The URL of the image to display. The set of supported image types is
18
+ # browser-dependent; PNG and JPEG are recommended.
19
+
20
+ ##
21
+ # :attr: image_width
22
+ # The width of the image in pixels. For static images, this property is
23
+ # computed implicitly from the loaded image resources. For dynamic images, this
24
+ # property can be used to specify the width of the pixel buffer; otherwise, the
25
+ # value is derived from the <tt>width</tt> property.
26
+
27
+ ##
28
+ # :attr: image_height
29
+ # The height of the image in pixels. For static images, this property is
30
+ # computed implicitly from the loaded image resources. For dynamic images, this
31
+ # property can be used to specify the height of the pixel buffer; otherwise, the
32
+ # value is derived from the <tt>height</tt> property.
33
+
34
+ attr_accessor_dsl :url, :image_width, :image_height
35
+
36
+
37
+ # Default properties for images. By default, there is no stroke or fill style.
38
+ def self.defaults
39
+ Image.new.extend(Bar.defaults).fill_style(nil)
40
+ end
41
+
42
+ # @TODO: NOT IMPLEMENTED YET
43
+ # Specifies the dynamic image function. By default, no image function is
44
+ # specified and the <tt>url</tt> property is used to load a static image
45
+ # resource. If an image function is specified, it will be invoked for each
46
+ # pixel in the image, based on the related <tt>imageWidth</tt> and
47
+ # <tt>imageHeight</tt> properties.
48
+ #
49
+ # <p>For example, given a two-dimensional array <tt>heatmap</tt>, containing
50
+ # numbers in the range [0, 1] in row-major order, a simple monochrome heatmap
51
+ # image can be specified as:
52
+ #
53
+ # vis.add(pv.Image)
54
+ # .image_width(heatmap[0].length)
55
+ # .image_height(heatmap.length)
56
+ # .image(pv.ramp("white", "black").by(lambda {|x,y| heatmap[y][x]}))
57
+ #
58
+ # For fastest performance, use an ordinal scale which caches the fixed color
59
+ # palette, or return an object literal with <tt>r</tt>, <tt>g</tt>, <tt>b</tt>
60
+ # and <tt>a</tt> attributes. A {@link pv.Color} or string can also be returned,
61
+ # though this typically results in slower performance.
62
+
63
+ def image(f)
64
+ f,dummy=arguments
65
+ @_image = lambda {|*args|
66
+ c=f.js_apply(self,args)
67
+ c.nil? ? pv.Color.transparent : (c.is_a?(String) ? Rubyvis.color(c) : c )
68
+ }
69
+ self
70
+ end
71
+
72
+
73
+ # Scan the proto chain for an image function.
74
+ def bind
75
+ mark_bind
76
+ bind=self.binds
77
+ mark=self
78
+ begin
79
+ binds.image = mark._image
80
+ end while(!binds.image and (mark==mark.proto))
81
+ end
82
+
83
+
84
+ def build_implied(s)
85
+ mark_build_implied(s)
86
+ return if !s.visible
87
+ # Compute the implied image dimensions. */
88
+ s.image_width = s.width if s.image_width.nil?
89
+ s.image_height = s.height if s.image_height.nil?
90
+ # Compute the pixel values. */
91
+ if (s.url.nil? and self.binds.image)
92
+ raise "not implemented yet"
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,30 @@
1
+ module Rubyvis
2
+ module SvgScene
3
+ def self.image(scenes)
4
+ e=scenes._g.elements[1]
5
+ scenes.each_with_index do |s,i|
6
+ next unless s.visible
7
+ e=self.fill(e,scenes,i)
8
+ if s.image
9
+ raise "Not implemented yet"
10
+ else
11
+ e = self.expect(e, "image", {
12
+ "preserveAspectRatio"=> "none",
13
+ "cursor"=> s.cursor,
14
+ "x"=> s.left,
15
+ "y"=> s.top,
16
+ "width"=> s.width,
17
+ "height"=> s.height
18
+ })
19
+
20
+ e.add_attribute("xlink:href", s.url);
21
+ end
22
+ e = self.append(e, scenes, i);
23
+
24
+ #/* stroke */
25
+ e = self.stroke(e, scenes, i);
26
+ end
27
+ e
28
+ end
29
+ end
30
+ end
@@ -6,6 +6,7 @@ require 'rubyvis/scene/svg_line'
6
6
  require 'rubyvis/scene/svg_dot'
7
7
  require 'rubyvis/scene/svg_area'
8
8
  require 'rubyvis/scene/svg_wedge'
9
+ require 'rubyvis/scene/svg_image'
9
10
 
10
11
  class REXML::Element
11
12
  attr_accessor :_scene
@@ -77,7 +78,7 @@ module Rubyvis
77
78
  if type=='svg'
78
79
  el.add_namespace(self.svg)
79
80
  #el.add_namespace("xmlns:xmlns", self.xmlns)
80
- #el.add_namespace("xlink", self.xlink)
81
+ el.add_namespace("xmlns:xlink", self.xlink)
81
82
  end
82
83
  el
83
84
  end
@@ -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, :layers, :orient, :offset, :order
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,:url, :image_width, :image_height, :image
9
9
 
10
10
  def []=(v,i)
11
11
  if v.is_a? Numeric
data/web/Rakefile CHANGED
@@ -15,7 +15,7 @@ task :build_site do
15
15
  ruby "build_site.rb"
16
16
  end
17
17
 
18
- task :default=>["index.html"]+EXAMPLES_BASE.map {|v| "examples/#{v}.html"}
18
+ task :default=>["index.html","../lib/rubyvis.rb"]+EXAMPLES_BASE.map {|v| "examples/#{v}.html"}
19
19
 
20
20
 
21
21
  file "index.html"=>["index.haml", :build_site]+EXAMPLES_BASE.map {|v| "examples/#{v}.png"}
data/web/examples.haml CHANGED
@@ -24,3 +24,14 @@
24
24
  %embed.svg{:src=>svg_file,:width=>"500", :height=>"300"}
25
25
  %object.svg{:data=>svg_file, :type=>"image/svg+xml"}
26
26
  .source=find_and_preserve(source)
27
+ :javascript
28
+ var _gaq = _gaq || [];
29
+ _gaq.push(['_setAccount', 'UA-5764936-8']);
30
+ _gaq.push(['_trackPageview']);
31
+
32
+ (function() {
33
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
34
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
35
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
36
+ })();
37
+
data/web/index.haml CHANGED
@@ -36,6 +36,7 @@
36
36
  bottom(0).
37
37
  left(lambda {self.index * 25})
38
38
  vis.render()
39
+ puts vis.to_svg # Output final SVG
39
40
  #svg_code
40
41
  %h3 SVG
41
42
  %pre
@@ -95,3 +96,12 @@
95
96
  API documentation on
96
97
  %a{:href=>'http://rubyvis.rubyforge.org/rubyvis/'}
97
98
  http://rubyvis.rubyforge.org/rubyvis/
99
+ :javascript
100
+ var _gaq = _gaq || [];
101
+ _gaq.push(['_setAccount', 'UA-5764936-8']);
102
+ _gaq.push(['_trackPageview']);
103
+ (function() {
104
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
105
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
106
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
107
+ })();
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- version: 0.1.6
8
+ - 7
9
+ version: 0.1.7
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-30 00:00:00 -03:00
38
+ date: 2010-10-31 00:00:00 -03:00
39
39
  default_executable:
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
@@ -93,7 +93,10 @@ files:
93
93
  - examples/crimea/crimea_line.rb
94
94
  - examples/dot.rb
95
95
  - examples/first.rb
96
+ - examples/fixtures/tipsy.gif
96
97
  - examples/grouped_charts.rb
98
+ - examples/image.rb
99
+ - examples/image.svg
97
100
  - examples/line.rb
98
101
  - examples/line_and_step.rb
99
102
  - examples/nested_grid.rb
@@ -118,6 +121,7 @@ files:
118
121
  - lib/rubyvis/mark/area.rb
119
122
  - lib/rubyvis/mark/bar.rb
120
123
  - lib/rubyvis/mark/dot.rb
124
+ - lib/rubyvis/mark/image.rb
121
125
  - lib/rubyvis/mark/label.rb
122
126
  - lib/rubyvis/mark/line.rb
123
127
  - lib/rubyvis/mark/panel.rb
@@ -133,6 +137,7 @@ files:
133
137
  - lib/rubyvis/scene/svg_area.rb
134
138
  - lib/rubyvis/scene/svg_bar.rb
135
139
  - lib/rubyvis/scene/svg_dot.rb
140
+ - lib/rubyvis/scene/svg_image.rb
136
141
  - lib/rubyvis/scene/svg_label.rb
137
142
  - lib/rubyvis/scene/svg_line.rb
138
143
  - lib/rubyvis/scene/svg_panel.rb
metadata.gz.sig CHANGED
Binary file