Class: Rubyvis::Image

Inherits:
Bar show all
Defined in:
lib/rubyvis/mark/image.rb

Instance Attribute Summary collapse

Attributes inherited from Mark

#_properties, #binds, #child_index, #parent, #proto, #root, #scale, #scene, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Bar

#width

Methods inherited from Mark

#add, #anchor, #area, attr_accessor_dsl, #bar, #build, #build_instance, #build_properties, #context, #context_apply, #context_clear, #cousin, #delete_index, #dot, #event, #execute, #first, #image, index, #index, index=, #index=, #index_defined?, #instance, #instances, #label, #last, #layout_partition, #layout_partition_fill, #layout_stack, #layout_treemap, #line, #margin, #mark_anchor, #mark_bind, #mark_build_implied, #mark_build_instance, #mark_build_properties, #mark_extend, mark_method, #panel, #properties, properties, property_method, #property_value, #render, #rule, scene, scene=, #sibling, stack, stack=, #wedge

Constructor Details

#initialize(opts = Hash.new) ⇒ Image

Returns a new instance of Image.



11
12
13
14
# File 'lib/rubyvis/mark/image.rb', line 11

def initialize(opts=Hash.new)
  super(opts)
  @_image=nil
end

Instance Attribute Details

#_imageObject

Returns the value of attribute _image.



10
11
12
# File 'lib/rubyvis/mark/image.rb', line 10

def _image
  @_image
end

Class Method Details

.defaultsObject

Default properties for images. By default, there is no stroke or fill style.



38
39
40
# File 'lib/rubyvis/mark/image.rb', line 38

def self.defaults
  Image.new.mark_extend(Bar.defaults).fill_style(nil)
end

Instance Method Details

#bindObject

Scan the proto chain for an image function.



74
75
76
77
78
79
80
81
# File 'lib/rubyvis/mark/image.rb', line 74

def bind
  mark_bind
  bind=self.binds
  mark=self
  begin
    binds.image = mark._image
  end while(!binds.image and (mark==mark.proto))
end

#build_implied(s) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rubyvis/mark/image.rb', line 84

def build_implied(s)
  mark_build_implied(s)
  return if !s.visible
  # Compute the implied image dimensions. */
  s.image_width = s.width   if s.image_width.nil?
  s.image_height = s.height if s.image_height.nil?
  # Compute the pixel values. */
  if (s.url.nil? and self.binds.image)
    raise "not implemented yet"
  end
end

#dynamic_image(f) ⇒ Object

@TODO: NOT IMPLEMENTED YET Specifies the dynamic image function. By default, no image function is specified and the url property is used to load a static image resource. If an image function is specified, it will be invoked for each pixel in the image, based on the related imageWidth and imageHeight properties.

<p>For example, given a two-dimensional array heatmap, containing numbers in the range [0, 1] in row-major order, a simple monochrome heatmap image can be specified as:

vis.add(pv.Image)
  .image_width(heatmap[0].length)
  .image_height(heatmap.length)
  .image(pv.ramp("white", "black").by(lambda {|x,y| heatmap[y][x]}))

For fastest performance, use an ordinal scale which caches the fixed color palette, or return an object literal with r, g, b and a attributes. A pv.Color or string can also be returned, though this typically results in slower performance.



63
64
65
66
67
68
69
70
# File 'lib/rubyvis/mark/image.rb', line 63

def dynamic_image(f)
  f,dummy=arguments
  @_image = lambda {|*args|
    c=f.js_apply(self,args)
    c.nil? ? pv.Color.transparent : (c.is_a?(String) ? Rubyvis.color(c) : c )
  }
  self
end

#typeObject



6
7
8
# File 'lib/rubyvis/mark/image.rb', line 6

def type
  "image"
end

#urlObject

:attr: image_height The height of the image in pixels. For static images, this property is computed implicitly from the loaded image resources. For dynamic images, this property can be used to specify the height of the pixel buffer; otherwise, the value is derived from the height property.



34
# File 'lib/rubyvis/mark/image.rb', line 34

attr_accessor_dsl :url, :image_width, :image_height