# File lib/scruffy/components/legend.rb, line 6
    def draw(svg, bounds, options={})
      vertical = options[:vertical_legend]
      legend_info = relevant_legend_info(options[:layers])
      @line_height, x, y, size = 0
      if vertical
        set_line_height = 0.08 * bounds[:height]
        @line_height = bounds[:height] / legend_info.length
        @line_height = set_line_height if @line_height >
          set_line_height
      else
        set_line_height = 0.90 * bounds[:height]
        @line_height = set_line_height
      end

      text_height = @line_height * FONT_SIZE / 100
      # #TODO how does this related to @points?
      active_width, points = layout(legend_info, vertical)

      offset = (bounds[:width] - active_width) / 2    # Nudge over a bit for true centering

      # Render Legend
      points.each_with_index do |point, idx|
        if vertical
          x = 0
          y = point
          size = @line_height * 0.5
        else
          x = offset + point
          y = 0
          size = relative(50)
        end
        
        # "#{x} #{y} #{@line_height} #{size}"
        
        svg.rect(:x => x, 
          :y => y, 
          :width => size, 
          :height => size,
          :fill => legend_info[idx][:color])

        svg.text(legend_info[idx][:title], 
          :x => x + @line_height, 
          :y => y + text_height * 0.75,
          'font-size' => text_height, 
          'font-family' => options[:theme].font_family,
          :style => "color: #{options[:theme].marker || 'white'}",
          :fill => (options[:theme].marker || 'white'))
      end
    end