Class: CTioga2::Graphics::Styles::ContoursStyle

Inherits:
BaseContourStyle show all
Defined in:
lib/ctioga2/graphics/styles/contour.rb

Overview

This class expands on the previous one to provide for mechanisms to draw many related contour plots.

Constant Summary

Constants inherited from BasicStyle

BasicStyle::AllStyles, BasicStyle::OldAttrAccessor

Instance Method Summary collapse

Methods inherited from BaseContourStyle

#make_contour

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

#initializeContoursStyle

Returns a new instance of ContoursStyle.



63
64
65
66
67
68
# File 'lib/ctioga2/graphics/styles/contour.rb', line 63

def initialize()
  @number = 20
  @use_naturals = true
  @minor_number = 4
  @minor_scale = 0.6
end

Instance Method Details

#plot_contours(t, table, zmin, zmax, color_map) ⇒ Object

Computes and plots the contours according to the style, using the given color map.



72
73
74
75
76
77
78
79
80
81
82
83
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
# File 'lib/ctioga2/graphics/styles/contour.rb', line 72

def plot_contours(t, table, zmin, zmax, color_map)

  ticks = []
  minor_ticks = []

  if @use_naturals
    bdz = (zmax - zmin)*@minor_number/@number
    bdz = Utils.closest_subdivision(bdz)

    zb = ((zmin/bdz).ceil) * bdz
    z = zb
    i = 0
    while z < zmax
      ticks << z
      z = zb + i*bdz
      i += 1
    end

    sbdz = bdz/@minor_number
    sbdz = Utils.closest_subdivision(sbdz, false)

    zb = ((zmin/sbdz).ceil) * sbdz
    z = zb
    i = 0
    idx = 0
    while z < zmax
      if ticks[idx] == z
        idx += 1
      else
        minor_ticks << z
      end
      i += 1
      z = zb + i*sbdz
    end
  else
    dz = (zmax - zmin)/@number
    @number.times do |i|
      ticks << zmin + (i + 0.5) * dz
    end
  end

  for lvl in ticks
    t.context do
      t.stroke_color = color_map.z_color(lvl, zmin, zmax)
      contour = make_contour(table, lvl)
      t.append_points_with_gaps_to_path(*contour)
      t.stroke
    end
  end

  # Minor ticks, when applicable !
  t.context do 
    t.line_width = t.line_width * @minor_scale
    @minor.set_stroke_style(t) if @minor
    for lvl in minor_ticks
      t.stroke_color = color_map.z_color(lvl, zmin, zmax)
      contour = make_contour(table, lvl)
      t.append_points_with_gaps_to_path(*contour)
      t.stroke
    end
  end

end