Guest User

Untitled

a guest
Jan 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # Original test.rb. Incorrect plot.
  2.  
  3. require "rubyvis"
  4.  
  5. data = pv.range(0, 10, 0.1).map {|x|
  6. OpenStruct.new({:x=> x, :y=> Math.sin(x) + 2+rand()})
  7. }
  8.  
  9. #p data
  10. w = 400
  11. h = 200
  12. x = pv.Scale.linear(data, lambda {|d| d.x}).range(0, w)
  13. y = pv.Scale.linear(data, lambda {|d| d.y}).range(0, h)
  14.  
  15. #/* The root panel. */
  16. vis = pv.Panel.new().
  17. width(w).
  18. height(h).
  19. bottom(20).
  20. left(20).
  21. right(10).
  22. top(5)
  23.  
  24. vis.add(pv.Line).
  25. data(data).
  26. line_width(5).
  27. left(lambda {|d| x.scale(d.x)}).
  28. bottom(lambda {|d| y.scale(d.y)}).
  29. anchor("bottom").add(pv.Line).
  30. stroke_style('red').
  31. line_width(1)
  32.  
  33. vis
  34.  
  35. #
  36. # Next two lines are uncommented when running without continuous evaluation.
  37. # My app calls these after getting the Rubyvis::Panel (vis) back from eval.
  38. #
  39.  
  40. # vis.render()
  41. # vis.to_svg()
Add Comment
Please, Sign In to add comment