Class: Nyaplot::Plot3D

Inherits:
Object
  • Object
show all
Includes:
Jsonizable
Defined in:
lib/nyaplot3d/plot3d.rb

Overview

Plot Object for 3D diagrams

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Jsonizable

#before_to_json, #get_property, included, #init_properties, #set_property, #to_json

Constructor Details

#initializePlot3D



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

#heightNumeric



11
# File 'lib/nyaplot3d/plot3d.rb', line 11

define_group_properties(:options, [:width, :height])

#widthNumeric



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

Examples:

plot.add(:surface, [0,1,2], [0,1,2], [0,1,2])


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

Examples:

df = Nyaplot::DataFrame.new({x: [0,1,2], y: [0,1,2], z: [0,1,2]})
plot.add(df, :surface, :x, :y, :z)


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

Examples:

plot = Nyaplot::Plot3D.new
plot.configure do
  width(700)
  height(700)
end


74
75
76
# File 'lib/nyaplot3d/plot3d.rb', line 74

def configure(&block)
  self.instance_eval(&block) if block_given?
end

#df_listArray<String>



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

#showObject

Show plot on IRuby notebook



45
46
47
# File 'lib/nyaplot3d/plot3d.rb', line 45

def show
  Frame.new.tap {|f| f.add(self) }.show
end

#to_irubyObject

Show plot automatically on IRuby notebook



50
51
52
# File 'lib/nyaplot3d/plot3d.rb', line 50

def to_iruby
  Frame.new.tap {|f| f.add(self) }.to_iruby
end