Class: AlGraphXY::GraphXY

Inherits:
AlGraph::Graph show all
Defined in:
lib/al_graph_xy.rb

Overview

XYグラフ用クラス

Direct Known Subclasses

AlGraphScatter::GraphScatter

Constant Summary

Constants inherited from AlGraph::Graph

AlGraph::Graph::SHAPE_LIST

Constants inherited from AlGraph::GraphBase

AlGraph::GraphBase::COLOR_LIST

Constants inherited from AlGraph::GraphView

AlGraph::GraphView::ATTR_NAMES

Instance Attribute Summary

Attributes inherited from AlGraph::Graph

#at_xaxis_title, #at_xaxis_unit, #at_y2axis_unit, #at_yaxis_title, #at_yaxis_unit, #bar_plot, #line_plot, #shape_list, #x_axis, #y2_axis, #y_axis

Attributes inherited from AlGraph::GraphBase

#at_graph_area, #at_legend, #at_main_title, #at_plot_area, #color_list, #output

Attributes inherited from AlGraph::GraphView

#data_series, #height, #width

Instance Method Summary collapse

Methods inherited from AlGraph::Graph

#add_data_bar, #add_data_line, #add_data_line_y2, #add_xaxis_title, #add_xaxis_unit, #add_y2axis_unit, #add_yaxis_title, #add_yaxis_unit, #draw, #set_margin

Methods inherited from AlGraph::GraphBase

#add_aux_tag, #add_legend, #add_main_title, #add_text, #draw_buffer, #set_margin, #set_mode

Constructor Details

#initialize(width = 320, height = 240) ⇒ GraphXY

(GraphXY) constructor

Parameters:

  • width (Integer) (defaults to: 320)

  • height (Integer) (defaults to: 240)

    高さ



34
35
36
37
38
# File 'lib/al_graph_xy.rb', line 34

def initialize(width = 320, height = 240)
  super

  @x_axis = XAxisReal.new(@at_plot_area[:width], @at_plot_area[:height])
end

Instance Method Details

#add_data(data1, data2, legend = nil) ⇒ ContainerXY

(GraphXY) データ追加

Parameters:

  • data1 (Array<Numeric>)

    データの配列 X軸

  • data2 (Array<Numeric>)

    データの配列 Y軸

  • legend (String) (defaults to: nil)

    データの名前(凡例)

Returns:

  • (ContainerXY)

    データコンテナオブジェクト



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/al_graph_xy.rb', line 49

def add_data(data1, data2, legend = nil)
  add_legend() if legend
  @line_plot = AlGraph::LinePlot.new(@width, @height) if ! @line_plot

  data_obj = ContainerXY.new(data1, data2, legend)
  data_obj.x_axis = @x_axis
  data_obj.y_axis = @y_axis
  data_obj.plot = @line_plot
  data_obj.at_marker[:shape] = @shape_list[ @data_series.size % @shape_list.size ]
  data_obj.at_marker[:fill] = @color_list[ @data_series.size % @color_list.size ]
  data_obj.at_plot_line[:stroke] = data_obj.at_marker[:fill]

  add_data_series(data_obj)
  @line_plot.add_data_series(data_obj)
  @x_axis.add_data_series(data_obj)
  @y_axis.add_data_series(data_obj)

  return data_obj
end

#add_data_pair(data, legend = nil) ⇒ ContainerXY

(GraphXY) データペア追加

[[x1,y1],…] もしくは [x1,y1,x2,y2…] の型式でデータを与える

Parameters:

  • data (Array<Array<Numeric,Numeric>>, Array<Numeric>)

    データの配列

  • legend (String) (defaults to: nil)

    データの名前(凡例)

Returns:

  • (ContainerXY)

    データコンテナオブジェクト



79
80
81
82
83
84
85
86
87
88
# File 'lib/al_graph_xy.rb', line 79

def add_data_pair(data, legend = nil)
  data1 = []
  data2 = []
  data.flatten.each_slice(2) {|d1, d2|
    data1 << d1
    data2 << d2
  }

  return add_data(data1, data2, legend)
end