Class: CTioga2::Graphics::Styles::ParametricPlotStyle

Inherits:
BasicStyle
  • Object
show all
Defined in:
lib/ctioga2/graphics/styles/plot-types.rb

Overview

This class defines how the Z values are converted into stylistic information

Constant Summary

Constants inherited from BasicStyle

BasicStyle::AllStyles, BasicStyle::OldAttrAccessor

Instance Method Summary collapse

Methods inherited from BasicStyle

alias_for, aliases, attr_accessor, attribute_type, attribute_types, attributes, convert_string_hash, defined_aliases, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, normalize_hash, normalize_in, normalize_out, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #update_from_other, #use_defaults_from

Constructor Details

#initializeParametricPlotStyle

Returns a new instance of ParametricPlotStyle.



60
61
62
# File 'lib/ctioga2/graphics/styles/plot-types.rb', line 60

def initialize
  @z1 = :marker_color
end

Instance Method Details

#marker_style(curve_style, zvalue, zmin, zmax) ⇒ Object

Returns the marker style for the given Z values.

This will only work if #prepare has been called first !



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ctioga2/graphics/styles/plot-types.rb', line 84

def marker_style(curve_style, zvalue, zmin, zmax)

  style = curve_style.marker.dup

  if @reversed[:marker_scale]
    idx = @reversed[:marker_scale]
    if idx < zvalue.size
      max_scale = curve_style.marker.scale || 1.0

      ## @todo Later on, when a min_marker_scale is provided,
      ## then the scale will be constrained between the min
      ## and max. For now, it is simply proportionnal to the
      ## absolute value of the largest.
      min_scale = curve_style.marker_min_scale

      zm = zmin[idx]
      zM = zmax[idx] 
      
      mm = zM.abs
      m2 = zm.abs
      mm = m2 if m2 > mm

      z = zvalue[idx]

      style.scale = if min_scale
                      min_scale + (max_scale - min_scale) * 
                        (z - zm)/(zM - zm)
                    else
                      zvalue[idx].abs/mm * max_scale
                    end
    end

  end

  for bs in [:color, :line_color, :fill_color]
    stl = "marker_#{bs}".to_sym
    if @reversed[stl]
      idx = @reversed[stl]
      if idx < zvalue.size
        map = curve_style.send("#{stl}_map")
        if map
          style.send("#{bs}=",map.z_color(zvalue[idx], 
                                          zmin[idx], 
                                          zmax[idx]))
        end
      end
    end
  end

  return style

end

#prepareObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ctioga2/graphics/styles/plot-types.rb', line 64

def prepare
  @reversed = {}

  4.times do |i|
    val = self.send("z#{i+1}")
    if val
      @reversed[val] = i
      @needed = i+1
    end
  end
end

#z_columns_neededObject

The number of Z columns needed for the style.



77
78
79
# File 'lib/ctioga2/graphics/styles/plot-types.rb', line 77

def z_columns_needed
  return @needed || 0
end