lib/ctioga2/graphics/styles/plot.rb in ctioga2-0.3 vs lib/ctioga2/graphics/styles/plot.rb in ctioga2-0.4
- old
+ new
@@ -17,11 +17,11 @@
require 'ctioga2/graphics/coordinates'
# This module contains all the classes used by ctioga
module CTioga2
- Version::register_svn_info('$Revision$', '$Date$')
+ Version::register_svn_info('$Revision: 370 $', '$Date: 2012-12-28 17:40:18 +0100 (Fri, 28 Dec 2012) $')
module Graphics
module Styles
@@ -31,10 +31,14 @@
# * labels
# * axes and edges (in a *clean* way !)
# * ticks
# * background (uniform fill + watermark if applicable + possibly
# a picture .?)
+ #
+ # This class is way too complex and needs too much flexibility
+ # to be handled by a subclass of BasicStyle. However, all
+ # substyles should be.
class PlotStyle
include Tioga::FigureConstants
include Log
@@ -75,31 +79,40 @@
attr_accessor :padding
def initialize
# Default style for the plots.
@axes = {}
- @axes[:left] = AxisStyle.new(:left,
- AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
- '$y$')
- @axes[:bottom] = AxisStyle.new(:bottom,
- AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
- '$x$')
+ @axes[:left] =
+ StyleSheet.style_for(AxisStyle, 'left', :left,
+ AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
+ '$y$')
+ @axes[:bottom] =
+ StyleSheet.style_for(AxisStyle, 'bottom', :bottom,
+ AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
+ '$x$')
- @axes[:right] = AxisStyle.new(:right, AXIS_WITH_TICKS_ONLY)
- @axes[:top] = AxisStyle.new(:top, AXIS_WITH_TICKS_ONLY)
+ @axes[:right] =
+ StyleSheet.style_for(AxisStyle, 'right', :right,
+ AXIS_WITH_TICKS_ONLY)
+ @axes[:top] =
+ StyleSheet.style_for(AxisStyle, 'top', :top,
+ AXIS_WITH_TICKS_ONLY)
@xaxis_location = :bottom
@yaxis_location = :left
- @title = TextLabel.new
- @title.loc = Types::PlotLocation.new(:top)
+ @title =
+ StyleSheet.style_for(TextLabel, 'title',
+ nil,
+ Types::PlotLocation.new(:top))
@plot_margin = nil
@transforms = CoordinateTransforms.new
- @background = BackgroundStyle.new
+ @background =
+ StyleSheet.style_for(BackgroundStyle, 'background')
# A padding of 4bp ? Why ?? Why not ?
@padding = Types::Dimension.new(:bp, 4)
end
@@ -225,11 +238,11 @@
begin
axis.set_bounds_for_axis(t, bounds[which])
axis.draw_axis(t)
rescue Exception => e
error { "Impossible to draw axis #{which}: #{e.message}" }
- debug { "Full message: #{e.inspect}" }
+ debug { "Full message: #{e.inspect}\n#{e.backtrace.join("\n")}" }
end
end
end
# We draw the title last
title.draw(t, 'title')
@@ -317,55 +330,57 @@
AxisGroup = CmdGroup.new('axes-labels',
"Axes and labels", "Axes and labels", 40)
-
AxisTypeCommands = []
[:left, :right, :top, :bottom].each do |loc|
AxisTypeCommands <<
Cmd.new("#{loc}",nil,"--#{loc}",
[
- CmdArg.new('axis-decoration'),
+ AxisStyleOptions['decoration'],
], PartialAxisStyle) do |plotmaker, dec, opts|
style = AxisStyle.current_axis_style(plotmaker, loc)
style.decoration = dec
style.set_from_hash(opts)
end
AxisTypeCommands.last.
describe("Sets the type of the #{loc} axis",
<<"EOH", AxisGroup)
Sets the type of the #{loc} axis.
+
+The options have the same meaning as for {command: define-axis-style},
+see that command for more information.
EOH
+
end
AxisStyleCommand =
Cmd.new("axis-style",nil,"--axis-style",
[
CmdArg.new('axis'),
- ], FullAxisStyle) do |plotmaker, which, opts|
+ ], AxisStyleOptions) do |plotmaker, which, opts|
style = AxisStyle.current_axis_style(plotmaker, which)
style.set_from_hash(opts)
end
AxisStyleCommand.
describe("Sets the style of the given axis",
<<"EOH", AxisGroup)
This command can be used to set various aspects of the style of the
-given axis, through its various options:
- * decoration
+given axis, through its various options, which are documented in more details
+in the {command: define-axis-style} command.
EOH
BackgroundLinesCommand =
Cmd.new('background-lines', nil, '--background-lines',
[
CmdArg.new('axis'),
CmdArg.new('color-or-false')
- ],{
- 'style' => CmdArg.new('line-style'),
- 'width' => CmdArg.new('float')
- }) do |plotmaker, which, color, options|
+ ],
+ StrokeStyle.options_hash().without('color')
+ ) do |plotmaker, which, color, options|
axis = AxisStyle.current_axis_style(plotmaker, which)
if color
style = {'color' => color}
style.merge!(options)
if axis.background_lines
@@ -386,18 +401,21 @@
%w{x y}.each do |axis|
labelcmd = Cmd.new("#{axis}label", "-#{axis}",
"--#{axis}label", [ CmdArg.new('text') ],
- FullTextStyleOptions) do |plotmaker, label, options|
+ TextLabel.options_hash().without('text')
+ ) do |plotmaker, label, options|
PlotStyle.current_plot_style(plotmaker).
set_label_style("#{axis}_label", options, label)
end
labelcmd.describe("Sets the #{axis.upcase} label of the plot",
<<"EOH", AxisGroup)
Sets the #{axis.upcase} label of the current plot.
EOH
+
+ Commands::make_alias_for_option "#{axis}label", 'alignment', 'align', true
nolabelcmd = Cmd.new("no-#{axis}label", nil,
"--no-#{axis}label", []) do |plotmaker|
PlotStyle.current_plot_style(plotmaker).
set_label_style("#{axis}_label", {}, false)
@@ -422,21 +440,25 @@
end
TitleLabelCommand =
- Cmd.new('title', '-t', '--title', [ CmdArg.new('text') ],
- FullTextStyleOptions) do |plotmaker, label, options|
+ Cmd.new('title', '-t', '--title',
+ [ CmdArg.new('text') ],
+ TextLabel.options_hash().without('text')
+ ) do |plotmaker, label, options|
PlotStyle.current_plot_style(plotmaker).
set_label_style('title', options, label)
end
TitleLabelCommand.describe("Sets the title of the plot",
<<"EOH", AxisGroup)
Sets the title of the current plot.
EOH
+ Commands::make_alias_for_option 'title', 'alignment', 'align', true
+
NoTitleLabelCommand =
Cmd.new('no-title', nil, '--no-title', []) do |plotmaker|
PlotStyle.current_plot_style(plotmaker).
set_label_style('title', {}, false)
end
@@ -499,10 +521,12 @@
[ CmdArg.new('label') ], # Here: change the label too...
FullTextLabelOptions) do |plotmaker, which, options|
PlotStyle.current_plot_style(plotmaker).
set_label_style(which, options)
end
+
+ Commands::make_alias_for_option 'label-style', 'alignment', 'align', true
LabelStyleCommand.describe("Sets the style of the given label",
<<"EOH", AxisGroup)
Sets the style of the given label (see the type {type: label} for more
information).
@@ -514,9 +538,10 @@
lines of the corresponding axis. If you don't want that, you can
override the color using the /stroke_color option of
{command: axis-style}. This will only work with Tioga version 1.11 or
greater.
EOH
+
end
end
end