class GerbilCharts::Surfaces::DetailedLegend

Legend

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

Constants

STAT_TABLE_SIZE
WIDTH_MAX

Attributes

always_visible[R]
showvalues[R]
width[R]

Public Class Methods

new(opts={}) click to toggle source
Calls superclass method
# File lib/gerbilcharts/surfaces/detailed_legend.rb, line 14
def initialize(opts={})
  @class = "legendpanel"
  super(opts)
  @width = opts[:dim] if defined? opts[:dim]
  @always_visible = opts[:always_visible] || false 
  @show_stats = opts[:show_stats].nil? ? true:opts[:show_stats]
end

Public Instance Methods

align_to_anchor(anc) click to toggle source
Calls superclass method
# File lib/gerbilcharts/surfaces/detailed_legend.rb, line 124
def align_to_anchor(anc)
  super
  @bounds.deflate_v(10,10)
  @bounds.deflate_h(2,4)
  if isoverlay? and @width 
    @bounds.left = @bounds.right - @width
  end
end
fmt_prefix_2(raw_value) click to toggle source

format for volumes

# File lib/gerbilcharts/surfaces/detailed_legend.rb, line 134
def fmt_prefix_2 raw_value
units_str = [
                  [1099511627776.0,"T","%.2f%s"],
                  [1073741824.0,   "G","%.2f%s"],
                  [1048576.0,      "M","%.2f%s"],
                  [1024.0,         "K","%.2f%s"],
                  [1,     "", "%d %s"],
                  [1e-03, "m","%.3f %s"],
                  [1e-06, "u","%.3f %s"],
                  [1e-09, "n","%.3f %s"],
                  [1e-12, "p","%.3f %s"],
            ]

  return "0" if raw_value == 0

  units_str.each do |unit|
    if raw_value >= unit[0]
      retval = raw_value  / unit[0]
      return format(unit[2], retval, unit[1])
    end
  end
  return raw_value.to_s
end
int_render(g) click to toggle source
# File lib/gerbilcharts/surfaces/detailed_legend.rb, line 22
def int_render(g)



      if @always_visible
         w=g.newwin("legendpanel_detail")
      else
         w=g.newwin("legendpanel_detail", {:visibility => 'hidden'} )
  end
      g.setactivewindow(w)


      # get max modname, used to calculate width of detailed panel
      max_name_length=0
  parent.modelgroup.each_model do | mod |
           max_name_length = [max_name_length,mod.name.length].max
      end

      @bounds.left = @bounds.right-WIDTH_MAX  if @bounds.width > WIDTH_MAX

  # count determines the bounds
  @bounds.bottom = @bounds.top + 16 + 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 => "showMiniLegend(event);",
                                                                                               :fill => "white",
                                                                                               :stroke => "none", 
                                                                                               :gerbiltooltip1 => "Click to show compact legend" }) 
      g.textout(@bounds.left-4,@bounds.top+5,'>', {:class=>'legend-tool', 
                                                                                              :onclick => "showMiniLegend(event);", 
                                                                                               :gerbiltooltip1 => "Click to show compact legend" }) 

  
  rbox = Rect.new
  rbox.initfrom(@bounds)
  rbox.left += 2
  rbox.right = rbox.left + 10
  rbox.top += 2
  rbox.bottom = rbox.top+10
   

      stat_label_pos = @bounds.right -  STAT_TABLE_SIZE
      headers  = %w(Max Min Avg Latest Total)
      if parent.get_global_option(:show_95th_percentile,false) 
    headers << " 95th"
    stat_label_pos = stat_label_pos - 25
  end

      lab = headers.inject("") { |m,ai| m += ai.rjust(9)}  
      if @show_stats
    g.textout(stat_label_pos, 
              rbox.bottom-2, lab, 
              {'xml:space' => 'preserve', :class => "legendstats"} )
      end

  rbox.top += 16
  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}")
    
            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.slice(0..40),opts)

            stat_ana = mod.get_statistical_analysis
            bucketsize = mod.respond_to?(:bucket_size_secs)? mod.bucket_size_secs: 8


            outs = mod.formatted_val(stat_ana[1]).to_s.rjust(9) +
                       mod.formatted_val(stat_ana[0]).to_s.rjust(9) +
                       mod.formatted_val(stat_ana[2]).to_s.rjust(9) +
                       mod.formatted_val(stat_ana[4]).to_s.rjust(9) +
                       fmt_prefix_2(stat_ana[3]).to_s.rjust(9) 

    if parent.get_global_option(:show_95th_percentile,false) 
      outs += mod.formatted_val(stat_ana[5]).to_s.rjust(9)
    end 

            if @show_stats
            g.textout(stat_label_pos, rbox.bottom-2, outs, {'xml:space' => 'preserve', :class => 'legendstats'} )
            end

    
    rbox.top += 10 + 5
    rbox.bottom = rbox.top+10

  end

      g.setactivewindow
  
end