emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: julia.jacobson@arcor.de
To: emacs-orgmode@gnu.org
Subject: Code for feature for showing progress in lisp code for creation of Gantt charts
Date: Thu, 24 May 2012 17:00:54 +0200 (CEST)	[thread overview]
Message-ID: <646467803.782330.1337871654994.JavaMail.ngmail@webmail18.arcor-online.net> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 654 bytes --]

Hello everybody out there using Org-mode,

Some time ago, Eric Fraga had posted a script for generating Gantt charts directly out of Org-mode which is very helpful.
Some project management software allows to follow the progress of tasks by staining a proportional part of the rectangle for a certain task in relation to its completion percentage in green and the rest in red.
This allows easier evaluation of a project's current status.
I added this feature to Eric Fraga's code and would like to post it here for discussion. It would be great if it could be somehow added to Org-mode.

Thank you for making Org-mode such a good piece of software,
Julia

[-- Attachment #2: pro_prog.org --]
[-- Type: application/octet-stream, Size: 7551 bytes --]

#+TITLE:     Gantt charts with progress status
#+AUTHOR:    Julia Jacobson
#+EMAIL:     julia.jacobson@arcor.de
#+DATE:      \today
#+LASTCHANGE:      2012.05.23 21:08:08
#+DESCRIPTION: 
#+KEYWORDS: 
#+LANGUAGE:  en
#+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+LINK_UP:   
#+LINK_HOME: 

#+latex_header: \usepackage{pgf, pgfarrows, pgfnodes}
#+latex_header: \usepackage{tikz}

#+latex_header: \newcommand\ganttline[4]{% line, tag, start end
#+latex_header:   \node at (0,#1) [anchor=base east] {#2};
#+latex_header:   \fill[black!20!white] (#3/20,#1-.2) rectangle (#4/20,#1+.2);}

* Table of tasks and milestones   :noexport:

  One additional column where for the progress of a task in percent is added to the original table.

#+tblname: gantttesttable
    |    | type      |   label | activity                      | depends | start | duration | end | align | progress |
    |----+-----------+---------+-------------------------------+---------+-------+----------+-----+-------+----------|
    |  1 | date      |   Start |                               |         |     0 |          |   0 |       |          |
    |  2 | task      |     1.1 | Lit        survey             |         |     0 |        2 |   2 | right |       75 |
    |  3 | task      |     1.2 | experiments                   |         |     2 |        6 |   8 |       |       40 |
    |  4 | milestone |      M1 | data collected                |       3 |     8 |          |   8 |       |          |
    |  5 | task      |     1.3 | Report                        |       3 |     8 |        6 |  14 |       |       30 |
    |  6 | date      | 6 weeks |                               |         |    14 |          |  14 |       |          |
    |  7 | milestone |      M2 | Release                       |       5 |    14 |          |  14 |       |          |
    |----+-----------+---------+-------------------------------+---------+-------+----------+-----+-------+----------|
    |  8 | task      |     2.1 | Discuss                       |       5 |    14 |        1 |  15 | left  |       90 |
    |  9 | task      |     2.2 | Correct mistakes              |       8 |    15 |        1 |  16 | left  |       10 |
    | 10 | task      |     2.3 | Add feedback                  |       5 |    14 |        2 |  16 | left  |       50 |
    | 11 | date      |     End |                               |         |    16 |          |  16 |       |          |
    |----+-----------+---------+-------------------------------+---------+-------+----------+-----+-------+----------|
    #+TBLFM: address@hidden::$8=$6+$7::@address@hidden::@address@hidden::@address@hidden::@address@hidden::@address@hidden


* lisp code for creating latex that uses above   :noexport:
#+source: elispgantt
#+begin_src emacs-lisp :var table=gantttesttable :results raw :export results
(defun esf/generate-gantt-chart (table)
  (let ((dates "")
	(entries (nthcdr 2 table))
	(milestones "")
	(nmilestones 0)
	(ntasks 0)
	(projecttime 0)
	(tasks "")
	(xlength 1)
	(progress 1)
	)
    (message "Initial: %s\n" table)
    (message "Entries: %s\n" entries)
    (while entries
      (let ((entry (first entries)))
	(if (listp entry)
	    (let ((id (first entry))
		  (type (nth 1 entry))
		  (label (nth 2 entry))
		  (task (nth 3 entry))
		  (dependencies (nth 4 entry))
		  (start (nth 5 entry))
		  (duration (nth 6 entry))
		  (end (nth 7 entry))
		  (alignment (nth 8 entry))
		  (progress (nth 9 entry))
		  )
	      (if (> start projecttime) (setq projecttime start))
	      (if (string= type "task")
		  (let ((end (+ start duration))
			(textposition (+ start (/ duration 2)))
			(flush "")
			)
		    (if (string= alignment "left")
			(progn
			  (setq textposition start)
			  (setq flush "[left]"))
		      (if (string= alignment "right")
			  (progn
			    (setq textposition end)
			    (setq flush "[right]"))
			)
		      )
		    (setq tasks (format "%s  \\gantttask{%s}{%s}{%d}{%d}{%d}{%s}{%d}\n" tasks label task start end textposition flush progress))
		    (setq ntasks (+ 1 ntasks))
		    (if (> end projecttime)
			(setq projecttime end))
		    )
		(if (string= type "milestone")
		    (progn
		      (setq milestones (format "%s  \\ganttmilestone{$\\begin{array}{c}\\mbox{%s}\\\\ \\mbox{%s}\\end{array}$}{%d}\n" milestones label task start))
		      (setq nmilestones (+ 1 nmilestones)))
		  (if (string= type "date")
		      (setq dates (format "%s  \\ganttdateline{%s}{%d}\n" dates label start))
		    (message "Ignoring entry with type %s\n" type)
		    )
		  )
		)
	      )
	  (message "Ignoring non-list entry %s\n" entry)
	  ) ; end if list entry
	(setq entries (cdr entries))
	)
      ) ; end while entries left
    (format "#+begin_latex
\\pgfdeclarelayer{background}
\\pgfdeclarelayer{foreground}
\\pgfsetlayers{background,foreground}
\\renewcommand{\\ganttprojecttime}{%d}
\\renewcommand{\\ganttntasks}{%d}
\\noindent
\\begin{tikzpicture}[y=-0.75cm,x=0.75\\textwidth]
  \\begin{pgfonlayer}{background}
    \\draw[very thin, red!10!white] (0,1+\\ganttntasks) grid [ystep=0.75cm,xstep=1/\\ganttprojecttime] (1,0);
    \\draw[\\ganttdatelinecolour] (0,0) -- (1,0);
    \\draw[\\ganttdatelinecolour] (0,1+\\ganttntasks) -- (1,1+\\ganttntasks);
  \\end{pgfonlayer}
%s
%s
%s
\\end{tikzpicture}
,#+end_latex\n" projecttime ntasks tasks milestones dates)
    )
  )
(esf/generate-gantt-chart table)
#+end_src

* Time line

#+latex_header: \usepackage{tikz}

#+begin_latex
\newcounter{gantttask}
\newcommand{\gantttaskcol}{blue!50!white}
\newcommand{\gantttaskcolour}{yellow!50!white}
\newcommand{\ganttmilestonecolour}{red!50!white}
\newcommand{\ganttdatelinecolour}{black!50!white}
\newcommand{\ganttprojecttime}{1}
\newcommand{\ganttntasks}{1}
\newcommand\gantttask[7]{% label, activity, start, end, labelpos, align
  \begin{pgfonlayer}{foreground}
    % \node at (0,\thegantttask) [anchor=base east] {#2};
    \stepcounter{gantttask}
    \node [left] at (0,\thegantttask) {#1};
    \draw[fill=\gantttaskcol] (#3/\ganttprojecttime,\thegantttask-0.4) rectangle (#3/\ganttprojecttime + #7/100 * #4/\ganttprojecttime - #7/100 * #3/\ganttprojecttime,\thegantttask +0.4);
    \draw[fill=\gantttaskcolour] (#3/\ganttprojecttime + #7/100 * #4/\ganttprojecttime - #7/100 * #3/\ganttprojecttime,\thegantttask-0.4) rectangle (#4/\ganttprojecttime,\thegantttask +0.4);
    \node at (#5/\ganttprojecttime,\thegantttask) #6 {#2};
  \end{pgfonlayer}
}
\newcommand\ganttpoint[3]{% line, tag, date
  \node at (0,#1) [anchor=base east] {#2};
  \fill[black] (#3/\ganttprojecttime,#1) circle (0.1/\ganttprojecttime);
}
\newcommand\ganttdateline[2]{% tag, date
  \begin{pgfonlayer}{background}
    \draw[\ganttdatelinecolour] (#2/\ganttprojecttime,0) -- (#2/\ganttprojecttime,\thegantttask+1);
    \node at (#2/\ganttprojecttime,0) [above] {#1};
  \end{pgfonlayer}
}
\newcommand\ganttmilestone[2]{% tag, date
  \begin{pgfonlayer}{foreground}
    \node at (#2/\ganttprojecttime,\thegantttask+1.0) [below] {#1};
    \draw[black,fill=\ganttmilestonecolour] (#2/\ganttprojecttime-0.1\ganttntasks/\ganttprojecttime,\thegantttask+0.9) rectangle (#2/\ganttprojecttime+0.1\ganttntasks/\ganttprojecttime,\thegantttask+1.1);
  \end{pgfonlayer}
}

#+END_LaTeX


#+   \\draw[help lines, very thin, red!20!white] (0,%s) grid (\\ganttprojecttime,0);

# <<actions>>

             reply	other threads:[~2012-05-24 15:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-24 15:00 julia.jacobson [this message]
2012-05-24 21:10 ` Code for feature for showing progress in lisp code for creation of Gantt charts John Hendy
2012-05-25  7:49 ` julia.jacobson
2012-05-25 13:21   ` John Hendy
2012-05-27  8:37   ` Sean O'Halpin
2012-08-04  8:01 ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=646467803.782330.1337871654994.JavaMail.ngmail@webmail18.arcor-online.net \
    --to=julia.jacobson@arcor.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).