lib/ctioga2/graphics/legends/area.rb in ctioga2-0.4 vs lib/ctioga2/graphics/legends/area.rb in ctioga2-0.5

- old
+ new

@@ -14,11 +14,11 @@ require 'ctioga2/utils' require 'ctioga2/log' 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: 386 $', '$Date: 2013-03-11 22:57:16 +0100 (Mon, 11 Mar 2013) $') module Graphics # This module holds all the classes dealing with legends module Legends @@ -72,48 +72,67 @@ # applicable ? # def display_legend(t, container) items = container.legend_storage.harvest_contents t.context do + + ## @todo These two commands should join LegendStyle t.rescale(@legend_style.scale) t.rescale_text(@legend_style.text_scale) # We make figure coordinates frame coordinates t.set_bounds([0, 1, 1, 0]) ## \todo customize this ! x, y = initial_xy(t, container) - w,h = *size(t, container) - h /= @legend_style.scale * @legend_style.text_scale + w,h = *size(t, container, false) + + @legend_style.frame. draw_box_around(t, x, y, x + w, y - h, @legend_style.frame_padding) for item in items ## \todo transform the 0.0 for x into a negative # user-specifiable stuff. + iw, ih = *item.size(t, @legend_style) item.draw(t, @legend_style, x , y) - y -= @legend_style.dy.to_figure(t,:y) + y -= ih end end end # Returns the total size of the legend as a # [ width, height ] # array in figure coordinates. - def size(t, container) + # + # It assumes that the scales are not setup yet, unless + # _resize_ is set to false. + def size(t, container, resize = true) items = container.legend_storage.harvest_contents width, height = 0,0 + + # We apparently can't use context here, for a reason that fails me... + if resize + t.rescale(@legend_style.scale) + t.rescale_text(@legend_style.text_scale) + end + for item in items w,h = item.size(t, @legend_style) + if w > width width = w end - # Hmmm... this is plain wrong... - # height += h - height += @legend_style.dy.to_figure(t,:y) * - @legend_style.scale * @legend_style.text_scale + + height += h end + + if resize + t.rescale(1/@legend_style.scale) + t.rescale_text(1/@legend_style.text_scale) + end + return [ width, height ] end # Returns an enlarged page size that can accomodate for both