Class: Charty::Plotters::SimpleNormalizer
- Inherits:
-
Object
- Object
- Charty::Plotters::SimpleNormalizer
- Defined in:
- lib/charty/plotters/relational_plotter.rb
Overview
TODO: This should be replaced with red-colors’s Normalize feature
Instance Attribute Summary collapse
-
#vmax ⇒ Object
Returns the value of attribute vmax.
-
#vmin ⇒ Object
Returns the value of attribute vmin.
Instance Method Summary collapse
- #call(value, clip = nil) ⇒ Object
-
#initialize(vmin = nil, vmax = nil) ⇒ SimpleNormalizer
constructor
A new instance of SimpleNormalizer.
Constructor Details
#initialize(vmin = nil, vmax = nil) ⇒ SimpleNormalizer
Returns a new instance of SimpleNormalizer.
41 42 43 44 |
# File 'lib/charty/plotters/relational_plotter.rb', line 41 def initialize(vmin=nil, vmax=nil) @vmin = vmin @vmax = vmax end |
Instance Attribute Details
#vmax ⇒ Object
Returns the value of attribute vmax.
46 47 48 |
# File 'lib/charty/plotters/relational_plotter.rb', line 46 def vmax @vmax end |
#vmin ⇒ Object
Returns the value of attribute vmin.
46 47 48 |
# File 'lib/charty/plotters/relational_plotter.rb', line 46 def vmin @vmin end |
Instance Method Details
#call(value, clip = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/charty/plotters/relational_plotter.rb', line 48 def call(value, clip=nil) scalar_p = false vector_p = false case value when Charty::Vector vector_p = true value = value.to_a when Array # do nothing else scalar_p = true value = [value] end @vmin = value.min if vmin.nil? @vmax = value.max if vmax.nil? result = value.map {|x| (x - vmin) / (vmax - vmin).to_f } case when scalar_p result[0] when vector_p Charty::Vector.new(result, index: value.index) else result end end |