class CTioga2::Graphics::Styles::ContoursStyle
This class expands on the previous one to provide for mechanisms to draw many related contour plots.
Public Class Methods
new()
click to toggle source
# File lib/ctioga2/graphics/styles/contour.rb, line 63 def initialize() @number = 20 @use_naturals = true @minor_number = 4 @minor_scale = 0.6 end
Public Instance Methods
plot_contours(t, table, zmin, zmax, color_map)
click to toggle source
Computes and plots the contours according to the style, using the given color map.
# 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