1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# structures.rb, copyright (c) 2006 by Vincent Fourmond:
# The code file for fancy structural elements.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details (in the COPYING file).
require 'Dobjects/Dvector'
require 'CTioga/debug'
require 'CTioga/log'
require 'CTioga/elements'
module CTioga
Version::register_svn_info('$Revision: 653 $', '$Date: 2007-11-15 21:58:42 +0100 (Thu, 15 Nov 2007) $')
# A subplot class for handling plot with alternative axes.
class SharedAxisPlot < SubPlot
# The positions concerned by the axis type in the
# arrays returned by get_boundaries and the like.
BoundaryPositions = {
:y => [2,3],
:x => [0,1]
}
# Some pseudo-accessors:
def shared_axis
if @axis == :y
:x
else
:y
end
end
def private_axis
@axis
end
# Creates a subplot of _parent_ which will use alternative
# axes for _axis_. _axis_ is the axis which is *not* shared !
def initialize(axis = :y, parent = nil)
super(:subplot, parent)
@axis = axis
# We forward all legend information to the parent
@accept_legend = false
end
# Report appropriate values for the axes to the parent
# plot.
def get_boundaries
bounds = internal_get_boundaries
for i in BoundaryPositions[private_axis]
bounds[i] = 0.0/0.0 # NaN is ignored
end
return bounds
end
# We use the parents boundary for the shared axis.
def compute_boundaries
# First, we compute the boundaries using the standard
# Subplot function
bounds = super
# Then we override the shared values using the parents:
parents = parent.compute_boundaries
for i in BoundaryPositions[shared_axis]
bounds[i] = parents[i] # We use the parents boundaries.
end
return bounds
end
end
end
|