class Nyaplot::Plot3D
Plot
Object for 3D diagrams
Public Class Methods
new()
click to toggle source
# File lib/nyaplot3d/plot3d.rb, line 13 def initialize init_properties set_property(:diagrams, []) set_property(:options, {}) set_property(:extension, 'Elegans') end
Public Instance Methods
add(type, *data)
click to toggle source
Add diagram with Array
@param [Symbol] type the type of diagram to add @param [Array<Array>] *data array from which diagram is created @example
plot.add(:surface, [0,1,2], [0,1,2], [0,1,2])
# File lib/nyaplot3d/plot3d.rb, line 25 def add(type, *data) df = DataFrame.new({x: data[0], y: data[1], z: data[2]}) return add_with_df(df, type, :x, :y, :z) end
add_with_df(df, type, *labels)
click to toggle source
Add diagram with DataFrame
@param [DataFrame] DataFrame
from which diagram is created @param [Symbol] type the type of diagram to add @param [Array<Symbol>] *labels column labels for x, y or some other dimension @example
df = Nyaplot::DataFrame.new({x: [0,1,2], y: [0,1,2], z: [0,1,2]}) plot.add(df, :surface, :x, :y, :z)
# File lib/nyaplot3d/plot3d.rb, line 37 def add_with_df(df, type, *labels) diagram = Diagram3D.new(df, type, labels) diagrams = get_property(:diagrams) diagrams.push(diagram) return diagram end
configure(&block)
click to toggle source
Shortcut method to configure plot @example
plot = Nyaplot::Plot3D.new plot.configure do width(700) height(700) end
# File lib/nyaplot3d/plot3d.rb, line 74 def configure(&block) self.instance_eval(&block) if block_given? end
df_list()
click to toggle source
@return [Array<String>] names of dataframe used by diagrams belog to this plot
# File lib/nyaplot3d/plot3d.rb, line 62 def df_list diagrams = get_property(:diagrams) return diagrams.map{|d| next d.df_name} end
export_html(path=nil)
click to toggle source
export html file
# File lib/nyaplot3d/plot3d.rb, line 55 def export_html(path=nil) require 'securerandom' path = "./plot-" + SecureRandom.uuid().to_s + ".html" if path.nil? Frame.new.tap {|f| f.add(self) }.export_html(path) end
show()
click to toggle source
Show plot on IRuby notebook
# File lib/nyaplot3d/plot3d.rb, line 45 def show Frame.new.tap {|f| f.add(self) }.show end
to_iruby()
click to toggle source
Show plot automatically on IRuby notebook
# File lib/nyaplot3d/plot3d.rb, line 50 def to_iruby Frame.new.tap {|f| f.add(self) }.to_iruby end