# File lib/bio/graphics/panel.rb, line 179
    def draw(file_name)
      if @final_panel_drawing.nil?
        # Create a panel that is huge vertically
        huge_height = 2000

        huge_panel_destination = nil
        huge_panel_destination = Cairo::ImageSurface.new(1, @width, huge_height)

        background = Cairo::Context.new(huge_panel_destination)
        background.set_source_rgb(1,1,1)
        background.rectangle(0,0,@width,huge_height).fill

        # Add ruler
        vertical_offset = 0
        ruler = Ruler.new(self)
        ruler.draw(huge_panel_destination)
        vertical_offset += ruler.height

        # Add tracks
        @tracks.each do |track|
          track.vertical_offset = vertical_offset
          track.draw(huge_panel_destination)
          @number_of_feature_rows += track.number_of_feature_rows
          vertical_offset += ( track.number_of_feature_rows*(FEATURE_HEIGHT+FEATURE_V_DISTANCE+5)) + 10 # '10' is for the header
        end

        # And create a smaller version of the panel
        @height = ruler.height
        @height += 20*@number_of_feature_rows
        @height += 10*@tracks.length #To correct for the track headers
        
        huge_panel_destination = flip_orientation(huge_panel_destination) if @vertical

        @final_panel_destination = Cairo::ImageSurface.new(1, @width, @height)
        resized_context = Cairo::Context.new(@final_panel_destination)
        resized_context.set_source(huge_panel_destination, 0, 0)
        resized_context.rectangle(0,0,@width, @height).fill
      end
      
      # And print to file
      if @format == :png
        @final_panel_destination.write_to_png(file_name)
      else
        case @format
        when :pdf
          output_destination = Cairo::PDFSurface.new(file_name, @width, @height)
        when :ps
          output_destination = Cairo::PSSurface.new(file_name, @width, @height)
        when :svg
          output_destination = Cairo::SVGSurface.new(file_name, @width, @height)
        end
        
        output_context = Cairo::Context.new(output_destination)
        output_context.set_source(@final_panel_destination, 0, 0)
        output_context.rectangle(0,0,@width, @height).fill
      end
      
      @image_map.save(file_name) if @clickable # create png and map
    end