Class: AlGraph::YAxis

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

Overview

Y軸クラス

Direct Known Subclasses

Y2Axis

Constant Summary

Constant Summary

Constants inherited from GraphBase

GraphBase::ATTR_NAMES, GraphBase::ATTR_UNITS

Instance Attribute Summary

Attributes inherited from Axis

#at_interval_marks, #at_labels, #at_scale_line, #labels

Attributes inherited from GraphBase

#height, #output, #width

Instance Method Summary (collapse)

Methods inherited from Axis

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

Constructor Details

- (YAxis) initialize(width, height, output)

constructor

Parameters:

  • width (Integer)

  • height (Integer)

    高さ

  • output (GraphOutput)

    出力制御オブジェクト



397
398
399
400
401
# File 'lib/al_graph.rb', line 397

def initialize(width, height, output)
  super
  @at_labels[:text_anchor] = 'end'
  @at_interval_marks[:grid] = true
end

Instance Method Details

- (Integer) calc_pixcel_position(v)

Note:

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

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

Parameters:

  • v (Numeric)

    実数

Returns:

  • (Integer)

    ピクセル位置



506
507
508
509
510
511
512
# File 'lib/al_graph.rb', line 506

def calc_pixcel_position(v)
  if @flag_reverse
    return (@height * (v - @scale_min) / @scale_max_min_width.to_f).to_i
  else
    return @height - (@height * (v - @scale_min) / @scale_max_min_width.to_f).to_i
  end
end

- (Object) do_scaling

Note:

あらかじめ与えられているデータ系列情報などを元に、 オートスケール処理など、内部データの整合性をとる。

目盛りスケーリング

Returns:

  • 成功時、真。



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/al_graph.rb', line 410

def do_scaling()
  max = nil
  min = nil
  interval = nil

  #
  # search max and min value.
  #
  @data_series.each do |ds|
    max = ds.y_data_max if max == nil || max < ds.y_data_max
    min = ds.y_data_min if min == nil || min > ds.y_data_min
  end
  
  # 空のデータ系列が指定されていた場合のmax, min
  max ||= 0
  min ||= 0

  if max == min
    max += max.abs * 0.5
    min -= min.abs * 0.5
  end
  
  # 
  # max point adjustment.
  #
  diff = max - min
  max += diff * 0.1


  #
  # zero point adjustment.
  #
  diff = max - min
  if min > 0 && diff * 2 > min
    min = 0
  elsif (max < 0 && diff * 2 > -max)
    max = 0
  end

  # 
  # refrect user settings.
  #
  max = @scale_max_user if @scale_max_user
  min = @scale_min_user if @scale_min_user
  interval = @scale_interval_user if @scale_interval_user

  #
  # auto scaling.
  # 
  diff = max - min
  if diff > 0
    # calc interval.
    unless @scale_interval_user
      # .to_fを呼ばないとintervalがRationalオブジェクトになる
      interval = (10 ** (Math.log10(diff).floor - 1)).to_f
      tick = diff / interval
      if tick > 50
        interval *= 10
      elsif tick > 20
        interval *= 5
      elsif tick > 10
        interval *= 2
      end
    end

    #max and min point adjustment.
    max = (max / interval).ceil * interval unless @scale_max_user
    min = (min / interval).floor * interval unless @scale_min_user
  end

  return false unless interval

  @scale_max = max
  @scale_min = min
  @scale_interval = interval
  @scale_max_min_width = @scale_max - @scale_min
  @scale_max_min_width = 1 if @scale_max_min_width == 0

  #
  # check scale intarval value, and fource adjust.
  #
  if @width.to_i > 0 && ((max - min) / interval) > @width 
    @scale_interval = (max - min) / (@width / 2)
  end

  return true
end