Class: CTioga2::Graphics::Elements::Histogram

Inherits:
Curve2D show all
Includes:
Log, Dobjects
Defined in:
lib/ctioga2/graphics/elements/histogram.rb

Overview

A histogram

Constant Summary

Constants inherited from TiogaElement

TiogaElement::StyleBaseOptions

Instance Attribute Summary collapse

Attributes inherited from Curve2D

#function, #path_elements

Attributes inherited from PlotBasedElement

#curve_style, #dataset

Attributes inherited from TiogaElement

#clipped, #depth, #hidden, #location, #object_classes, #object_id, #object_parent, #parent

Instance Method Summary collapse

Methods included from Log

context, counts, debug, error, fatal, #format_exception, #identify, info, init_logger, log_to, logger, set_level, #spawn, warn

Methods inherited from Curve2D

#can_clip?, #draw_errorbars, #draw_fill, #draw_markers, #draw_path, #get_axes, #real_do

Methods inherited from PlotBasedElement

#clipped, #depth, #location

Methods inherited from TiogaElement

all_styles, base_style, #check_styled, define_style, #do, find_object, find_objects, #get_style, #has_style?, inherited, #inspect, register_object, register_style, #setup_style, #style_class, style_class, style_name, #style_name, styled_classes, #update_style

Constructor Details

#initialize(dataset, style, hstyle) ⇒ Histogram

Returns a new instance of Histogram.



41
42
43
44
# File 'lib/ctioga2/graphics/elements/histogram.rb', line 41

def initialize(dataset, style, hstyle)
  super(dataset, style)
  @histogram_style = hstyle
end

Instance Attribute Details

#histogram_styleObject

The histogram style at the moment of the creation of the object.



38
39
40
# File 'lib/ctioga2/graphics/elements/histogram.rb', line 38

def histogram_style
  @histogram_style
end

Instance Method Details

#get_boundariesObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ctioga2/graphics/elements/histogram.rb', line 46

def get_boundaries
  ry = modified_yvalues
  bnds =  Types::Boundaries.bounds(@function.x, ry)
  if ! @within_gb
    base = get_base

    nb = bnds.dup
    nb.bottom = base
    nb.top = base

    # include the width ?
  

    bnds.extend(nb)
  end
  return bnds
end

#make_closed_path(t, close_type = nil) ⇒ Object

The algorithms for closing the path just look ugly for histograms that are offset from something. The reasoning does not apply here.



92
93
94
95
96
97
98
99
# File 'lib/ctioga2/graphics/elements/histogram.rb', line 92

def make_closed_path(t, close_type = nil)
  org = get_cached_organization
  if org[:has_offsets][self]
    make_path(t)
  else
    super
  end
end

#make_path(t) ⇒ Object

First, a very naive way.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ctioga2/graphics/elements/histogram.rb', line 67

def make_path(t)
  base = get_base

  w, ho, yo = *get_properties(t)

  org = get_cached_organization
  h_o = org[:has_offsets][self]

  for x,y in @function
    xl = x + ho
    xr = xl + w
    b = yo[x]
    t.move_to_point(xl, base+b)
    t.append_point_to_path(xl, y+b)
    t.append_point_to_path(xr, y+b)
    t.append_point_to_path(xr, base+b)
    if h_o               # close !
      t.move_to_point(xl, base+b)
    end
  end
end