module TaskJuggler::HTMLGraphics

This module provides some functions to render simple graphical objects like filled rectangles and lines as HTML elements.

Public Instance Methods

arrowHeadToHTML(x, y) click to toggle source
# File lib/taskjuggler/reports/HTMLGraphics.rb, line 72
def arrowHeadToHTML(x, y)
  XMLElement.new('div', 'class' => 'tj_arrow_head',
                        'style' => "left:#{x.to_i - 5}px; " +
                                   "top:#{y.to_i - 5}px;")
end
diamondToHTML(x, y) click to toggle source
# File lib/taskjuggler/reports/HTMLGraphics.rb, line 61
def diamondToHTML(x, y)
  html = []
  html << XMLElement.new('div', 'class' => 'tj_diamond_top',
                         'style' => "left:#{x.to_i - 6}px; " +
                                    "top:#{y.to_i - 7}px;")
  html << XMLElement.new('div', 'class' => 'tj_diamond_bottom',
                         'style' => "left:#{x.to_i - 6}px; " +
                                    "top:#{y.to_i}px;")
  html
end
jagToHTML(x, y) click to toggle source
# File lib/taskjuggler/reports/HTMLGraphics.rb, line 55
def jagToHTML(x, y)
  XMLElement.new('div', 'class' => 'tj_gantt_jag',
                        'style' => "left:#{x.to_i - 5}px; " +
                                   "top:#{y.to_i}px;")
end
lineToHTML(xs, ys, xe, ye, category) click to toggle source

Render a line as HTML element. We use ‘div’s with a single pixel width or height for this purpose. As a consequence of this, we can only generate horizontal or vertical lines. Diagonal lines are not supported. xs and ys are the start coordinates, xe and ye are the end coordinates. category determines the color.

# File lib/taskjuggler/reports/HTMLGraphics.rb, line 25
def lineToHTML(xs, ys, xe, ye, category)
  xs = xs.to_i
  ys = ys.to_i
  xe = xe.to_i
  ye = ye.to_i
  if ys == ye
    # Horizontal line
    xs, xe = xe, xs if xe < xs
    style = "left:#{xs}px; top:#{ys}px; " +
            "width:#{xe - xs + 1}px; height:1px;"
  elsif xs == xe
    # Vertical line
    ys, ye = ye, ys if ye < ys
    style = "left:#{xs}px; top:#{ys}px; " +
            "width:1px; height:#{ye - ys + 1}px;"
  else
    raise "Can't draw diagonal line #{xs}/#{ys} to #{xe}/#{ye}!"
  end
  XMLElement.new('div', 'class' => category, 'style' => style)
end
rectToHTML(x, y, w, h, category) click to toggle source

Draw a filled rectable at position x and y with the dimension w and h into another HTML element. The color is determined by the class category.

# File lib/taskjuggler/reports/HTMLGraphics.rb, line 49
def rectToHTML(x, y, w, h, category)
  style = "left:#{x.to_i}px; top:#{y.to_i}px; " +
          "width:#{w.to_i}px; height:#{h.to_i}px;"
  XMLElement.new('div', 'class' => category, 'style' => style)
end