private static final int GROUPS_VISIBLE = 6;
@Override
public JComponent render(DateGapAnalyzerResult result) {
final TaskSeriesCollection dataset = new TaskSeriesCollection();
final Set<String> groupNames = result.getGroupNames();
final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION);
final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS);
final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS);
for (final String groupName : groupNames) {
final String groupDisplayName;
if (groupName == null) {
if (groupNames.size() == 1) {
groupDisplayName = "All";
} else {
groupDisplayName = LabelUtils.NULL_LABEL;
}
} else {
groupDisplayName = groupName;
}
final TimeInterval completeDuration = result.getCompleteDuration(groupName);
final Task completeDurationTask = new Task(groupDisplayName, createTimePeriod(completeDuration.getFrom(),
completeDuration.getTo()));
completeDurationTaskSeries.add(completeDurationTask);
// plot gaps
{
final SortedSet<TimeInterval> gaps = result.getGaps(groupName);
int i = 1;
Task rootTask = null;
for (TimeInterval interval : gaps) {
final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());
if (rootTask == null) {
rootTask = new Task(groupDisplayName, timePeriod);
gapsTaskSeries.add(rootTask);
} else {
Task task = new Task(groupDisplayName + " gap" + i, timePeriod);
rootTask.addSubtask(task);
}
i++;
}
}
// plot overlaps
{
final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName);
int i = 1;
Task rootTask = null;
for (TimeInterval interval : overlaps) {
final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());
if (rootTask == null) {
rootTask = new Task(groupDisplayName, timePeriod);
overlapsTaskSeries.add(rootTask);
} else {
Task task = new Task(groupDisplayName + " overlap" + i, timePeriod);
rootTask.addSubtask(task);
}
i++;
}
}
}
dataset.add(overlapsTaskSeries);
dataset.add(gapsTaskSeries);
dataset.add(completeDurationTaskSeries);
final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0, GROUPS_VISIBLE);
final JFreeChart chart = ChartFactory.createGanttChart("Date gaps and overlaps in " + result.getFromColumnName()
+ " / " + result.getToColumnName(), result.getGroupColumnName(), "Time", slidingDataset, true, true, false);