Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom Date Range to Gantt Charts Part 2 #5220

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d40023e
Add date range parser
paldeep-singh Jan 20, 2024
4ef5798
Add db functions
paldeep-singh Jan 20, 2024
6f7cc40
Add db tests
paldeep-singh Jan 20, 2024
43dba1c
Add parser tests
paldeep-singh Jan 20, 2024
6389c59
Rework renderer timescale to use new db functions
paldeep-singh Jan 20, 2024
a37cb06
Add docs update
paldeep-singh Jan 20, 2024
281edc9
Add snapshot tests
paldeep-singh Jan 20, 2024
1bf4121
Compute start date if end-only dateRange provided
paldeep-singh Jan 20, 2024
62d5871
Add docs for verifying snapshots
paldeep-singh Jan 20, 2024
d0bba86
Ensure tasks do not spill out of date range
paldeep-singh Jan 20, 2024
c475e55
Remove eslint disables
paldeep-singh Jan 20, 2024
1cb58a3
Fix unit tests and add tests for out of bounds dates
paldeep-singh Jan 21, 2024
7cd30b5
add release version to docs
paldeep-singh Jan 21, 2024
f175a23
Make docs clearer
paldeep-singh Jan 21, 2024
9cb06bb
Update packages/mermaid/src/diagrams/gantt/ganttDb.js
paldeep-singh Mar 10, 2024
5bdec31
Fix dateRange parsing to not skip first character
paldeep-singh Mar 10, 2024
7480eec
Add additional tests for valid date ranges
paldeep-singh Mar 10, 2024
0444adb
Add tests for invalid date ranges and invalid range syntax
paldeep-singh Mar 10, 2024
81b57d6
Always throw error if dayjs determines date is invalid
paldeep-singh Mar 10, 2024
1071afc
Improve e2e test names for time-only date ranges
paldeep-singh Mar 10, 2024
d8b07bf
Add dateRange e2e tests for date-only ranges
paldeep-singh Mar 10, 2024
5ff31bd
Remove compact declaration in dateRange cypress tests
paldeep-singh Mar 10, 2024
db4a31a
Add test with tasks outside of specified date range
paldeep-singh Mar 10, 2024
fe77471
Merge branch 'develop' into feature/1530_gantt_chart_custom_range_2
paldeep-singh Mar 10, 2024
ec5b9b2
Fix syntax for title and dateFormat in theme tests for gantt charts
paldeep-singh Mar 15, 2024
6a3b4a0
Add tasks that partially exist within date range
paldeep-singh Mar 22, 2024
a4c03f1
Add time-only date range tests with tasks outside range
paldeep-singh Mar 22, 2024
6ca3fd0
Remove tasks outside of date range in tests not testing that behaviour
paldeep-singh Mar 22, 2024
1d0efd1
Default date format to YYYY-MM-DD
paldeep-singh Mar 22, 2024
e945fbf
Make chart titles in date range tests more descriptive
paldeep-singh Mar 22, 2024
424dac9
Add e2e test for time and date dateRange with tasks extending outside…
paldeep-singh Mar 22, 2024
00ddb98
Fix axis ticks for time-only date range test
paldeep-singh Mar 22, 2024
c644fb8
Merge branch 'develop' into feature/1530_gantt_chart_custom_range_2
paldeep-singh Mar 22, 2024
1ba0cb8
Merge branch 'develop' into feature/1530_gantt_chart_custom_range_2
paldeep-singh Mar 31, 2024
d481122
Merge branch 'develop' into feature/1530_gantt_chart_custom_range_2
paldeep-singh Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 241 additions & 0 deletions cypress/integration/rendering/gantt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,247 @@ describe('Gantt diagram', () => {
);
});

it('should render when there is a date-only dateRange with both start and end dates', () => {
imgSnapshotTest(
`
gantt
title GANTT with date-only startDate and endDate dateRange
dateFormat YYYY-MM-DD
dateRange 2022-01-01,2022-03-31
axisFormat %m-%d
tickInterval 1week
section DB Clean
Clean: 2022-01-01, 2d
Clean: 2022-01-05, 3d
Clean: 2022-01-30, 6d
Clean: 2022-02-02, 3d
Clean: 2022-02-15, 6d
Clean: 2022-03-10, 1d
Clean: 2022-03-29, 1d
section Sessions
A: 2022-01-01, 3d
B: 2022-01-07, 4d
C: 2022-01-31, 5d
D: 2022-02-03, 6d
E: 2022-02-22, 1d
F: 2022-02-25, 2d
G: 2022-03-01, 12d
H: 2022-03-19, 8d
I: 2022-03-23, 7d
`,
{}
);
});

it('should render when there is a date-only dateRange with a startDate only', () => {
imgSnapshotTest(
`
gantt
title GANTT with date-only startDate dateRange
dateFormat YYYY-MM-DD
dateRange 2022-01-01
axisFormat %m-%d
tickInterval 1week
section DB Clean
Clean: 2022-01-01, 2d
Clean: 2022-01-05, 3d
Clean: 2022-01-30, 6d
Clean: 2022-02-02, 3d
Clean: 2022-02-15, 6d
Clean: 2022-03-10, 1d
Clean: 2022-03-29, 1d
section Sessions
A: 2022-01-01, 3d
B: 2022-01-07, 4d
C: 2022-01-31, 5d
D: 2022-02-03, 6d
E: 2022-02-22, 1d
F: 2022-02-25, 2d
G: 2022-03-01, 12d
H: 2022-03-19, 8d
I: 2022-03-23, 7d
`,
{}
);
});

it('should render when there is a date-only dateRange with an endDate only', () => {
imgSnapshotTest(
`
gantt
title GANTT with date-only endDate dateRange
dateFormat YYYY-MM-DD
dateRange ,2022-03-31
axisFormat %m-%d
tickInterval 1week
section DB Clean
Clean: 2022-01-01, 2d
Clean: 2022-01-05, 3d
Clean: 2022-01-30, 6d
Clean: 2022-02-02, 3d
Clean: 2022-02-15, 6d
Clean: 2022-03-10, 1d
Clean: 2022-03-29, 1d
section Sessions
A: 2022-01-01, 3d
B: 2022-01-07, 4d
C: 2022-01-31, 5d
D: 2022-02-03, 6d
E: 2022-02-22, 1d
F: 2022-02-25, 2d
G: 2022-03-01, 12d
H: 2022-03-19, 8d
I: 2022-03-23, 7d
`,
{}
);
});

it('should render when there is a date-only dateRange with startDate and endDate, with tasks before and after the dateRange', () => {
imgSnapshotTest(
`gantt
title Gantt diagram with date-only date range and tasks before and after the date range
dateFormat YYYY-MM-DD
dateRange 2022-01-01,2022-03-31
axisFormat %m-%d
tickInterval 1week
section Section
A task before : 2021-12-01, 20d
A task starting before and completing within: 2021-12-25, 10d
A task within : 2022-01-15, 40d
A task starting within and ending after: 2022-03-25, 10d
A task after : 2022-04-01, 20d
section Another
A task before : 2021-11-01, 40d
A task within : 2022-02-15, 30d
A task after : 2023-04-01, 20d
`,
{}
);
});

it('should render when there is a time-only dateRange with both start and end dates', () => {
imgSnapshotTest(
`
gantt
title GANTT with time-only startDate and endDate dateRange
dateFormat HH:mm:ss
dateRange 12:30:00,13:30:00
axisFormat %Hh%M
section DB Clean
Clean: 12:30:00, 12m
Clean: 13:00:00, 8m
Clean: 13:20:00, 9m
section Sessions
B: 12:30:00, 12m
C: 13:05:00, 12m
D: 13:06:00, 33m
E: 13:15:00, 55m
F: 13:20:00, 10m
`,
{}
);
});

it('should render when there is a time-only dateRange with a startDate only', () => {
imgSnapshotTest(
`
gantt
title GANTT with time-Only startDate dateRange
dateFormat HH:mm:ss
dateRange 12:30:00
axisFormat %Hh%M
section DB Clean
Clean: 12:30:00, 12m
Clean: 13:00:00, 8m
Clean: 13:30:00, 9m
Clean: 14:00:00, 13m
Clean: 14:30:00, 10m
Clean: 15:00:00, 11m
section Sessions
A: 12:30:00, 12m
B: 13:05:00, 12m
C: 13:06:00, 33m
D: 13:15:00, 55m
E: 13:20:00, 12m
F: 13:32:00, 18m
G: 13:50:00, 20m
H: 14:10:00, 10m
`,
{}
);
});

it('should render when there is a time-only dateRange with an endDate only', () => {
imgSnapshotTest(
`
gantt
title GANTT with time-Only endDate dateRange
dateFormat HH:mm:ss
dateRange ,13:30:00
axisFormat %Hh%M
section DB Clean
Clean: 12:00:00, 10m
Clean: 12:30:00, 12m
Clean: 13:00:00, 8m
section Sessions
A: 12:00:00, 63m
B: 12:30:00, 12m
C: 13:05:00, 12m
D: 13:06:00, 33m
E: 13:15:00, 55m
F: 13:20:00, 10m
`,
{}
);
});

it('should render when there is a time-only dateRange with startDate and endDate, with tasks before and after the dateRange', () => {
imgSnapshotTest(
`gantt
title Gantt diagram with time-only date range and tasks before and after the date range
dateFormat HH:mm:ss
dateRange 12:00:00, 18:00:00
axisFormat %Hh%M
tickInterval 1week
section Section
A task before : 11:30:00, 25m
A task starting before and completing within: 11:00:00, 2h
A task within : 12:05:00, 60m
A task starting within and ending after: 17:30:00, 75m
A task after : 18:30:00, 30m
section Another
A task before : 10:00:00, 119m
A task within : 12:00:00, 6h
A task after : 20:00:00, 4h
`,
{}
);
});

it('should render when there is a date and time dateRange, with both start and end dates, and tasks before and after the dateRange', () => {
imgSnapshotTest(
`gantt
title Gantt diagram with time-only date range and tasks before and after the date range
dateFormat DD-MM-YYYY HH:mm:ss
dateRange 01-01-2021 12:00:00, 08-01-2021 18:00:00
axisFormat %m-%d
tickInterval 1week
section Section
A task before : 01-01-2021 11:30:00, 25m
A task starting before and completing within: 01-01-2021 10:00:00, 2d
A task within : 02-01-2021 12:05:00, 4d
A task starting within and ending after: 05-01-2021 12:30:00, 4d
A task after : 08-01-2021 18:30:00, 30m
section Another
A task before : 31-12-2020 10:00:00, 1d
A task within : 01-01-2021 12:00:00, 7d
A task after : 15-01-2021 12:00:00, 1d
`,
{}
);
});

// TODO: fix it
//
// This test is skipped deliberately
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/rendering/theme.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ erDiagram
accTitle: This is a title
accDescr: This is a description

dateFormat :YYYY-MM-DD
title :Adding GANTT diagram functionality to mermaid
dateFormat YYYY-MM-DD
title Adding GANTT diagram functionality to mermaid
excludes :excludes the named dates/days from being included in a charted task..
section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Expand Down
6 changes: 6 additions & 0 deletions docs/community/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ it('should render forks and joins', () => {
});
```

**Verifying Snapshots**

```sh
pnpm e2e open cypress/snapshots
```

<!-- **_[TODO - running the tests against what is expected in development. ]_** -->

<!-- **_[TODO - how to generate new screenshots]_** -->
Expand Down
30 changes: 30 additions & 0 deletions docs/syntax/gantt.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,36 @@ gantt

> **Warning** > `millisecond` and `second` support was added in v10.3.0

### Date Ranges (v\<MERMAID_RELEASE_VERSION>+)

The default behavior is to set the x range to include all of the data in the chart. You can override
the range by specifying `dateRange`. Any tasks falling outside the specified range will be removed
from the plot, and tasks overlapping with the boundaries will be truncated. The `dateRange` command
should follow the `dateFormat` and use the same format.

```mermaid-example
gantt
dateFormat HH:mm
dateRange 13:00, 14:00
axisFormat %H:%M
Task A : 13:24, 13:39
Task B : 13:50, 14:35
Dropped : 14:01, 14:20
```

```mermaid
gantt
dateFormat HH:mm
dateRange 13:00, 14:00
axisFormat %H:%M
Task A : 13:24, 13:39
Task B : 13:50, 14:35
Dropped : 14:01, 14:20
```

It is also possible to specify only a lower bound using `dateRange <date>` or only an upper bound
using `dateRange ,<date>`.

## Output in compact mode

The compact mode allows you to display multiple tasks in the same row. Compact mode can be enabled for a gantt chart by setting the display mode of the graph via preceding YAML settings.
Expand Down
Loading
Loading