Tips & Tricks: Overlapping Milestones in VARCHART JGantt

Posted by Martin Karlowitsch on Oct 18, 2011 4:46:00 PM

From time to time, we will also use this blog to share some tips & tricks how to unleash the full potential of our Gantt software components. We'll start this series with an interesting approach for our Java Gantt control VARCHART JGantt.
Especially while planning a project, the situation may arise that several milestones within one group are defined for the same date. If the single-row mode is used as group layout (jGantt1.setGroupLayout(JGantt.GROUP_ROWLAYOUT_SINGLE);) all milestones of the same date are displayed as overlapping. Hence these milestones can neither be distinguished optically nor be accessed interactively.

This problem can be solved in an application as described below:

Annotations - that in case of overlapping are being stacked - are assigned to the milestones. The following picture shows three milestones on one date. The milestone with the description MS2 has been selected by its annotation. Now it can be moved interactively as well and then gets a symbol of its own.





The sample MilestoneStacking shows how to proceed for three overlapping milestones at most.

In the method MilestoneStacking.prepareMilestones all milestones are collected in a Collection first, the milestones being recognizable by the attribute ms. After this, the date of every milestone is checked for overlapping with other milestones. If a milestone is the first or the only one at a certain date, the content of the attribute ms is copied to the attribute ms1. The same happens if the milestone is the second or third one at this date. The content of attribute ms is then copied to attribute ms2 or ms3, respectively.

The sample includes three LayerDefinitions with according annotations that were shifted vertically. They get activated by filters, taking into consideration the attributes ms1, ms2, and ms3. In the picture above, the positions of the different annotations are indicated by the texts MS1, MS2 and MS3.

Note concerning the sample:
JGantt.interactionTimeQuantum was set to INTERACTION_TIMEQUANTUM_DAY so that shifting a milestone to the date of another milestone is possible in the first place.

New Call-to-action

Topics: Java Gantt Control, JGantt development tricks, Gantt Chart Controls