class GerbilCharts::Surfaces::Legend

Legend

legend panel shows names/colors of items in a separate box (transparent)

Attributes

showvalues[R]
width[R]

Public Class Methods

new(opts={}) click to toggle source
# File lib/gerbilcharts/surfaces/legend.rb, line 10
def initialize(opts={})
  @class = "legendpanel"
  super(opts)
  @width = opts[:dim] if defined? opts[:dim]
end

Public Instance Methods

align_to_anchor(anc) click to toggle source
# File lib/gerbilcharts/surfaces/legend.rb, line 101
def align_to_anchor(anc)
  super
  @bounds.deflate_v(10,10)
  @bounds.deflate_h(2,4)
  if @width
    @bounds.left = @bounds.right - @width
  end
end
int_render(g) click to toggle source
# File lib/gerbilcharts/surfaces/legend.rb, line 16
def int_render(g)
      return if not parent.get_global_option(:enable_legend,true) 

      w=g.newwin("legendpanel_mini")

      if parent.get_global_option(:align, :right) == :left 
           g.add_option("transform", "translate(#{-@bounds.left+50})")
      end
      g.setactivewindow(w)

  # count determines the bounds
  @bounds.bottom = @bounds.top + 15 * parent.modelgroup.count
  g.rectangle_r(@bounds, {:class => @class})

      # toggle detail/mini legend
      g.rectangle(@bounds.left-5,@bounds.top,5,5, {:href => "javascript:void(0);", 
                                                                                              :onclick => "showDetailedLegend(event);",
                                                                                               :fill => "white",
                                                                                               :stroke => "none",
                                                                                               :gerbiltooltip1 => "Click to show a detailed legend" })

      g.textout(@bounds.left-7,@bounds.top+5,'+', {:class=> 'legend-tool', 
                                                                                              :onclick => "showDetailedLegend(event);", 
                                                                                               :gerbiltooltip1 => "Click to show a detailed legend" }) 

      # shift
      g.rectangle(@bounds.left-5,@bounds.top+15,5,5, {:href => "javascript:void(0);", 
                                                                                              :onclick => "shiftLegend(#{-@bounds.left+50});",
                                                                                               :fill => "white",
                                                                                               :stroke => "none",
                                                                                               :gerbiltooltip1 => "Click to move legend to left side" })
      g.textout(@bounds.left-7,@bounds.top+15,'<', {:class=>'legend-tool',
                                                                                              :onclick => "shiftLegend(#{-@bounds.left+50});", 
                                                                                               :gerbiltooltip1 => "Click to move legend to left side" })


      # shift
      g.rectangle(@bounds.left-5,@bounds.top+25,5,5, {:href => "javascript:void(0);", 
                                                                                              :onclick => "shiftLegend(0);",
                                                                                               :fill => "white",
                                                                                               :stroke => "none" ,
                                                                                               :gerbiltooltip1 => "Click to move legend to right side"})
      g.textout(@bounds.left-7,@bounds.top+25,'>', {:class => 'legend-tool',
                                                                                              :onclick => "shiftLegend(0);", 
                                                                                               :gerbiltooltip1 => "Click to move legend to right side"})
  rbox = Rect.new
  rbox.initfrom(@bounds)
  rbox.left += 20
  rbox.right = rbox.left + 10
  rbox.top += 2
  rbox.bottom = rbox.top+10
   
  parent.modelgroup.each_model_with_index do | mod, i|

            # Adding tool tips
            opts = { :class => "legendtext" }
            opts.merge!(:onmouseover => "OpacityDown(evt)", :onmouseout => "OpacityUp(evt)") 
            opts.store(:gerbiltooltip1, mod.name) 
            opts.store(:gerbiltooltip2, "Latest Value = #{mod.latest_val}")

            if mod.hasHref? 
                    opts.store(:href, mod.href)
            end
    
        # Selector
    ctlbox = Rect.new
            ctlbox.initfrom(rbox)
            ctlbox.offset_x(-16)
        ctlbox.deflate(1)
    g.circle_r(ctlbox, {:id => "lbx#{i}", :fill => 'gray', :stroke => 'none', :href => "javascript:void(0);", :onclick => "ToggleVisibility(#{i})"})
    
            boxopts = {:id => "item#{i}"}
            boxopts.store(:fill , color_for_id(i)) if i > 10
            g.rectangle_r(rbox, boxopts )
            g.textout(rbox.right+5, rbox.bottom-2, mod.name,opts)
                                            
    rbox.top += 10 + 5
    rbox.bottom = rbox.top+10

  end

      g.setactivewindow
  
end