Class: AlGraph::YAxis

Inherits:
Axis show all
Defined in:
lib/al_graph.rb

Overview

Y軸クラス

Direct Known Subclasses

Y2Axis

Constant Summary

Constants inherited from GraphView

GraphView::ATTR_NAMES

Instance Attribute Summary

Attributes inherited from Axis

#at_interval_marks, #at_labels, #at_scale_line, #labels, #mode_label

Attributes inherited from GraphView

#data_series, #height, #width

Instance Method Summary collapse

Methods inherited from Axis

#add_grid, #clear_grid, #clear_interval_marks, #clear_labels, #clear_scale_line, #do_scaling, #logarithmic, #max, #min, #reverse, #set_interval, #set_labels, #set_max, #set_min

Constructor Details

#initialize(width, height) ⇒ YAxis

(Yxis) constructor

Parameters:

  • width (Integer)

  • height (Integer)

    高さ



1220
1221
1222
1223
1224
1225
1226
# File 'lib/al_graph.rb', line 1220

def initialize(width, height)
  super

  @scale_mode = :LINER
  @at_labels[:text_anchor] = 'end'
  @at_interval_marks[:grid] = true
end

Instance Method Details

#calc_pixcel_position(v) ⇒ Integer

(YAxis) 軸上のピクセル位置を計算する。

Parameters:

  • v (Numeric)

    実数

Returns:

  • (Integer)

    ピクセル位置

    引数が軸上にない場合、返り値も軸上にはないピクセル位置が返る。



1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
# File 'lib/al_graph.rb', line 1237

def calc_pixcel_position(v)
  case @scale_mode
  when :LINER
    y = (@height * (v - @scale_min) / @scale_max_min).to_i
  when :LOGARITHMIC
    y = (@height * Math.log10(v/@scale_min) / @scale_max_min).to_i
  else
    raise "Not support #{@scale_mode} mode."
  end
  return @flag_reverse ? y : @height - y
end