Class: AlGraph::XAxis

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

Overview

X軸クラス

Direct Known Subclasses

AlGraphXY::XAxisReal

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

Constructor Details

#initialize(width, height) ⇒ XAxis

(XAxis) constructor

Parameters:

  • width (Integer)

  • height (Integer)

    高さ



1022
1023
1024
1025
1026
1027
# File 'lib/al_graph.rb', line 1022

def initialize(width, height)
  super

  @scale_mode = :ORDERED_LEFT
  @at_interval_marks[:grid] = false
end

Instance Method Details

#calc_pixcel_position(v) ⇒ Integer

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

Parameters:

  • v (Numeric)

    実数

Returns:

  • (Integer)

    ピクセル位置

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



1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
# File 'lib/al_graph.rb', line 1072

def calc_pixcel_position(v)
  case @scale_mode
  when :ORDERED_LEFT
    return (@width * (v - @scale_min) / @scale_max_min).to_i
  when :ORDERED_CENTER
    return ((2 * @width * (v - @scale_min) + @width) / (@scale_max_min + 1) / 2).to_i
  else
    raise "Not support #{@scale_mode} mode."
  end
end

#change_mode(mode) ⇒ Object

(XAxis) 軸描画モード変更

Parameters:

  • mode (Symbol)

    軸描画モード(:LEFT | :CENTER)



1035
1036
1037
1038
1039
1040
1041
# File 'lib/al_graph.rb', line 1035

def change_mode(mode)
  mode_sym = "ORDERED_#{mode}".to_sym
  case mode_sym
  when :ORDERED_LEFT, :ORDERED_CENTER
    @scale_mode = mode_sym
  end
end

#set_max(v) ⇒ Object

(XAxis) 目盛り最大値のユーザ指定 (override)

Parameters:

  • v (Numeric)

    目盛り最大値



1049
1050
1051
# File 'lib/al_graph.rb', line 1049

def set_max(v)
  @scale_max_user = v - 1
end

#set_min(v) ⇒ Object

(XAxis) 目盛り最小値のユーザ指定 (override)

Parameters:

  • v (Numeric)

    目盛り最小値



1059
1060
1061
# File 'lib/al_graph.rb', line 1059

def set_min(v)
  @scale_min_user = v - 1
end