Class: Charty::Plotters::SizeMapper::SimpleNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/charty/plotters/relational_plotter.rb

Overview

TODO: This should be replaced with red-colors’s Normalize feature

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vmin = nil, vmax = nil) ⇒ SimpleNormalizer

Returns a new instance of SimpleNormalizer.



128
129
130
131
# File 'lib/charty/plotters/relational_plotter.rb', line 128

def initialize(vmin=nil, vmax=nil)
  @vmin = vmin
  @vmax = vmax
end

Instance Attribute Details

#vmaxObject

Returns the value of attribute vmax.



133
134
135
# File 'lib/charty/plotters/relational_plotter.rb', line 133

def vmax
  @vmax
end

#vminObject

Returns the value of attribute vmin.



133
134
135
# File 'lib/charty/plotters/relational_plotter.rb', line 133

def vmin
  @vmin
end

Instance Method Details

#call(value, clip = nil) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/charty/plotters/relational_plotter.rb', line 135

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