class CTioga2::Graphics::Elements::Region
A Region
is an object that draws filled regions among its “elements”. It is a fake container in the sense that all the elements are actually forwarded to the parent.
Attributes
curves[RW]
The curves which delimit the region
fill_style[RW]
The fill style
reversed_fill_style[RW]
The fill style for reversed polarity
Public Class Methods
new(parent, root, opts)
click to toggle source
Creates a new empty region
# File lib/ctioga2/graphics/elements/region.rb, line 44 def initialize(parent, root, opts) setup_style(parent, opts) # A reason why we don't use the superclass constructor ? @parent = parent @clipped = true # clipped by default ! # elements to be given to tioga @curves = [] @root_object = root @legend_area = nil @fill_style = Styles::FillStyle.new @fill_style.color = [0.7,0.7,0.7] # For reversed polarity @reversed_fill_style = Styles::FillStyle.new end
Public Instance Methods
add_element(element)
click to toggle source
Adds an element. Actually forwards it to the parent.
# File lib/ctioga2/graphics/elements/region.rb, line 66 def add_element(element) parent.add_element(element) if element.respond_to?(:curve_style) && element.curve_style.region_position @curves << element end end
set_from_hash(hash)
click to toggle source
Sets the various things from hash.
# File lib/ctioga2/graphics/elements/region.rb, line 75 def set_from_hash(hash) @fill_style.set_from_hash(hash) # Reversed isn't what I want... @reversed_fill_style.set_from_hash(hash, 'reversed_%s') end
Protected Instance Methods
prepare_path(t, polarity = :normal)
click to toggle source
Prepares the path that will be filled, according to the given polarity.
# File lib/ctioga2/graphics/elements/region.rb, line 115 def prepare_path(t, polarity = :normal) # We clip the path for the given case polarity when :normal conversion = { :above => :bottom, :below => :top } when :reversed conversion = { :above => :top, :below => :bottom } end closer = Types::FillUntil.new # We clip for the first ones... for c in @curves[0..-2] closer.type = conversion[c.curve_style.region_position] c.make_closed_path(t, closer) t.clip end # We don't clip on the last one ! c = @curves.last closer.type = conversion[c.curve_style.region_position] c.make_closed_path(t, closer) end
real_do(t)
click to toggle source
Creates the appropriate subfigure and draws all its elements within.
todo: attempt to work fine while mixing curves with different axes. That won't be easy.
todo: enable to do positive and negative. The only thing to do is to swap above for below and call again.
# File lib/ctioga2/graphics/elements/region.rb, line 91 def real_do(t) # This function will be called with the proper figure # coordinates. if @fill_style.color t.context do @fill_style.setup_fill(t) prepare_path(t) @fill_style.do_fill(t) end end if @reversed_fill_style.color t.context do @reversed_fill_style.setup_fill(t) prepare_path(t, :reversed) @reversed_fill_style.do_fill(t) end end end