Class TaskJuggler::Painter
In: lib/taskjuggler/Painter.rb
lib/taskjuggler/Painter/BasicShapes.rb
lib/taskjuggler/Painter/Color.rb
lib/taskjuggler/Painter/Element.rb
lib/taskjuggler/Painter/FontData.rb
lib/taskjuggler/Painter/FontMetrics.rb
lib/taskjuggler/Painter/FontMetricsData.rb
lib/taskjuggler/Painter/Group.rb
lib/taskjuggler/Painter/Points.rb
lib/taskjuggler/Painter/Primitives.rb
lib/taskjuggler/Painter/SVGSupport.rb
lib/taskjuggler/Painter/Text.rb
Parent: Object

This is a vector drawing class. It can describe a canvas with lines, rectangles, circles, ellipses and text elements on it. The elements can be grouped. It currently only supports rendering as an SVG output.

Methods

method_missing   new   to_svg  

Included Modules

Primitives

Classes and Modules

Module TaskJuggler::Painter::Primitives
Module TaskJuggler::Painter::SVGSupport
Class TaskJuggler::Painter::Circle
Class TaskJuggler::Painter::Color
Class TaskJuggler::Painter::Element
Class TaskJuggler::Painter::Ellipse
Class TaskJuggler::Painter::FontMetrics
Class TaskJuggler::Painter::FontMetricsData
Class TaskJuggler::Painter::Group
Class TaskJuggler::Painter::Line
Class TaskJuggler::Painter::Points
Class TaskJuggler::Painter::PolyLine
Class TaskJuggler::Painter::Rect
Class TaskJuggler::Painter::Text

Public Class methods

Create a canvas of dimension width times height. The block can be used to add elements to the drawing. If the block has an argument, the block content is evaluated within the current context. If no argument is provided, the newly created object will be the evaluation context of the block. This will make instance variables of the caller inaccessible. Methods of the caller will still be available.

[Source]

# File lib/taskjuggler/Painter.rb, line 36
    def initialize(width, height, &block)
      @width = width
      @height = height

      @elements = []
      if block
        if block.arity == 1
          # This is the traditional case where self is passed to the block.
          # All Primitives methods now must be prefixed with the block
          # variable to call them.
          yield self
        else
          # In order to have the primitives easily available in the block, we
          # use instance_eval to switch self to this object. But this makes the
          # methods of the original self no longer accessible. We work around
          # this by saving the original self and using method_missing to
          # delegate the method call to the original self.
          @originalSelf = eval('self', block.binding)
          instance_eval(&block)
        end
      end
    end

Public Instance methods

Delegator to @originalSelf.

[Source]

# File lib/taskjuggler/Painter.rb, line 60
    def method_missing(method, *args, &block)
      @originalSelf.send(method, *args, &block)
    end

Render the canvas as SVG output (tree of XMLElement objects).

[Source]

# File lib/taskjuggler/Painter.rb, line 65
    def to_svg
      XMLElement.new('svg', 'width' => "#{@width}px",
                            'height' => "#{@height}px") do
        @elements.map { |el| el.to_svg }
      end
    end

[Validate]