Class: Nyaplot::CircularPlot

Inherits:
Plot
  • Object
show all
Includes:
Jsonizable
Defined in:
lib/bionya/plot.rb

Instance Attribute Summary collapse

Attributes inherited from Plot

#bg_color, #grid_color, #height, #legend, #legend_options, #legend_width, #margin, #rotate_x_label, #rotate_y_label, #width, #x_label, #xrange, #y_label, #yrange, #zoom

Instance Method Summary collapse

Methods included from Jsonizable

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

Methods inherited from Plot

#add_with_df, #configure, #df_list, #export_html, #show, #to_iruby

Constructor Details

#initialize(df, group_label, nested_label) ⇒ CircularPlot

Returns a new instance of CircularPlot.

Parameters:

  • df (DataFrame)
  • group_label (Symbol)

    The column which contains names of groups

  • nested_label (Symbol)

    The column which contains dataframe



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bionya/plot.rb', line 27

def initialize(df, group_label, nested_label)
  super()
  @df = df
  @inner_num = 0
  @outer_num = 1
  @nested_label = nested_label

  set_property(:axis_extra_options, {})
  group_by(group_label)
  color(['#253494'])
  extension('Bionya')
end

Instance Attribute Details

#chordBoolean

Returns boolean to decide whether chord is added to the circular plot.

Returns:

  • (Boolean)

    boolean to decide whether chord is added to the circular plot



22
# File 'lib/bionya/plot.rb', line 22

define_group_properties(:axis_extra_options, [:df_id, :inner_radius, :outer_radius, :group_by, :axis, :chord, :matrix, :inner_num, :outer_num, :color, :text_color, :text_size, :fill_by, :padding])

#colorArray<String>

Returns array of colors.

Returns:

  • (Array<String>)

    array of colors



22
# File 'lib/bionya/plot.rb', line 22

define_group_properties(:axis_extra_options, [:df_id, :inner_radius, :outer_radius, :group_by, :axis, :chord, :matrix, :inner_num, :outer_num, :color, :text_color, :text_size, :fill_by, :padding])

#fill_bySymbol

Returns the name of column that decides what colors to be filled in.

Returns:

  • (Symbol)

    the name of column that decides what colors to be filled in



22
# File 'lib/bionya/plot.rb', line 22

define_group_properties(:axis_extra_options, [:df_id, :inner_radius, :outer_radius, :group_by, :axis, :chord, :matrix, :inner_num, :outer_num, :color, :text_color, :text_size, :fill_by, :padding])

#inner_radiusNumeric

Returns the inner radius of circle.

Returns:

  • (Numeric)

    the inner radius of circle



22
# File 'lib/bionya/plot.rb', line 22

define_group_properties(:axis_extra_options, [:df_id, :inner_radius, :outer_radius, :group_by, :axis, :chord, :matrix, :inner_num, :outer_num, :color, :text_color, :text_size, :fill_by, :padding])

#outer_radiusNumeric

Returns the outer radius of circle.

Returns:

  • (Numeric)

    the outer radius of circle



22
# File 'lib/bionya/plot.rb', line 22

define_group_properties(:axis_extra_options, [:df_id, :inner_radius, :outer_radius, :group_by, :axis, :chord, :matrix, :inner_num, :outer_num, :color, :text_color, :text_size, :fill_by, :padding])

#paddingNumeric

Returns padding between two group arcs.

Returns:

  • (Numeric)

    padding between two group arcs



22
# File 'lib/bionya/plot.rb', line 22

define_group_properties(:axis_extra_options, [:df_id, :inner_radius, :outer_radius, :group_by, :axis, :chord, :matrix, :inner_num, :outer_num, :color, :text_color, :text_size, :fill_by, :padding])

#text_colorString

Returns the color of text.

Returns:

  • (String)

    the color of text



22
# File 'lib/bionya/plot.rb', line 22

define_group_properties(:axis_extra_options, [:df_id, :inner_radius, :outer_radius, :group_by, :axis, :chord, :matrix, :inner_num, :outer_num, :color, :text_color, :text_size, :fill_by, :padding])

#text_sizeNumeric

Returns the size of text of groups.

Returns:

  • (Numeric)

    the size of text of groups



22
# File 'lib/bionya/plot.rb', line 22

define_group_properties(:axis_extra_options, [:df_id, :inner_radius, :outer_radius, :group_by, :axis, :chord, :matrix, :inner_num, :outer_num, :color, :text_color, :text_size, :fill_by, :padding])

Instance Method Details

#add(layer, type, *labels) ⇒ Diagram

Add diagram to the plot

Parameters:

  • layer (Numeric)

    The number of layer where the plot is placed (0 is the grouped arc, 1, 2, … are the outside of circle, -1, -2, .. is the inside of circle)

  • type (Symbol)

    The type of plot to add

  • labels (Array<Symbol>)

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bionya/plot.rb', line 63

def add(layer, type, *labels)
  if(layer>0)
    @outer_num += 1
  elsif
    @inner_num += 1
  end

  diagram = Diagram.new(@df, type, labels.push(@nested_label))
  diagram.layer(layer)
  @axis = diagram.x
  self.diagrams.push(diagram)
  return diagram
end

#add_chord(matrix) ⇒ Object

Add chord to the plot

Parameters:

  • matrix (Array<Array>)

See Also:



43
44
45
# File 'lib/bionya/plot.rb', line 43

def add_chord(matrix)
  @matrix = matrix
end

#add_connector_with_df(df, from, to) ⇒ Diagram

Add connector to the plot

Parameters:

  • df (DataFrame)
  • from (Symbol)

    the column label

  • to (Symbol)

    the column label

Returns:



52
53
54
55
56
# File 'lib/bionya/plot.rb', line 52

def add_connector_with_df(df, from, to)
  diagram = Diagram.new(df, :connector, [from, to])
  self.diagrams.push(diagram)
  return diagram
end

#before_to_jsonObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bionya/plot.rb', line 77

def before_to_json
  zoom(true)
  width(800) if width.nil?
  height(800) if height.nil?

  inner_num(@inner_num)
  outer_num(@outer_num)
  df_id(@df.name)
  axis(@axis)

  self.options[:axis_extra_options] = axis_extra_options
end