Method: Rubyvis::Image#dynamic_image

Defined in:
lib/rubyvis/mark/image.rb

#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