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


64
65
66
# File 'lib/nyaplot3d/plot3d.rb', line 64

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



52
53
54
55
# File 'lib/nyaplot3d/plot3d.rb', line 52

def df_list
  diagrams = get_property(:diagrams)
  return diagrams.map{|d| next d.df_name}
end

#showObject

Show plot on IRuby notebook



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

def show
  frame = Frame.new
  frame.add(self)
  frame.show
end