Module: TaskJuggler::HTMLGraphics

Included in:
CollisionDetector, GanttChart, GanttContainer, GanttLine, GanttLoadStack, GanttMilestone, GanttTaskBar
Defined in:
lib/taskjuggler/reports/HTMLGraphics.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#arrowHeadToHTML(x, y) ⇒ Object



72
73
74
75
76
# 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) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# 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) ⇒ Object



55
56
57
58
59
# 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) ⇒ Object

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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ Object

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.



49
50
51
52
53
# 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