lib/ctioga2/graphics/styles/factory.rb in ctioga2-0.11 vs lib/ctioga2/graphics/styles/factory.rb in ctioga2-0.12

- old
+ new

@@ -38,10 +38,13 @@ # The pre-defined sets available to use with that # parameter. It is a hash. attr_accessor :sets + # The name of the default set, when it isn't 'default' + attr_accessor :default_set + # The description of the parameter. attr_accessor :description # The short option for setting the parameter directly from # the command-line. @@ -58,12 +61,20 @@ # Creates a new CurveStyleFactoryParameter object. def initialize(name, type, sets, description, short_option = nil, disable_cmds = false) @name = name - @type = type - @sets = sets + @type = type + if sets + # If the sets is an array, it is of the form [sets, 'default set'] + if sets.is_a? Array + @sets = sets[0] + @default_set = sets[1] + else + @sets = sets + end + end @description = description @short_option = short_option @disable_commands = disable_cmds ## \todo it is not very satisfying to mix CommandTypes and @@ -79,11 +90,13 @@ end # Returns a suitable default set for the given object. def default_set return nil unless @sets - if @sets.key? 'default' + if @default_set + return @sets[@default_set] + elsif @sets.key? 'default' return @sets['default'] else @sets.each do |k,v| return v end @@ -247,26 +260,40 @@ 'fill_color' => '=color'.to_sym, 'error_bar_color' => '=marker_color'.to_sym } @parameters_carrays = {} for target, param in self.class.parameters + # There should be a way to do that ! set = param.default_set if set @parameters_carrays[target] = CircularArray.new(set) end end + + @next_style = nil end + # Sets the style to be returned from the next call to #next + # (not counting the effect of the options passed) + def set_next_style(stl) + @next_style = stl + end + # Gets the style for the next curve. The _one_time_ hash # contains values 'parameter name' (name, and not target) => # value that are used for this time only. def next(one_time = {}) - base = {} - for target, array in @parameters_carrays - base[target] = array.next + if @next_style + base = @next_style + @next_style = nil + else + base = {} + for target, array in @parameters_carrays + base[target] = array.next + end + base.merge!(@override_parameters) end - base.merge!(@override_parameters) base.merge!(hash_name_to_target(one_time)) return CurveStyle.from_hash(resolve_links(base)) end @@ -325,22 +352,33 @@ simple_parameter 'line_width', 'line width', Sets::LineWidthSets simple_parameter 'line_style', 'line style', Sets::LineStyleSets # Markers - simple_parameter 'marker', 'marker', Sets::MarkerSets, '-m' + simple_parameter 'marker', 'marker', Sets::MarkerSets, '-m' simple_parameter 'marker_color', "marker color", Sets::ColorSets + simple_parameter 'marker_fill_color', "marker fill color", [Sets::ColorSets, 'nil'] + + simple_parameter 'marker_line_color', "marker stroke color", [Sets::ColorSets, 'nil'] + simple_parameter 'marker_scale', "marker scale", Sets::LineWidthSets + simple_parameter 'marker_angle', "marker angle", nil + + simple_parameter 'marker_line_width', "marker line width", nil + simple_parameter 'marker_min_scale', "marker scale", nil # Error bars: simple_parameter 'error_bar_color', "error bar color", Sets::ColorSets + simple_parameter 'error_bar_line_width', "error bar line width", + Sets::LineWidthSets + # Location: define_parameter 'location_xaxis', 'xaxis', nil, "X axis", nil, true define_parameter 'location_yaxis', 'yaxis', @@ -468,10 +506,43 @@ end return tv end end - end + + SkipCommand = + Cmd.new("skip",nil,"--skip", + [], {'number' => CmdArg.new("integer")} + ) do |plotmaker, opts| + number = opts['number'] || 1 + fct = plotmaker.curve_generator.style_factory + while number > 0 + number -= 1 + fct.next + end + end + + SkipCommand.describe('Skips next curve style', + <<EOH, CurveStyleFactory::CurveStyleGroup) +This command acts as if one (or @number@) dataset had been drawn with +respect to the style of the next dataset to be drawn. +EOH + + ReuseCommand = + Cmd.new("reuse-style",nil,"--reuse-style", + [CmdArg.new('object')], {} + ) do |plotmaker, obj, opts| + stl = obj.curve_style.to_hash + plotmaker.curve_generator.style_factory.set_next_style(stl) + end + + ReuseCommand.describe('Reuse the style of a previous curve', + <<EOH, CurveStyleFactory::CurveStyleGroup) +After using this command, the next curve will have the same style as the +curve whose name was given as the first argument (it is the name given to +the `/id=` option to plot. +EOH +end # Now, we document some aspects of the above created commands c = Commands::Command c.document_command("color-map", <<EOD)