Class: CTioga::Histogram2D

Inherits:
Curve2D show all
Defined in:
lib/CTioga/elements/curves.rb

Overview

The basic class to create histograms.

Instance Attribute Summary

Attributes inherited from Curve2D

#function, #style

Attributes inherited from TiogaElement

#parent

Instance Method Summary collapse

Methods inherited from Curve2D

compute_boundaries, #draw_error_bars, #draw_fill, #draw_markers, #draw_path, #get_boundaries, #has_legend?, #need_style?, #parse_position, #plot, #set_data, #set_style, #tangent, #y_value

Methods inherited from TiogaElement

#do, #inspect, #need_style?

Methods included from Log

#identify, #init_logger, #logger, #logger_options, #spawn

Methods included from Debug

#debug_figmaker, #debug_patterns, #debug_puts, #figmaker_options, #test_pattern, #test_pattern_right

Constructor Details

#initialize(*args) ⇒ Histogram2D

Returns a new instance of Histogram2D.



304
305
306
307
# File 'lib/CTioga/elements/curves.rb', line 304

def initialize(*args)
  super
  @line_cap = LINE_CAP_BUTT
end

Instance Method Details

#close_path(t, y) ⇒ Object

In the case of histograms with a defined level, we ignore the fill_type setting for the y value, we use the same level.



359
360
361
362
363
364
365
# File 'lib/CTioga/elements/curves.rb', line 359

def close_path(t,y)
  if y_value(@style.hist_type)
    t.close_path
  else
    super
  end
end

#make_path(t) ⇒ Object

Creates a path for the given curve. This should be defined with care, as it will be used for instance for region coloring and stroking. The function should only append to the current path, not attempt to create a new path or empty what was done before.



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/CTioga/elements/curves.rb', line 314

def make_path(t)
  # vectors to store the resulting path
  x_res = Dvector.new
  y_res = Dvector.new
  x_first = 2 * @function.x[0] - @function.x[1]
  y_first = 2 * @function.y[0] - @function.y[1]
  n = @function.size - 1
  x_last = 2 * @function.x[n] - @function.x[n-1]
  y_last = 2 * @function.y[n] - @function.y[n-1]
  
  t.make_steps('xs' => @function.x, 'ys' => @function.y,
               'dest_xs' => x_res, 'dest_ys' => y_res,
               'x_first' => x_first, 'y_first' => y_first,
               'x_last' =>  x_last,  'y_last' => y_last)
  y_base = y_value(@style.hist_type)
  if y_base
    x_prev = y_prev = nil
    # We remove outer elements, not needed.
    x_res.shift
    y_res.shift
    x_res.pop
    y_res.pop
    for x,y in Function.new(x_res, y_res)
      if x_prev
        # We create a path according to the specs
        x_left = (x_prev + (x - x_prev) * @style.hist_left)
        x_right = (x_prev + (x - x_prev) * @style.hist_right)
        x_p = Dvector[x_left, x_right, x_right]
        y_p = Dvector[y,y,y_base]
        t.move_to_point(x_left,y_base)
        t.append_points_to_path(x_p,y_p)
        y_prev = x_prev = nil
      else
        # Accumulate to get a full step. 
        x_prev = x
        y_prev = y
      end
    end
  else
    t.append_points_to_path(x_res, y_res)
  end
end