mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00
fix excluded dates ignored in YYYY-MM-DD HH:mm:ss date format
This commit is contained in:
@@ -647,6 +647,20 @@ describe('Gantt diagram', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render a gantt diagram excluding a specific date in YYYY-MM-DD HH:mm:ss format', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
dateFormat YYYY-MM-DD HH:mm:ss
|
||||||
|
excludes 2025-07-07
|
||||||
|
section Section
|
||||||
|
A task :a1, 2025-07-04 20:30:30, 2025-07-08 10:30:30
|
||||||
|
Another task:after a1, 20h
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("should render when there's a semicolon in the title", () => {
|
it("should render when there's a semicolon in the title", () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
|
@@ -554,12 +554,14 @@ export const draw = function (text, id, version, diagObj) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateFormat = diagObj.db.getDateFormat();
|
const normalizedExcludes = excludes.map((d) => dayjs(d).format('YYYY-MM-DD'));
|
||||||
|
const normalizedIncludes = includes.map((d) => dayjs(d).format('YYYY-MM-DD'));
|
||||||
const excludeRanges = [];
|
const excludeRanges = [];
|
||||||
let range = null;
|
let range = null;
|
||||||
let d = dayjs(minTime);
|
let d = dayjs(minTime);
|
||||||
while (d.valueOf() <= maxTime) {
|
while (d.valueOf() <= maxTime) {
|
||||||
if (diagObj.db.isInvalidDate(d, dateFormat, excludes, includes)) {
|
const dStr = d.format('YYYY-MM-DD');
|
||||||
|
if (normalizedExcludes.includes(dStr) && !normalizedIncludes.includes(dStr)) {
|
||||||
if (!range) {
|
if (!range) {
|
||||||
range = {
|
range = {
|
||||||
start: d,
|
start: d,
|
||||||
@@ -581,17 +583,11 @@ export const draw = function (text, id, version, diagObj) {
|
|||||||
|
|
||||||
rectangles
|
rectangles
|
||||||
.append('rect')
|
.append('rect')
|
||||||
.attr('id', function (d) {
|
.attr('id', (d) => 'exclude-' + d.start.format('YYYY-MM-DD'))
|
||||||
return 'exclude-' + d.start.format('YYYY-MM-DD');
|
.attr('x', (d) => timeScale(d.start.startOf('day')) + theSidePad)
|
||||||
})
|
|
||||||
.attr('x', function (d) {
|
|
||||||
return timeScale(d.start) + theSidePad;
|
|
||||||
})
|
|
||||||
.attr('y', conf.gridLineStartPadding)
|
.attr('y', conf.gridLineStartPadding)
|
||||||
.attr('width', function (d) {
|
.attr('width', (d) => timeScale(d.end.endOf('day')) - timeScale(d.start.startOf('day')))
|
||||||
const renderEnd = d.end.add(1, 'day');
|
|
||||||
return timeScale(renderEnd) - timeScale(d.start);
|
|
||||||
})
|
|
||||||
.attr('height', h - theTopPad - conf.gridLineStartPadding)
|
.attr('height', h - theTopPad - conf.gridLineStartPadding)
|
||||||
.attr('transform-origin', function (d, i) {
|
.attr('transform-origin', function (d, i) {
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user