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

Added support for millisecond and second to gantt tickInterval #4778

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions cypress/integration/rendering/gantt.spec.js
Expand Up @@ -330,6 +330,48 @@ describe('Gantt diagram', () => {
);
});

it('should render a gantt diagram with tick is 2 milliseconds', () => {
imgSnapshotTest(
`
gantt
title A Gantt Diagram
dateFormat SSS
axisFormat %Lms
tickInterval 2millisecond
excludes weekends

section Section
A task : a1, 000, 6ms
Another task : after a1, 6ms
section Another
Task in sec : a2, 006, 3ms
another task : 3ms
`,
{}
);
});

it('should render a gantt diagram with tick is 2 seconds', () => {
imgSnapshotTest(
`
gantt
title A Gantt Diagram
dateFormat ss
axisFormat %Ss
tickInterval 2second
excludes weekends

section Section
A task : a1, 00, 6s
Another task : after a1, 6s
section Another
Task in sec : 06, 3s
another task : 3s
`,
{}
);
});

it('should render a gantt diagram with tick is 15 minutes', () => {
imgSnapshotTest(
`
Expand Down
6 changes: 3 additions & 3 deletions docs/syntax/gantt.md
Expand Up @@ -241,7 +241,7 @@ The following formatting strings are supported:

More info in: <https://github.com/d3/d3-time-format/tree/v4.0.0#locale_format>

### Axis ticks
### Axis ticks (v10.3.0+)

The default output ticks are auto. You can custom your `tickInterval`, like `1day` or `1week`.

Expand All @@ -252,7 +252,7 @@ tickInterval 1day
The pattern is:

```javascript
/^([1-9][0-9]*)(minute|hour|day|week|month)$/;
/^([1-9][0-9]*)(millisecond|second|minute|hour|day|week|month)$/;
```

More info in: <https://github.com/d3/d3-time#interval_every>
Expand All @@ -271,7 +271,7 @@ gantt
weekday monday
```

Support: v10.3.0+
> **Warning** > `millisecond` and `second` support was added in vMERMAID_RELEASE_VERSION

## Output in compact mode

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/config.type.ts
Expand Up @@ -1048,7 +1048,7 @@ export interface GanttDiagramConfig extends BaseDiagramConfig {
* Pattern is:
*
* ```javascript
* /^([1-9][0-9]*)(minute|hour|day|week|month)$/
* /^([1-9][0-9]*)(millisecond|second|minute|hour|day|week|month)$/
* ```
*
*/
Expand Down
16 changes: 15 additions & 1 deletion packages/mermaid/src/diagrams/gantt/ganttRenderer.js
Expand Up @@ -10,6 +10,8 @@
axisBottom,
axisTop,
timeFormat,
timeMillisecond,
timeSecond,
timeMinute,
timeHour,
timeDay,
Expand Down Expand Up @@ -573,7 +575,7 @@
.tickSize(-h + theTopPad + conf.gridLineStartPadding)
.tickFormat(timeFormat(diagObj.db.getAxisFormat() || conf.axisFormat || '%Y-%m-%d'));

const reTickInterval = /^([1-9]\d*)(minute|hour|day|week|month)$/;
const reTickInterval = /^([1-9]\d*)(millisecond|second|minute|hour|day|week|month)$/;
const resultTickInterval = reTickInterval.exec(
diagObj.db.getTickInterval() || conf.tickInterval
);
Expand All @@ -584,6 +586,12 @@
const weekday = diagObj.db.getWeekday() || conf.weekday;

switch (interval) {
case 'millisecond':
bottomXAxis.ticks(timeMillisecond.every(every));
break;
case 'second':
bottomXAxis.ticks(timeSecond.every(every));
break;
case 'minute':
bottomXAxis.ticks(timeMinute.every(every));
break;
Expand Down Expand Up @@ -625,6 +633,12 @@
const weekday = diagObj.db.getWeekday() || conf.weekday;

switch (interval) {
case 'millisecond':
topXAxis.ticks(timeMillisecond.every(every));
break;

Check warning on line 638 in packages/mermaid/src/diagrams/gantt/ganttRenderer.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/gantt/ganttRenderer.js#L637-L638

Added lines #L637 - L638 were not covered by tests
case 'second':
topXAxis.ticks(timeSecond.every(every));
break;

Check warning on line 641 in packages/mermaid/src/diagrams/gantt/ganttRenderer.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/gantt/ganttRenderer.js#L640-L641

Added lines #L640 - L641 were not covered by tests
case 'minute':
topXAxis.ticks(timeMinute.every(every));
break;
Expand Down
8 changes: 5 additions & 3 deletions packages/mermaid/src/docs/syntax/gantt.md
Expand Up @@ -173,7 +173,7 @@ The following formatting strings are supported:

More info in: [https://github.com/d3/d3-time-format/tree/v4.0.0#locale_format](https://github.com/d3/d3-time-format/tree/v4.0.0#locale_format)

### Axis ticks
### Axis ticks (v10.3.0+)

The default output ticks are auto. You can custom your `tickInterval`, like `1day` or `1week`.

Expand All @@ -184,7 +184,7 @@ tickInterval 1day
The pattern is:

```javascript
/^([1-9][0-9]*)(minute|hour|day|week|month)$/;
/^([1-9][0-9]*)(millisecond|second|minute|hour|day|week|month)$/;
sidharthv96 marked this conversation as resolved.
Show resolved Hide resolved
```

More info in: [https://github.com/d3/d3-time#interval_every](https://github.com/d3/d3-time#interval_every)
Expand All @@ -197,7 +197,9 @@ gantt
weekday monday
```

Support: v10.3.0+
```warning
`millisecond` and `second` support was added in vMERMAID_RELEASE_VERSION
```

## Output in compact mode

Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/schemas/config.schema.yaml
Expand Up @@ -1524,10 +1524,10 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
Pattern is:

```javascript
/^([1-9][0-9]*)(minute|hour|day|week|month)$/
/^([1-9][0-9]*)(millisecond|second|minute|hour|day|week|month)$/
```
type: string
pattern: ^([1-9][0-9]*)(minute|hour|day|week|month)$
pattern: ^([1-9][0-9]*)(millisecond|second|minute|hour|day|week|month)$
topAxis:
description: |
When this flag is set, date labels will be added to the top of the chart
Expand Down