1
# containers.rb: drawables that contains other drawables
2
# copyright (c) 2006, 2007, 2008, 2009 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details (in the COPYING file).
15
require 'ctioga2/utils'
20
Version::register_svn_info('$Revision: 155 $', '$Date: 2010-06-21 21:41:32 +0200 (Mon, 21 Jun 2010) $')
26
# A Container is a drawable object that contains several others, its
28
class Container < TiogaElement
30
# All drawable Element contained in this object. It may
31
# contain other Container subobjects.
32
attr_accessor :elements
34
# The subframe position of this element with respect to its
35
# parent. It is a Types::Box object.
36
attr_accessor :subframe
38
# A reference to the RootObject
39
attr_accessor :root_object
41
# The Legends::LegendArea dedicated to the display of the
42
# legend of this object and its children, or _nil_ if the
43
# parent should handle the display.
44
attr_accessor :legend_area
46
# The Legends::LegendStorage that holds all the legends of the
48
attr_accessor :legend_storage
50
# Creates an empty new Container with the given _parent_.
51
def initialize(parent = nil, root = nil)
54
# elements to be given to tioga
57
# By default the frame takes up all the space.
58
@subframe = Types::MarginsBox.new(0, 0, 0, 0)
62
@legend_storage = Legends::LegendStorage.new
64
# By default, don't display legends.
68
# Returns the number of child elements
73
# Sometimes, the value of the subframe is _nil_ and determined
74
# during the plot. This function is guaranteed to return the
75
# correct value. It takes a reference to a FigureMaker object.
76
def actual_subframe(t)
81
def add_element(element)
85
# If the element has a curve_style, we add it as a
87
if element.respond_to?(:curve_style) and
88
element.curve_style.has_legend?
89
add_legend_item(Legends::CurveLegend.new(element.curve_style))
90
elsif element.is_a? Container
91
add_legend_item(element)
94
# We call LocationStyle#finalize! if possible
95
if(self.respond_to?(:style) and element.respond_to?(:location))
96
element.location.finalize!(self.style)
101
# Adds a legend item to the #associated_legend_storage
102
def add_legend_item(item)
103
@legend_storage.add_item(item)
106
# \todo provide coordinate conversion facilities...
110
# Creates the appropriate subfigure and draws all its elements
113
t.subfigure(@subframe.to_frame_margins(t)) do