Class: TaskJuggler::Painter::Element

Inherits:
Object
  • Object
show all
Includes:
Primitives, SVGSupport
Defined in:
lib/taskjuggler/Painter/Element.rb

Overview

The base class for all drawable elements.

Direct Known Subclasses

Circle, Ellipse, Line, PolyLine, Rect, Text

Constant Summary

Constants included from Primitives

Primitives::FillAndStrokeAttrs, Primitives::FillAttrs, Primitives::StrokeAttrs, Primitives::TextAttrs

Instance Method Summary collapse

Methods included from Primitives

#circle, #color, #ellipse, #group, #line, #points, #polyline, #rect, #text

Methods included from SVGSupport

#valuesToSVG

Constructor Details

#initialize(type, attrs, values) ⇒ Element

Create a new Element. type specifies the type of the element. attrs is a list of the supported attributes. values is a hash of the provided attributes.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/taskjuggler/Painter/Element.rb', line 30

def initialize(type, attrs, values)
  @type = type
  @attributes = attrs
  @values = {}
  @text = nil

  values.each do |k, v|
    unless @attributes.include?(k)
      raise ArgumentError, "Unsupported attribute #{k}"
    end
    @values[k] = v
  end
end

Instance Method Details

#to_svgObject

Convert the Element into an XMLElement tree using SVG syntax.



45
46
47
48
49
# File 'lib/taskjuggler/Painter/Element.rb', line 45

def to_svg
  el = XMLElement.new(@type, valuesToSVG)
  el << XMLText.new(@text) if @text
  el
end