Class: Charty::Backends::Rubyplot
- Inherits:
-
Object
- Object
- Charty::Backends::Rubyplot
- Defined in:
- lib/charty/backends/rubyplot.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Rubyplot
constructor
A new instance of Rubyplot.
- #label(x, y) ⇒ Object
- #old_style_render(context, filename = "") ⇒ Object
- #plot(plot, context) ⇒ Object
- #render_layout(layout) ⇒ Object
- #series=(series) ⇒ Object
Constructor Details
#initialize ⇒ Rubyplot
Returns a new instance of Rubyplot.
14 15 16 |
# File 'lib/charty/backends/rubyplot.rb', line 14 def initialize @plot = ::Rubyplot end |
Class Method Details
.prepare ⇒ Object
9 10 11 |
# File 'lib/charty/backends/rubyplot.rb', line 9 def prepare require 'rubyplot' end |
Instance Method Details
#label(x, y) ⇒ Object
18 19 |
# File 'lib/charty/backends/rubyplot.rb', line 18 def label(x, y) end |
#old_style_render(context, filename = "") ⇒ Object
36 37 38 39 |
# File 'lib/charty/backends/rubyplot.rb', line 36 def old_style_render(context, filename="") FileUtils.mkdir_p(File.dirname(filename)) plot(@plot, context).write(filename) end |
#plot(plot, context) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/charty/backends/rubyplot.rb', line 41 def plot(plot, context) # case # when plot.respond_to?(:xlim) # plot.xlim(context.range_x.begin, context.range_x.end) # plot.ylim(context.range_y.begin, context.range_y.end) # when plot.respond_to?(:set_xlim) # plot.set_xlim(context.range_x.begin, context.range_x.end) # plot.set_ylim(context.range_y.begin, context.range_y.end) # end figure = ::Rubyplot::Figure.new axes = figure.add_subplot 0,0 axes.title = context.title if context.title axes.x_title = context.xlabel if context.xlabel axes.y_title = context.ylabel if context.ylabel case context.method when :bar context.series.each do |data| axes. do |p| p.data(data.xs.to_a) p.label = data.label end end figure when :barh raise NotImplementedError when :box_plot raise NotImplementedError when :bubble context.series.each do |data| axes.bubble! do |p| p.data(data.xs.to_a, data.ys.to_a, data.zs.to_a) p.label = data.label if data.label end end figure when :curve context.series.each do |data| axes.line! do |p| p.data(data.xs.to_a, data.ys.to_a) p.label = data.label if data.label end end figure when :scatter context.series.each do |data| axes.scatter! do |p| p.data(data.xs.to_a, data.ys.to_a) p.label = data.label if data.label end end figure when :error_bar # refs. https://github.com/SciRuby/rubyplot/issues/26 raise NotImplementedError when :hist raise NotImplementedError end end |
#render_layout(layout) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/charty/backends/rubyplot.rb', line 25 def render_layout(layout) (_fig, axes) = *@plot.subplots(nrows: layout.num_rows, ncols: layout.num_cols) layout.rows.each_with_index do |row, y| row.each_with_index do |cel, x| plot = layout.num_rows > 1 ? axes[y][x] : axes[x] plot(plot, cel) end end @plot.show end |
#series=(series) ⇒ Object
21 22 23 |
# File 'lib/charty/backends/rubyplot.rb', line 21 def series=(series) @series = series end |