# subplot-commands.rb: commands for dealing with subplots # copyright (c) 2009 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. # 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 'ctioga2/utils' require 'ctioga2/log' module CTioga2 module Graphics # The group containing all commands linked to subplots and other # insets, frame margin selections... SubplotsGroup = CmdGroup.new('subplots', "Subplots and assimilated", "Subplots and assimilated", 31) SFMOpts = {} for w in %w(left right top bottom) SFMOpts[w] = CmdArg.new("dimension") end SetFrameMarginsCommand = Cmd.new("frame-margins",nil,"--frame-margins", [ CmdArg.new('frame-margins'), ], SFMOpts) do |plotmaker, margins, opts| if margins for w in SFMOpts.keys if opts.key? w dim = margins.send(w) dim.copy_from(opts[w]) end end end plotmaker.root_object.current_plot.subframe = margins end SetFrameMarginsCommand.describe('Sets the margins of the current plot', < :old, /^\s*both/i => :both, /^\s*measure/i => :measure, } TEType = CmdType.new('text-adjust-mode', {:type => :re_list, :list => TARE}, < CmdArg.new('color'), 'pattern' => CmdArg.new('fill-pattern'), 'reversed_pattern' => CmdArg.new('fill-pattern'), 'transparency' => CmdArg.new('float'), 'reversed_color' => CmdArg.new('color'), 'reversed_transparency' => CmdArg.new('float'), } RegionOptions.merge!(Elements::TiogaElement::StyleBaseOptions) RegionCommand = Cmd.new("region",nil,"--region", [ ], RegionOptions) do |plotmaker, options| r = plotmaker.root_object.enter_region(options) r.set_from_hash(options) end RegionCommand.describe('Starts a region with filling between curves', < CmdArg.new('text')}) do |plotmaker, scale, options| what = options['what'] || 'text' case what when /text/i Styles::PlotStyle.current_plot_style(plotmaker).text_scale = scale when /lines/i Styles::PlotStyle.current_plot_style(plotmaker).lines_scale = scale when /both/i Styles::PlotStyle.current_plot_style(plotmaker).text_scale = scale Styles::PlotStyle.current_plot_style(plotmaker).lines_scale = scale else CTioga2::Log::error { "Unkown 'what' option for plot-scale: #{what}" } end end RescaleCommand.describe('Rescales the current (sub)plot', < CmdArg.new('boolean') }) do |plotmaker, objs, opts| hidden = if opts.key? 'show' ! opts['show'] else true end for o in objs o.hidden = hidden end end HideCommand.describe('Hides named objects', <