lib/ctioga2/graphics/styles/legend.rb in ctioga2-0.4 vs lib/ctioga2/graphics/styles/legend.rb in ctioga2-0.5

- old
+ new

@@ -15,30 +15,33 @@ require 'ctioga2/log' # This module contains all the classes used by ctioga module CTioga2 - Version::register_svn_info('$Revision: 359 $', '$Date: 2012-12-26 10:45:35 +0100 (Wed, 26 Dec 2012) $') + Version::register_svn_info('$Revision: 387 $', '$Date: 2013-03-12 09:33:37 +0100 (Tue, 12 Mar 2013) $') module Graphics module Styles # Style of a given Legends::LegendStorage object. class LegendStorageStyle < BasicStyle # The distance between two lines, a Types::Dimension object. - typed_attribute :dy, 'dimension' + deprecated_attribute :dy, 'dimension', "use vpadding instead" + # The minimum distance between successive vertical elements + typed_attribute :vpadding, 'dimension' + # The width of the legend pictogram, a Types::Dimension object. - attr_accessor :picto_width + typed_attribute :picto_width, 'dimension' # The height of the legend pictogram, a Types::Dimension object. - attr_accessor :picto_height + typed_attribute :picto_height, 'dimension' # The distance between the legend pictogram and the text - attr_accessor :picto_to_text + typed_attribute :picto_to_text, 'dimension' # The overall scale of the legend typed_attribute :scale, 'float' # The scale of the legend text -- relative to the overall @@ -54,12 +57,15 @@ # Padding around the frame typed_attribute :frame_padding, 'dimension' def initialize - @dy = Types::Dimension.new(:dy, 1.6, :y) + # @dy = Types::Dimension.new(:dy, 1.6, :y) + + @vpadding = Types::Dimension.new(:dy, 0.3, :y) + @picto_width = Types::Dimension.new(:dy, 1.6, :x) @picto_height = Types::Dimension.new(:dy, 0.6, :y) @picto_to_text = Types::Dimension.new(:dy, 0.3, :x) @@ -68,9 +74,46 @@ @symbol_scale = 1 @frame = BoxStyle.new() @frame_padding = Types::Dimension.from_text("1mm", :x) + end + + def dy_to_figure(t) + + # Defaults to one line height + the padding + + if @dy + return @dy.to_figure(t, :y) + end + + line = Types::Dimension.new(:dy, 1, :y) + return line.to_figure(t, :y) + @vpadding.to_figure(t, :y) + end + + def vpadding_to_figure(t) + if @dy + line = Types::Dimension.new(:dy, 1, :y) + return (@dy.to_figure(t, :y) - line.to_figure(t, :y)) + end + return @vpadding.to_figure(t, :y) + end + + end + + class MultiColumnLegendStyle < BasicStyle + + # Padding ! + typed_attribute :dx, 'dimension' + + # Number of columns + typed_attribute :columns, 'integer' + + def initialize() + + @dx = Types::Dimension.new(:dy, 0.2, :x) + + @columns = 2 end end end end end