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", () => {
|
||||
imgSnapshotTest(
|
||||
`
|
||||
|
@@ -554,12 +554,14 @@ export const draw = function (text, id, version, diagObj) {
|
||||
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 = [];
|
||||
let range = null;
|
||||
let d = dayjs(minTime);
|
||||
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) {
|
||||
range = {
|
||||
start: d,
|
||||
@@ -581,17 +583,11 @@ export const draw = function (text, id, version, diagObj) {
|
||||
|
||||
rectangles
|
||||
.append('rect')
|
||||
.attr('id', function (d) {
|
||||
return 'exclude-' + d.start.format('YYYY-MM-DD');
|
||||
})
|
||||
.attr('x', function (d) {
|
||||
return timeScale(d.start) + theSidePad;
|
||||
})
|
||||
.attr('id', (d) => 'exclude-' + d.start.format('YYYY-MM-DD'))
|
||||
.attr('x', (d) => timeScale(d.start.startOf('day')) + theSidePad)
|
||||
.attr('y', conf.gridLineStartPadding)
|
||||
.attr('width', function (d) {
|
||||
const renderEnd = d.end.add(1, 'day');
|
||||
return timeScale(renderEnd) - timeScale(d.start);
|
||||
})
|
||||
.attr('width', (d) => timeScale(d.end.endOf('day')) - timeScale(d.start.startOf('day')))
|
||||
|
||||
.attr('height', h - theTopPad - conf.gridLineStartPadding)
|
||||
.attr('transform-origin', function (d, i) {
|
||||
return (
|
||||
|
Reference in New Issue
Block a user