lib/ctioga2/graphics/styles/plot.rb in ctioga2-0.9 vs lib/ctioga2/graphics/styles/plot.rb in ctioga2-0.10
- old
+ new
@@ -77,11 +77,16 @@
attr_accessor :padding
# Mode for auto-adjust
attr_accessor :text_auto_adjust
+ # If not nil, then the boundaries are computed from the real
+ # dimensions of the plot frame, using the given number as a
+ # conversion factor from the output dimensions.
+ attr_accessor :frame_real_size
+
@@current_index = 0
def initialize
# Default style for the plots.
@axes = {}
@@ -106,11 +111,10 @@
@title =
StyleSheet.style_for(TextLabel, 'title',
nil,
Types::PlotLocation.new(:top))
-
@plot_margin = nil
@transforms = CoordinateTransforms.new
@background =
@@ -305,11 +309,11 @@
end
if @title.loc.is_side?(side)
exts << @title.label_extension(t, 'title', @title.loc) *
(@text_scale || 1)
end
- Types::Dimension.new(:dy, exts.max)
+ Types::Dimension.new(:dy, exts.max || 0)
end
box = Types::MarginsBox.new(*margins)
if @padding
for dim in box.margins
@@ -317,10 +321,19 @@
end
end
return box
end
+ # Clear all axes
+ def clear_axes()
+ [:left, :right, :top, :bottom].each do |loc|
+ style = get_axis_style(loc)
+ style.decoration = Tioga::FigureConstants::AXIS_HIDDEN
+ style.axis_label.text = false
+ end
+ end
+
# Computes the margins based on the text information.
#
# This is very different from the one above, since this one
# relies on measured texts to get it right !
def compute_margins(t, prev_margins)
@@ -431,19 +444,42 @@
EOH
ClearAxesCommand =
Cmd.new("clear-axes",nil,"--clear-axes"
) do |plotmaker, opts|
- [:left, :right, :top, :bottom].each do |loc|
- style = AxisStyle.current_axis_style(plotmaker, loc)
- style.decoration = Tioga::FigureConstants::AXIS_HIDDEN
- style.axis_label.text = false
- end
+ PlotStyle.current_plot_style(plotmaker).clear_axes
end
ClearAxesCommand.
describe("Clear all axes",
<<"EOH", AxisGroup)
Removes all the axes and their associated labels
+EOH
+
+ DrawingFrameCommand =
+ Cmd.new("drawing-frame",nil,"--drawing-frame", [],
+ { 'units' => CmdArg.new('text')
+ }) do |plotmaker, opts|
+ style = PlotStyle.current_plot_style(plotmaker)
+ style.clear_axes
+ style.padding = nil
+ u = opts['units'] || 'cm'
+ if u =~ /([\d.]+)?\s*(cm|in|bp|pt|mm)/
+ nb = $1 ? $1.to_f : 1.0
+ un = $2
+ style.frame_real_size = 10 * nb *
+ Types::Dimension::DimensionConversion.fetch(un)
+ else
+ raise 'Invalid unit'
+ end
+ end
+ DrawingFrameCommand.
+ describe("Setup a drawing frame",
+ <<"EOH", AxisGroup)
+Setup a drawing frame, ie a frame in which the top-left point is at
+0,0, with X and Y values positive over the whole frame, and counted in
+centimeters (or with the unit given using the @/units@ option, ie
+@/units=mm@ expressed in millimeters or @/units=12pt@ expressed in
+multiple of 12 TeX points).
EOH
TicksCommand =
Cmd.new("ticks",nil,"--ticks",