Class: Charty::Backends::Bokeh
- Inherits:
-
Object
- Object
- Charty::Backends::Bokeh
- Defined in:
- lib/charty/backends/bokeh.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Bokeh
constructor
A new instance of Bokeh.
- #old_style_render(context, filename) ⇒ Object
- #old_style_save(plot, context, filename) ⇒ Object
- #plot(context) ⇒ Object
- #series=(series) ⇒ Object
Constructor Details
#initialize ⇒ Bokeh
Returns a new instance of Bokeh.
12 13 14 |
# File 'lib/charty/backends/bokeh.rb', line 12 def initialize @plot = PyCall.import_module('bokeh.plotting') end |
Class Method Details
.prepare ⇒ Object
7 8 9 |
# File 'lib/charty/backends/bokeh.rb', line 7 def prepare require 'pycall' end |
Instance Method Details
#old_style_render(context, filename) ⇒ Object
20 21 22 23 24 |
# File 'lib/charty/backends/bokeh.rb', line 20 def old_style_render(context, filename) plot = plot(context) save(plot, context, filename) PyCall.import_module('bokeh.io').show(plot) end |
#old_style_save(plot, context, filename) ⇒ Object
26 27 28 29 30 |
# File 'lib/charty/backends/bokeh.rb', line 26 def old_style_save(plot, context, filename) if filename PyCall.import_module('bokeh.io').save(plot, filename) end end |
#plot(context) ⇒ Object
32 33 34 35 36 37 38 39 40 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 |
# File 'lib/charty/backends/bokeh.rb', line 32 def plot(context) #TODO To implement boxplot, bublle, error_bar, hist. plot = @plot.figure(title: context&.title) plot.xaxis[0].axis_label = context&.xlabel plot.yaxis[0].axis_label = context&.ylabel case context.method when :bar context.series.each do |data| diffs = data.xs.to_a.each_cons(2).map {|n, m| (n - m).abs } width = diffs.min * 0.8 plot.(data.xs.to_a, width, data.ys.to_a) end when :barh context.series.each do |data| diffs = data.xs.to_a.each_cons(2).map {|n, m| (n - m).abs } height = diffs.min * 0.8 plot.(data.xs.to_a, height, data.ys.to_a) end when :boxplot raise NotImplementedError when :bubble raise NotImplementedError when :curve context.series.each do |data| plot.line(data.xs.to_a, data.ys.to_a) end when :scatter context.series.each do |data| plot.scatter(data.xs.to_a, data.ys.to_a) end when :error_bar raise NotImplementedError when :hist raise NotImplementedError end plot end |
#series=(series) ⇒ Object
16 17 18 |
# File 'lib/charty/backends/bokeh.rb', line 16 def series=(series) @series = series end |