Class: ColorLegend::ColorDelta

Inherits:
BaseLegend show all
Defined in:
lib/graphics/color_delta.rb

Overview

Class to color the output field according to color in BaseLegend#value_legend attributes (see Base). This class should be used when visualizing the difference between two datasets.

Instance Attribute Summary

Attributes inherited from BaseLegend

#delta, #max_value, #min_value, #value_legend

Instance Method Summary collapse

Methods inherited from BaseLegend

#create_color_legend, #print_color_legend, #print_interval_values

Constructor Details

#initialize(min_value, max_value) ⇒ ColorDelta

initialization with constraint: max_value > min_value

Parameters:

  • min_value (Float)

    the minimum value

  • max_value (Float)

    the maximum value



16
17
18
19
20
21
22
23
24
# File 'lib/graphics/color_delta.rb', line 16

def initialize(min_value, max_value)
  if (max_value <= min_value)
    raise ArgumentError,
        " Error in ColorLegend: max_value <= min_value\n".red
  end

  super
  create_color_legend(7)
end

Instance Method Details

#create_output_string_for(value, out_str) ⇒ String

creates an output string for given value

Parameters:

  • value (Float)

    the data value

  • out_str (String)

    form of the output string

Returns:

  • (String)

    colored string for the given value



30
31
32
33
34
35
36
37
38
# File 'lib/graphics/color_delta.rb', line 30

def create_output_string_for(value, out_str)
  return out_str.blue_bg if (value <= @value_legend[0])
  return out_str.cyan_bg if (value <= @value_legend[1])
  return out_str.light_cyan_bg if (value <= @value_legend[2])
  return out_str.light_green_bg if (value <= @value_legend[3])
  return out_str.yellow_bg if (value <= @value_legend[4])
  return out_str.light_red_bg if (value <= @value_legend[5])
  out_str.red_bg
end