Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Original test.rb. Incorrect plot.
- require "rubyvis"
- data = pv.range(0, 10, 0.1).map {|x|
- OpenStruct.new({:x=> x, :y=> Math.sin(x) + 2+rand()})
- }
- #p data
- w = 400
- h = 200
- x = pv.Scale.linear(data, lambda {|d| d.x}).range(0, w)
- y = pv.Scale.linear(data, lambda {|d| d.y}).range(0, h)
- #/* The root panel. */
- vis = pv.Panel.new().
- width(w).
- height(h).
- bottom(20).
- left(20).
- right(10).
- top(5)
- vis.add(pv.Line).
- data(data).
- line_width(5).
- left(lambda {|d| x.scale(d.x)}).
- bottom(lambda {|d| y.scale(d.y)}).
- anchor("bottom").add(pv.Line).
- stroke_style('red').
- line_width(1)
- vis
- #
- # Next two lines are uncommented when running without continuous evaluation.
- # My app calls these after getting the Rubyvis::Panel (vis) back from eval.
- #
- # vis.render()
- # vis.to_svg()
Add Comment
Please, Sign In to add comment