lib/ctioga2/graphics/styles/factory.rb in ctioga2-0.4 vs lib/ctioga2/graphics/styles/factory.rb in ctioga2-0.5
- old
+ new
@@ -1,7 +1,7 @@
# factory.rb: an object in charge of generating the style for Curves
-# copyright (c) 2009 by Vincent Fourmond
+# copyright (c) 2009, 2013 by Vincent Fourmond
# 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.
@@ -15,11 +15,11 @@
require 'ctioga2/log'
# This module contains all the classes used by ctioga
module CTioga2
- Version::register_svn_info('$Revision: 217 $', '$Date: 2010-12-31 16:18:20 +0100 (Fri, 31 Dec 2010) $')
+ Version::register_svn_info('$Revision: 432 $', '$Date: 2013-08-23 19:06:36 +0200 (Fri, 23 Aug 2013) $')
module Graphics
module Styles
@@ -60,11 +60,11 @@
# Creates a new CurveStyleFactoryParameter object.
def initialize(name, type, sets, description,
short_option = nil, disable_cmds = false)
@name = name
- @type = Commands::CommandType.get_type(type)
+ @type = type
@sets = sets
@description = description
@short_option = short_option
@disable_commands = disable_cmds
@@ -106,15 +106,18 @@
# Creates a new parameter for the style factory.
#
# \todo add a way to add some more text to the description;
# possibly a self.describe_parameter function ?
- def self.define_parameter(target, name, type, sets, description,
+ #
+ # @todo Remove completely the 'type' argument
+ def self.define_parameter(target, name, sets, description,
short_option = nil, disable_cmds = false)
# We define two new types:
# - first, the color-or-auto type:
- base_type = Commands::CommandType.get_type(type)
+ # base_type = Commands::CommandType.get_type(type)
+ base_type = CurveStyle.attribute_type(target)
if ! Commands::Interpreter.type("#{base_type.name}-or-auto")
mb_type = base_type.type.dup
mb_type.re_shortcuts = (mb_type.re_shortcuts ?
mb_type.re_shortcuts.dup : {})
@@ -139,20 +142,27 @@
:shortcuts => sets
} ,
"Sets of {type: #{base_type.name}}")
end
param =
- CurveStyleFactoryParameter.new(name, type, sets,
+ CurveStyleFactoryParameter.new(name, base_type, sets,
description, short_option,
disable_cmds)
@parameters ||= {}
@parameters[target] = param
@name_to_target ||= {}
@name_to_target[name] = target
end
+ # A simple parameter is something whose target defines all, ie
+ # only the name and a documentation text is necessary.
+ def self.simple_parameter(target, text, sets = nil)
+ name = target.gsub(/_/, '-')
+ define_parameter(target, name, sets, text, nil)
+ end
+
# Returns the Hash containing the class parameters.
def self.parameters
return @parameters || {}
end
@@ -314,77 +324,73 @@
end
# Now, the parameters:
# Lines:
- define_parameter 'line_color', 'color', 'color',
- Sets::ColorSets, "color", "-c"
+ define_parameter 'line_color', 'color',
+ Sets::ColorSets, "line color", "-c"
- define_parameter 'line_width', 'line-width', 'float',
- Sets::LineWidthSets, "line width", nil
+ simple_parameter 'line_width', 'line width', Sets::LineWidthSets
- define_parameter 'line_style', 'line-style', 'line-style',
- Sets::LineStyleSets, "line style", nil
+ simple_parameter 'line_style', 'line style', Sets::LineStyleSets
# Markers
- define_parameter 'marker_marker', 'marker', 'marker',
+ define_parameter 'marker_marker', 'marker',
Sets::MarkerSets, "marker", '-m'
- define_parameter 'marker_color', 'marker-color', 'color',
- Sets::ColorSets, "marker color", nil
+ simple_parameter 'marker_color', "marker color", Sets::ColorSets
- define_parameter 'marker_scale', 'marker-scale', 'float',
- Sets::LineWidthSets, "marker scale", nil
+ simple_parameter 'marker_scale', "marker scale", Sets::LineWidthSets
# Error bars:
- define_parameter 'error_bar_color', 'error-bar-color', 'color',
- Sets::ColorSets, "error bar color", nil
+ simple_parameter 'error_bar_color', "error bar color",
+ Sets::ColorSets
# Location:
- define_parameter 'location_xaxis', 'xaxis', 'axis',
+ define_parameter 'location_xaxis', 'xaxis',
nil, "X axis", nil, true
- define_parameter 'location_yaxis', 'yaxis', 'axis',
+ define_parameter 'location_yaxis', 'yaxis',
nil, "Y axis", nil, true
# Now, fill style
- define_parameter 'fill_y0', 'fill', 'fill-until',
+ define_parameter 'fill_y0', 'fill',
{}, "Fill until", nil
- define_parameter 'fill_color', 'fill-color', 'color',
- Sets::ColorSets, "fill color", nil
+ simple_parameter 'fill_color', "fill color", Sets::ColorSets
- define_parameter 'fill_transparency', 'fill-transparency', 'float',
- {}, "Fill transparency", nil
+ simple_parameter 'fill_transparency', 'fill transparency', {}
# Region handling
- define_parameter 'region_position', 'region-side', 'region-side',
+ define_parameter 'region_position', 'region-side',
{"default" => [:above, :below]}, "region side", nil
- define_parameter 'style', 'style', 'text',
- {}, "Path style", nil
+ simple_parameter 'path_style', 'path style', {}
# Only for xyz-maps or xy-parametric
- define_parameter 'color_map', 'color-map', 'colormap',
- nil, "Color map", nil
+ simple_parameter 'color_map', 'color map'
+ simple_parameter 'zaxis', "name for the Z axis"
- define_parameter 'zaxis', 'zaxis', 'text',
- nil, "Name for the Z axis", nil
-
## @todo For xy-parametric, there should be a way to specify
## to which z value the maps apply (ie lines = y2, marker =
## y3...). Although for readability, it is probably better
## to avoid that...
- define_parameter 'marker_color_map', 'marker-color-map', 'colormap',
- nil, "Marker color map", nil
+ simple_parameter 'marker_color_map', 'color map for markers'
- define_parameter 'split_on_nan', 'split-on-nan', 'boolean',
- nil, "Split on NaN", nil
+ simple_parameter 'split_on_nan', 'split on NaN'
+ # Contour plot styles
+ simple_parameter 'contour_conrec', "use CONREC for contouring"
+ simple_parameter 'contour_number', "overall number of level lines"
+ simple_parameter 'contour_minor_number', "number of minor level lines between major ones (approx)"
+ simple_parameter 'contour_minor_scale', "relative scale of minor level lines"
+ simple_parameter 'contour_minor_style', "minor ticks line style"
+
+
# And finally, we register all necessary commands...
create_commands
# A constant suitable for use as the optional arguments of the
# plot command.
@@ -460,8 +466,43 @@
return tv
end
end
end
+
+ # Now, we document some aspects of the above created commands
+ c = Commands::Command
+
+ c.document_command("color-map", <<EOD)
+Sets the color map for the subsequent curves, until cancelled by an
+@auto@ argument.
+
+Color maps are used for 3D plots, ie under the effet of
+{command: contour}, {command: xyz-map} and {command: xy-parametric}.
+EOD
+
+ c.document_command("contour-conrec", <<EOD)
+If on, the subsequent curves will use the CONREC algorithm for
+contouring. In the opposite case, the contouring algorithm of Gri is
+used.
+
+Only useful when {command: contour} is in effect.
+EOD
+
+ c.document_command("split-on-nan", <<EOD)
+In general, the NaN (not a number, ie invalid data points in the
+dataset) in a dataset are silently ignored. When this option is on,
+the lines of {command: xy-plot}-style plots are split upon
+encountering a NaN.
+EOD
+
+ c.document_command("zaxis", <<EOD)
+Sets the name of the zaxis for the subsequent curves. This must be an
+axis that has been previously created using {command: new-zaxis}.
+
+This axis will be used to display the colormaps of the following
+curve.
+EOD
+
end
end