Gantt

From ConTeXt wiki
Revision as of 14:28, 27 July 2011 by Mæstro (talk | contribs) (usemodule fix)
Jump to navigationJump to search

< Modules | Graphics | Gantt charts | MetaPost >

This is a module for drawing Gantt diagrams via MetaPost.

It is the recommended way of creating Gantt charts within ConTeXt.

Gantt is included as a (third party) module for ConTeXt.

Description

This is a rewrite of the Gantt-tikz module using MetaPost. It shares the same syntax and features and should produce a similar output as the TikZ version.

Here is a short description of the environments and commands:

Gantt

The gantt environment draws the canvas of a gantt figure.

\startgantt[...]{no of Tasks to plot}{no of time slots}

The optional argument [...] can be filled in a key=value syntax, using one or more of the following keys:

  • sx - horizontal scale factor (default: 1)
  • sy - vertical scale factor (default: 1)
  • xunitlength - length of one time slot (default: 1cm)
  • fontsize - fontsize of labels (default: \tf)
  • titlefontsize - fontsize of title section (default: \tfx)
  • drawledgerline - Switch to enable/disable the drawing of horizontal ledger lines (default value: false)

Ganttitle

This is the environment for drawing the title section.

\startganttitle (...) \stopganttitle

Titleelement

This draws one element of the title.

\titleelement{label}{length}

Numtitle

This draws a numbered sequence of title elements.

\numtitle{start number}{increment}{end number}{length of each title element}

Ganttbar

This draws a single, unconnected bar for representing a task.

\ganttbar[pattern=,color=]{label}{start}{length}

The optional comma separated arguments are:

  • <pattern> - not implemented, see Regressions section
  • <color> - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)

Ganttcon

This draws an arrow between the bars specified by coordinates.

\ganttcon{startx}{starty}{endx}{endy}

Ganttbarcon

This draws a single bar and connects the bar with the previous bar for consecutive tasks.

\ganttbarcon[pattern=,color=]{label}{start}{length}

The optional pattern argument are the same as for \ganttbar

Ganttgroup

This draws a bar to group tasks.

\ganttgroup{label}{start}{length}

Examples

Minimal example

\usemodule[gantt]
\setuppagenumbering[location=]

\starttext
  \startgantt{7}{12}
    \startganttitle
      \numtitle{1}{1}{12}{1}
    \stopganttitle
    \ganttbar{a task}{0}{2}
    \ganttbarcon{a consecutive task}{2}{4}
    \ganttbarcon{another consecutive task}{8}{2}
    \ganttbar{another task}{2}{2}
    \ganttbar{another task}{4}{2}
    \ganttbar{another task}{4}{2}
    \ganttcon{4}{4}{4}{6}
  \stopgantt
\stoptext

Gantt example1.png


Similar example using names of calendar months

\usemodule[gantt]
\setuppagenumbering[location=]

\starttext
  \startgantt{3}{12}
    \startganttitle
      \titleelement{Jan}{1}
      \titleelement{Feb}{1}
      \titleelement{Mar}{1}
      \titleelement{Apr}{1}
      \titleelement{May}{1}
      \titleelement{Jun}{1}
      \titleelement{Jul}{1}
      \titleelement{Aug}{1}
      \titleelement{Sep}{1}
      \titleelement{Oct}{1}
      \titleelement{Nov}{1}
      \titleelement{Dec}{1}
    \stopganttitle
    \ganttbar{Task 1}{0}{2}
    \ganttbarcon{a consecutive task}{2}{4}
  \stopgantt
\stoptext

Gantt example2.png


Multiple titles with different length

\usemodule[gantt]
\setuppagenumbering[location=]

\starttext
  \startgantt{4}{12}
    \startganttitle
      \numtitle{2010}{1}{2012}{4}
    \stopganttitle
    \startganttitle
      \numtitle{1}{1}{4}{1}
      \numtitle{1}{1}{4}{1}
      \numtitle{1}{1}{4}{1}
    \stopganttitle
    \ganttbar{Task 1}{0}{2}
    \ganttbarcon{a consecutive task}{2}{4}
  \stopgantt
\stoptext

Gantt example3.png


More complex example (using groups and optional arguments)

\usemodule[gantt]
\setuppapersize[landscape][landscape]
\setuplayout[scale=0.8]
\setuppagenumbering[location=]

\starttext
  \startgantt[xunitlength=0.5cm,fontsize=\tfx,titlefontsize=\tfx,drawledgerline=true]{10}{48}
    \startganttitle
      \titleelement{2009}{7}
      \numtitle{2010}{1}{2012}{12} 
      \titleelement{2013}{5}
    \stopganttitle
    \startganttitle
      \numtitle{6}{1}{12}{1} 
      \numtitle{1}{1}{12}{1} 
      \numtitle{1}{1}{12}{1} 
      \numtitle{1}{1}{12}{1} 
      \numtitle{1}{1}{5}{1} 
    \stopganttitle
    \ganttbar{task 1}{2}{17} 
    \ganttgroup{a group of tasks}{6}{18}
    \ganttbar{task 2}{5}{10} 
    \ganttbar[color=blue]{task 3}{15}{3}  
    \ganttbar{task 4}{20}{3}  
    \ganttcon{15}{4}{20}{6}
    \ganttbar{task 5}{15}{5} 
    \ganttbarcon[color=red]{task 6}{20}{5}
    \ganttbarcon{task 7}{30}{5}
  \stopgantt
\stoptext

Gantt example4.png

Regressions

There are no default color patterns in MetaPost. This needs to be implemented separately in order to have a pattern option in this module.

The temporary solution in this module uses the hatching MetaPost package.

See also


The package maintainer is Adam Reviczky and it is released as Public Domain.