GemTimelineChart
A timeline chart visualizes one or more series of time-bound blocks (e.g. tasks or events) along a shared time axis, making it easy to compare their durations and overlaps. For example, it can be used to visualize a project's task schedule (Gantt-style), the booking periods of several rooms in a hotel, or the operating and downtime periods of machines in a Digital Twin.
Usage Example
/* (c) https://github.com/MontiCore/monticore */
package example_charts;
import Domain.Person;
import mc.fenix.charts.GemTimelineChart;
import common.ExamplePage;
page GemTimelineChartExample (List<Person> persons) {
@ExamplePage(
component = @GemTimelineChart(
data = computeDate(persons),
blockClick = getBlockClick(),
showConfig = true
),
basePath = "example_charts",
componentName = "GemTimelineChartExample"
);
}
TypeScript implementation:
package example_charts;
import domain.Person;
import mc.fenix.charts.gemtimelinecharttypes.Timeline;
import mc.fenix.charts.gemtimelinecharttypes.TimelineBlock;
import mc.fenix.charts.gemtimelinecharttypes.TimelineBlockBuilder;
import mc.fenix.charts.gemtimelinecharttypes.TimelineBuilder;
import mc.fenix.charts.gemtimelinecharttypes.TimelineData;
import mc.fenix.charts.gemtimelinecharttypes.TimelineDataBuilder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
public class GemTimelineChartExample extends GemTimelineChartExampleTOP {
private String[] colors = {"red", "green", "blue", "yellow", "orange", "purple", "cyan"};
@Override
public TimelineData computeDate(List<Person> persons) {
List<Timeline> personList = getPersonlist(persons);
TimelineDataBuilder data = new TimelineDataBuilder();
data.timeLine(personList);
return data.build().get();
}
private List<Timeline> getPersonlist(List<Person> persons) {
List<Timeline> personList = new ArrayList<>();
if (persons == null) return personList;
for (int i = 0 ; i< persons.size() && i < colors.length; i++) {
TimelineBuilder timelineBuilder = new TimelineBuilder();
TimelineBlockBuilder preBDay = new TimelineBlockBuilder()
.start(LocalDateTime.of(2025, 0, 1, 0, 00, 00))
.end(persons.get(i).getBirthday().withYear(2025).withDayOfMonth(1).atStartOfDay())
.lane("Not Birthday Month");
TimelineBlockBuilder BDay = new TimelineBlockBuilder()
.start(persons.get(i).getBirthday().withYear(2025).withDayOfMonth(1).atStartOfDay())
.end(persons.get(i).getBirthday().withYear(2025).plusMonths(1).withDayOfMonth(1).atStartOfDay())
.lane("Birthday Month");
TimelineBlockBuilder postBDay = new TimelineBlockBuilder()
.start(persons.get(i).getBirthday().withYear(2025).plusMonths(1).withDayOfMonth(1).atStartOfDay())
.end(LocalDateTime.of(2026, 0,1,0,0,0))
.lane("Not Birthday Month");
List<TimelineBlock> blockList = new ArrayList<>();
blockList.add(preBDay);
blockList.add(BDay);
blockList.add(postBDay);
timelineBuilder.color(Optional.of(colors[i%colors.length]))
.name(persons.get(i).getName())
.identifier((long) i)
.deactivated(false)
.hidden(false)
.block(blockList);
personList.add(timelineBuilder.build().get());
}
return personList;
}
@Override
public Consumer<TimelineBlock> getBlockClick() {
return x -> {
System.out.println(x.getStart());
};
}
}
GUI Model
package mc.fenix.charts;
import mc.fenix.charts.GemTimelineChartTypes.TimelineData;
import mc.fenix.charts.GemTimelineChartTypes.TimelineBlock;
import mc.fenix.charts.GemTimelineChartTypes.Timeline;
import java.time.LocalDateTime;
import java.util.Optional;
component GemTimelineChart (
TimelineData data,
Optional<LocalDateTime> showAfter,
Optional<LocalDateTime> showUntil,
Boolean hideLegend,
Event<TimelineBlock> blockClick,
String width = "100%",
String height = "350px",
boolean showConfig = false
)
| Name |
Type |
Description |
Default value |
data |
TimelineData |
The data to be displayed in the chart, consisting of one or more timelines. |
|
showAfter |
Optional<LocalDateTime> |
If set, only blocks starting after this point in time are shown. |
|
showUntil |
Optional<LocalDateTime> |
If set, only blocks starting before this point in time are shown. |
|
hideLegend |
Boolean |
Whether the legend is hidden. |
|
blockClick |
Event<TimelineBlock> |
Callback that is executed when a timeline block is clicked. |
|
width |
String |
Width of the component in px, %, vh, etc. |
"100%" |
height |
String |
Height of the component in px, %, vh, etc. |
"350px" |
showConfig |
boolean |
Whether the chart's configuration panel is shown. |
false |
Types
GemTimelineChartTypes
package mc.fenix.charts;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
<<pojoCD>>
public classdiagram GemTimelineChartTypes {
public class TimelineData {
List<Timeline> timeLine;
}
public class Timeline {
Long identifier;
String name;
Optional<String> color;
boolean hidden;
boolean deactivated;
List<TimelineBlock> block;
}
public class TimelineBlock {
LocalDateTime start;
LocalDateTime end;
String lane;
}
}
TimelineData
| Name |
Type |
Description |
Default value |
timeLine |
List<Timeline> |
* A list of timelines to be displayed. |
|
Timeline
| Name |
Type |
Description |
Default value |
identifier |
Long |
* A unique identifier for the timeline. |
|
name |
String |
* The name of the timeline. |
|
color |
Optional<String> |
* The color of the timeline. |
|
hidden |
boolean |
* Whether the timeline is hidden. |
|
deactivated |
boolean |
* Whether the timeline is deactivated. |
|
block |
List<TimelineBlock> |
* A list of blocks within the timeline. |
|
TimelineBlock
| Name |
Type |
Description |
Default value |
start |
LocalDateTime |
* The start time of the block. |
|
end |
LocalDateTime |
* The end time of the block. |
|
lane |
String |
* The lane in which the block is displayed. |
|