Sha256: 574ab4efdad14e0f377e4d85e2d8be42d6a682ff2ed1d0349a44322869e9feae

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# = Area Interpolation
# This example show the 5 types of interpolation available for areas.
$:.unshift(File.dirname(__FILE__)+"/../lib")
require 'rubyvis'

data = pv.range(0, 10, 0.5).map {|x| 
  OpenStruct.new({:x=> x, :y=> Math.sin(x) + 2+rand()*0.3})
}

p_w=200
p_h=150
#p data
w = 20+p_w*2
h = 20+p_h*3

x = pv.Scale.linear(data, lambda {|d| d.x}).range(0, p_w-30)
y = pv.Scale.linear(data, lambda {|d| d.y}).range(0, p_h-20);
interpolations=["linear","step-before","step-after", "basis", "cardinal"]

vis = Rubyvis::Panel.new do |pan|
  pan.width w 
  pan.height h 
  pan.bottom 20 
  pan.left 20 
  pan.right 10 
  pan.top 5 

  interpolations.each_with_index do |inter,i|
    n=i%2
    m=(i/2).floor
    pan.panel do
      left(n*(p_w+10))
      top(m*(p_h+10))
      width p_w
      height p_h
      label(:anchor=>'top') do
        text(inter)
      end
      # uses 'a' as reference inside block
      # to use data method with data variable
      area do |a| 
        a.data data
        a.left {|d| x.scale(d.x)}
        a.height {|d| y.scale(d.y)}
        a.bottom 1
        a.interpolate inter
      end
    end
  end
end  
     

vis.render();


puts vis.to_svg

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubyvis-0.2.0 examples/area_interpolation.rb