Lacie
Lacie

Reputation: 145

JFreeChart Gantt display subtasks' overlapping

I need to visualize overlapping of subtasks. In my case, a task is one person1, and subtasks of each task have descriptions "SignIn", "SignOut", "Click" (short-duration tasks), "Call" (long-duration task). What I want is to be able to: 1. See the overlap of 2 calls and see overlap of shortTasks and longTasks. Something similar to this enter image description here

My thoughts:

I've followed this Changing saturation of subtasks, changing transparency in getItemPaint

Color rbg = clut.get(clutIndex);
return new Color(rbg.getRed(), rbg.getGreen(), rbg.getBlue(), 150);

but it's not exactly what I'm looking for, since the overlapped areas are not demonstrated.

private @NotNull IntervalCategoryDataset createDataset() {

    final TaskSeries s1 = new TaskSeries("Scheduled");
    Task person1 = new Task("Person1",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
                    date(30, Calendar.APRIL, 2001)));

    // Subtasks
    Task subTask1 = new Task("SignIn",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
                    date(2, Calendar.APRIL, 2001))); // no overlap
    Task subTask2 = new Task("Call1",
            new SimpleTimePeriod(date(5, Calendar.APRIL, 2001),
                    date(20, Calendar.APRIL, 2001))); // day 5 - 20
    Task subTask3 = new Task("Click",
            new SimpleTimePeriod(date(16, Calendar.APRIL, 2001),
                    date(17, Calendar.APRIL, 2001))); // overlap with call1 and call2
    Task subTask4 = new Task("Call2",
            new SimpleTimePeriod(date(15, Calendar.APRIL, 2001),
                    date(30, Calendar.APRIL, 2001))); // day 15 - 30

    person1.addSubtask(subTask1);
    person1.addSubtask(subTask2);
    person1.addSubtask(subTask3);
    person1.addSubtask(subTask4);
    s1.add(person1);
    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);

    return collection;
}

Overlap demo

How to code using my approach or is there any better approaches to achieve this? Thank you!

Upvotes: 1

Views: 80

Answers (1)

trashgod
trashgod

Reputation: 205785

While GanttRenderer doesn't support AlphaComposite directly, you can adjust the hue, saturation and brightness; saturation is shown here, but ⍺ < 1 may be worth exploring. You can set the mode in your implementation of drawItem(); Xor is pictured. Use the AlphaCompositeDemo cited here to find the desired mode and colors.

private static class MyRenderer extends GanttRenderer {
…
    @Override
    public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
        g2.setComposite(AlphaComposite.Xor);
        super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
    }
}

image

Upvotes: 1

Related Questions