Class: Nyaplot::Plot3D
- Inherits:
-
Object
- Object
- Nyaplot::Plot3D
- Includes:
- Jsonizable
- Defined in:
- lib/nyaplot3d/plot3d.rb
Overview
Plot Object for 3D diagrams
Instance Attribute Summary collapse
-
#height ⇒ Numeric
The height of the plotp.
-
#width ⇒ Numeric
The width of the plot.
Instance Method Summary collapse
-
#add(type, *data) ⇒ Object
Add diagram with Array.
-
#add_with_df(df, type, *labels) ⇒ Object
Add diagram with DataFrame.
-
#configure(&block) ⇒ Object
Shortcut method to configure plot.
-
#df_list ⇒ Array<String>
Names of dataframe used by diagrams belog to this plot.
-
#export_html(path = nil) ⇒ Object
export html file.
-
#initialize ⇒ Plot3D
constructor
A new instance of Plot3D.
-
#show ⇒ Object
Show plot on IRuby notebook.
-
#to_iruby ⇒ Object
Show plot automatically on IRuby notebook.
Methods included from Jsonizable
#before_to_json, #get_property, included, #init_properties, #set_property, #to_json
Constructor Details
#initialize ⇒ Plot3D
Returns a new instance of Plot3D.
13 14 15 16 17 18 |
# File 'lib/nyaplot3d/plot3d.rb', line 13 def initialize init_properties set_property(:diagrams, []) set_property(:options, {}) set_property(:extension, 'Elegans') end |
Instance Attribute Details
#height ⇒ Numeric
Returns the height of the plotp.
11 |
# File 'lib/nyaplot3d/plot3d.rb', line 11 define_group_properties(:options, [:width, :height]) |
#width ⇒ Numeric
Returns the width of the plot.
11 |
# File 'lib/nyaplot3d/plot3d.rb', line 11 define_group_properties(:options, [:width, :height]) |
Instance Method Details
#add(type, *data) ⇒ Object
Add diagram with Array
25 26 27 28 |
# 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) ⇒ Object
Add diagram with DataFrame
37 38 39 40 41 42 |
# 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) ⇒ Object
Shortcut method to configure plot
74 75 76 |
# File 'lib/nyaplot3d/plot3d.rb', line 74 def configure(&block) self.instance_eval(&block) if block_given? end |
#df_list ⇒ Array<String>
Returns names of dataframe used by diagrams belog to this plot.
62 63 64 65 |
# 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) ⇒ Object
export html file
55 56 57 58 59 |
# 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 |