Class: CTioga2::Graphics::Styles::CurveStyle

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

Overview

A class holding all the styles for a curve.

todo maybe for objects different than Curve2D, a subclass of CurveStyle could be used ? This way, we could have clearly separated legends and the like ?

Constant Summary

Constants inherited from BasicStyle

BasicStyle::AllStyles, BasicStyle::OldAttrAccessor

Instance Attribute Summary collapse

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

#initializeCurveStyle

Returns a new instance of CurveStyle.



118
119
120
121
# File 'lib/ctioga2/graphics/styles/curve.rb', line 118

def initialize()
  @clipped = true
  @depth = 50
end

Instance Attribute Details

#targetObject

The object attached to this style. It is set by Generator#curve_from_dataset



116
117
118
# File 'lib/ctioga2/graphics/styles/curve.rb', line 116

def target
  @target
end

Instance Method Details

#draw_legend_pictogram(t) ⇒ Object

TODO:

Most probably the legend pictogram should be done by

Draws a legend pictogram that fills up the whole current frame.

todo add more elements to the pictogram in case of more complex things.

the curve directly rather than by the style.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/ctioga2/graphics/styles/curve.rb', line 146

def draw_legend_pictogram(t)
  t.context do
    case @target
    when Elements::Curve2D
      if has_line?
        @line.set_stroke_style(t)
        t.stroke_line(0.0, 0.5, 1.0, 0.5)
      end
      if has_marker?
        @marker.draw_markers_at(t, [0.5], [0.5])
      end
    when Elements::Parametric2D
      if has_marker? && @marker_color_map
        colors = @marker_color_map.colors.uniq
        i = 1
        total = colors.size + 1.0
        for c in colors
          @marker.draw_markers_at(t, [i/total], [0.5], 
                                  {'color' => c} )
          i += 1
        end
      end
    end
  end
end

#has_legend?Boolean

True if there is one legend to be drawn for this object.

Returns:

  • (Boolean)


134
135
136
# File 'lib/ctioga2/graphics/styles/curve.rb', line 134

def has_legend?
  return @legend
end

#has_line?Boolean

True if a line should be drawn.

Returns:

  • (Boolean)


124
125
126
# File 'lib/ctioga2/graphics/styles/curve.rb', line 124

def has_line?
  return @line && @line.style
end

#has_marker?Boolean

True if markers should be drawn

Returns:

  • (Boolean)


129
130
131
# File 'lib/ctioga2/graphics/styles/curve.rb', line 129

def has_marker?
  return @marker && @marker.marker
end