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

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

#heightNumeric

Returns the height of the plotp.

Returns:

  • (Numeric)

    the height of the plotp



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

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

#widthNumeric

Returns the width of the plot.

Returns:

  • (Numeric)

    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

Examples:

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

Parameters:

  • type (Symbol)

    the type of diagram to add

  • *data (Array<Array>)

    array from which diagram is created



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)

Parameters:

  • DataFrame (DataFrame)

    from which diagram is created

  • type (Symbol)

    the type of diagram to add

  • *labels (Array<Symbol>)

    column labels for x, y or some other dimension



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>

Returns names of dataframe used by diagrams belog to this plot.

Returns:

  • (Array<String>)

    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

#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