From cafe932cbc3e1af9a1a0d106f599fcf06f73bda5 Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Mon, 22 Jan 2024 20:11:27 +0000 Subject: [PATCH 01/11] implement until keyword in gantt charts --- docs/syntax/gantt.md | 13 +++-- .../mermaid/src/diagrams/gantt/ganttDb.js | 29 ++++++++++ .../src/diagrams/gantt/ganttDb.spec.ts | 56 ++++++++++++++++++- packages/mermaid/src/docs/syntax/gantt.md | 9 ++- 4 files changed, 99 insertions(+), 8 deletions(-) diff --git a/docs/syntax/gantt.md b/docs/syntax/gantt.md index 07fc897ec1..08d24c036f 100644 --- a/docs/syntax/gantt.md +++ b/docs/syntax/gantt.md @@ -67,8 +67,8 @@ gantt Create tests for parser :crit, active, 3d Future task in critical line :crit, 5d Create tests for renderer :2d - Add to mermaid :1d - Functionality added :milestone, 2014-01-25, 0d + Add to mermaid :until isadded + Functionality added :milestone, isadded, 2014-01-25, 0d section Documentation Describe gantt syntax :active, a1, after des1, 3d @@ -100,8 +100,8 @@ gantt Create tests for parser :crit, active, 3d Future task in critical line :crit, 5d Create tests for renderer :2d - Add to mermaid :1d - Functionality added :milestone, 2014-01-25, 0d + Add to mermaid :until isadded + Functionality added :milestone, isadded, 2014-01-25, 0d section Documentation Describe gantt syntax :active, a1, after des1, 3d @@ -114,6 +114,9 @@ gantt Add another diagram to demo page :48h ``` +> **Note** +> Support for keyword `until` was added in (v\+). This can be used to define a task which is running until some other specific task or milestone starts. + It is possible to set multiple dependencies separated by space: ```mermaid-example @@ -121,6 +124,7 @@ gantt apple :a, 2017-07-20, 1w banana :crit, b, 2017-07-23, 1d cherry :active, c, after b a, 1d + kiwi :d, 2017-07-20, until b c ``` ```mermaid @@ -128,6 +132,7 @@ gantt apple :a, 2017-07-20, 1w banana :crit, b, 2017-07-23, 1d cherry :active, c, after b a, 1d + kiwi :d, 2017-07-20, until b c ``` ### Title diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.js b/packages/mermaid/src/diagrams/gantt/ganttDb.js index 1c73a13ea9..4b70f7e85f 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.js +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.js @@ -343,6 +343,35 @@ const parseDuration = function (str) { const getEndDate = function (prevTime, dateFormat, str, inclusive = false) { str = str.trim(); + // Test for until + const re = /^until\s+([\d\w- ]+)/; + const untilStatement = re.exec(str.trim()); + + if (untilStatement !== null) { + // check all until ids and take the earliest + let earliestStartingTask = null; + untilStatement[1].split(' ').forEach(function (id) { + let task = findTaskById(id); + if (task !== undefined) { + if (!earliestStartingTask) { + earliestStartingTask = task; + } else { + if (task.startTime < earliestStartingTask.startTime) { + earliestStartingTask = task; + } + } + } + }); + + if (!earliestStartingTask) { + const dt = new Date(); + dt.setHours(0, 0, 0, 0); + return dt; + } else { + return earliestStartingTask.startTime; + } + } + // Check for actual date let mDate = dayjs(str, dateFormat.trim(), true); if (mDate.isValid()) { diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts index 416368e8f9..e055e2d958 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts @@ -140,10 +140,10 @@ describe('when using the ganttDb', function () { it('should handle relative start date based on id regardless of sections', function () { ganttDb.setDateFormat('YYYY-MM-DD'); - ganttDb.addSection('testa1'); + ganttDb.addSection('sec1'); ganttDb.addTask('test1', 'id1,2013-01-01,2w'); ganttDb.addTask('test2', 'id2,after id3,1d'); - ganttDb.addSection('testa2'); + ganttDb.addSection('sec2'); ganttDb.addTask('test3', 'id3,after id1,2d'); const tasks = ganttDb.getTasks(); @@ -158,6 +158,58 @@ describe('when using the ganttDb', function () { expect(tasks[2].startTime).toEqual(new Date(2013, 0, 15)); expect(tasks[2].endTime).toEqual(new Date(2013, 0, 17)); }); + + it('should handle relative end date based on id regardless of sections', function () { + ganttDb.setDateFormat('YYYY-MM-DD'); + ganttDb.addSection('sec1'); + ganttDb.addTask('task1', 'id1,2013-01-01,until id3'); + ganttDb.addSection('sec2'); + ganttDb.addTask('task2', 'id2,2013-01-10,until id3'); + ganttDb.addTask('task3', 'id3,2013-02-01,2d'); + + const tasks = ganttDb.getTasks(); + + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)); + expect(tasks[0].endTime).toEqual(new Date(2013, 1, 1)); + expect(tasks[0].id).toEqual('id1'); + expect(tasks[0].task).toEqual('task1'); + + expect(tasks[1].id).toEqual('id2'); + expect(tasks[1].task).toEqual('task2'); + expect(tasks[1].startTime).toEqual(new Date(2013, 0, 10)); + expect(tasks[1].endTime).toEqual(new Date(2013, 1, 1)); + }); + + it('should handle relative start date based on multiple id', function () { + ganttDb.setDateFormat('YYYY-MM-DD'); + ganttDb.addSection('sec1'); + ganttDb.addTask('task1', 'id1,after id2 id3 id4,1d'); + ganttDb.addTask('task2', 'id2,2013-01-01,1d'); + ganttDb.addTask('task3', 'id3,2013-02-01,3d'); + ganttDb.addTask('task4', 'id4,2013-02-01,2d'); + + const tasks = ganttDb.getTasks(); + + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 2)); + expect(tasks[0].id).toEqual('id1'); + expect(tasks[0].task).toEqual('task1'); + }); + + it('should handle relative end date based on multiple id', function () { + ganttDb.setDateFormat('YYYY-MM-DD'); + ganttDb.addSection('sec1'); + ganttDb.addTask('task1', 'id1,2013-01-01,until id2 id3 id4'); + ganttDb.addTask('task2', 'id2,2013-01-11,1d'); + ganttDb.addTask('task3', 'id3,2013-02-10,1d'); + ganttDb.addTask('task4', 'id4,2013-02-12,1d'); + + const tasks = ganttDb.getTasks(); + + expect(tasks[0].endTime).toEqual(new Date(2013, 1, 10)); + expect(tasks[0].id).toEqual('id1'); + expect(tasks[0].task).toEqual('task1'); + }); + it('should ignore weekends', function () { ganttDb.setDateFormat('YYYY-MM-DD'); ganttDb.setExcludes('weekends 2019-02-06,friday'); diff --git a/packages/mermaid/src/docs/syntax/gantt.md b/packages/mermaid/src/docs/syntax/gantt.md index 6940f882fd..cde1a5504e 100644 --- a/packages/mermaid/src/docs/syntax/gantt.md +++ b/packages/mermaid/src/docs/syntax/gantt.md @@ -49,8 +49,8 @@ gantt Create tests for parser :crit, active, 3d Future task in critical line :crit, 5d Create tests for renderer :2d - Add to mermaid :1d - Functionality added :milestone, 2014-01-25, 0d + Add to mermaid :until isadded + Functionality added :milestone, isadded, 2014-01-25, 0d section Documentation Describe gantt syntax :active, a1, after des1, 3d @@ -63,6 +63,10 @@ gantt Add another diagram to demo page :48h ``` +```note +Support for keyword `until` was added in (v+). This can be used to define a task which is running until some other specific task or milestone starts. +``` + It is possible to set multiple dependencies separated by space: ```mermaid-example @@ -70,6 +74,7 @@ gantt apple :a, 2017-07-20, 1w banana :crit, b, 2017-07-23, 1d cherry :active, c, after b a, 1d + kiwi :d, 2017-07-20, until b c ``` ### Title From b44ec7daddf7d4ee4d66b9bfacffbe2281735758 Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Mon, 22 Jan 2024 21:46:52 +0000 Subject: [PATCH 02/11] fix bad expected values in gantt units tests --- packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts index e055e2d958..96aae0b89c 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts @@ -190,7 +190,7 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks(); - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 2)); + expect(tasks[0].endTime).toEqual(new Date(2013, 1, 5)); expect(tasks[0].id).toEqual('id1'); expect(tasks[0].task).toEqual('task1'); }); @@ -205,7 +205,7 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks(); - expect(tasks[0].endTime).toEqual(new Date(2013, 1, 10)); + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 11)); expect(tasks[0].id).toEqual('id1'); expect(tasks[0].task).toEqual('task1'); }); From 099f580e520a9721deae8b543f06e97bbe9b98d1 Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Wed, 24 Jan 2024 09:30:21 +0000 Subject: [PATCH 03/11] address review comment on implementation; apply similar changes on existing impl of keyword 'after' --- .../mermaid/src/diagrams/gantt/ganttDb.js | 72 ++++++++----------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.js b/packages/mermaid/src/diagrams/gantt/ganttDb.js index 4b70f7e85f..b54fe821c7 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.js +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.js @@ -256,31 +256,25 @@ const getStartDate = function (prevTime, dateFormat, str) { str = str.trim(); // Test for after - const re = /^after\s+([\d\w- ]+)/; - const afterStatement = re.exec(str.trim()); + const afterRePattern = /^after\s+(?[\d\w- ]+)/; + const afterStatement = afterRePattern.exec(str); if (afterStatement !== null) { // check all after ids and take the latest - let latestEndingTask = null; - afterStatement[1].split(' ').forEach(function (id) { + let latestTask = null; + for (const id of afterStatement.groups.ids.split(' ')) { let task = findTaskById(id); - if (task !== undefined) { - if (!latestEndingTask) { - latestEndingTask = task; - } else { - if (task.endTime > latestEndingTask.endTime) { - latestEndingTask = task; - } - } + if (task !== undefined && (!latestTask || task.endTime > latestTask.endTime)) { + latestTask = task; } - }); + } - if (!latestEndingTask) { - const dt = new Date(); - dt.setHours(0, 0, 0, 0); - return dt; + if (latestTask) { + return latestTask.endTime; } else { - return latestEndingTask.endTime; + const today = new Date(); + today.setHours(0, 0, 0, 0); + return today; } } @@ -343,42 +337,36 @@ const parseDuration = function (str) { const getEndDate = function (prevTime, dateFormat, str, inclusive = false) { str = str.trim(); - // Test for until - const re = /^until\s+([\d\w- ]+)/; - const untilStatement = re.exec(str.trim()); + // test for until + const untilRePattern = /^until\s+(?[\d\w- ]+)/; + const untilStatement = untilRePattern.exec(str); if (untilStatement !== null) { // check all until ids and take the earliest - let earliestStartingTask = null; - untilStatement[1].split(' ').forEach(function (id) { + let earliestTask = null; + for (const id of untilStatement.groups.ids.split(' ')) { let task = findTaskById(id); - if (task !== undefined) { - if (!earliestStartingTask) { - earliestStartingTask = task; - } else { - if (task.startTime < earliestStartingTask.startTime) { - earliestStartingTask = task; - } - } + if (task !== undefined && (!earliestTask || task.startTime < earliestTask.startTime)) { + earliestTask = task; } - }); + } - if (!earliestStartingTask) { - const dt = new Date(); - dt.setHours(0, 0, 0, 0); - return dt; + if (earliestTask) { + return earliestTask.startTime; } else { - return earliestStartingTask.startTime; + const today = new Date(); + today.setHours(0, 0, 0, 0); + return today; } } - // Check for actual date - let mDate = dayjs(str, dateFormat.trim(), true); - if (mDate.isValid()) { + // check for actual date + let parsedDate = dayjs(str, dateFormat.trim(), true); + if (parsedDate.isValid()) { if (inclusive) { - mDate = mDate.add(1, 'd'); + parsedDate = parsedDate.add(1, 'd'); } - return mDate.toDate(); + return parsedDate.toDate(); } let endTime = dayjs(prevTime); From fd3f1caff6c43e8bc39a6700e2058cea735bae88 Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Sat, 27 Jan 2024 11:27:28 +0000 Subject: [PATCH 04/11] add parsing unit test for after/until keywords --- .../src/diagrams/gantt/parser/gantt.spec.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js b/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js index e7ce1ffa4f..8146affacc 100644 --- a/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js +++ b/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js @@ -82,6 +82,38 @@ describe('when parsing a gantt diagram it', function () { expect(tasks[0].id).toEqual('des1'); expect(tasks[0].task).toEqual('Design jison grammar'); }); + it('should handle a task with start/end time relative to other tasks', function () { + const str = + 'gantt\n' + + 'dateFormat YYYY-MM-DD\n' + + 'title Adding gantt diagram functionality to mermaid\n' + + 'section Documentation\n' + + 'task A: a, 2024-01-27, 2024-01-28\n' + + 'task B: b, after a, 2024-01-30\n' + + 'task C: c, 2024-01-20, until a\n' + + 'task D: d, after c, until b'; + + expect(parserFnConstructor(str)).not.toThrow(); + + const tasks = parser.yy.getTasks(); + + expect(tasks[0].startTime).toEqual(new Date(2024, 0, 27)); + expect(tasks[0].endTime).toEqual(new Date(2024, 0, 28)); + expect(tasks[0].id).toEqual('b'); + expect(tasks[0].task).toEqual('task B'); + expect(tasks[1].startTime).toEqual(new Date(2024, 0, 28)); + expect(tasks[1].endTime).toEqual(new Date(2024, 0, 30)); + expect(tasks[1].id).toEqual('b'); + expect(tasks[1].task).toEqual('task B'); + expect(tasks[2].startTime).toEqual(new Date(2024, 0, 20)); + expect(tasks[2].endTime).toEqual(new Date(2024, 0, 27)); + expect(tasks[2].id).toEqual('c'); + expect(tasks[2].task).toEqual('task C'); + expect(tasks[3].startTime).toEqual(new Date(2024, 0, 27)); + expect(tasks[3].endTime).toEqual(new Date(2024, 0, 28)); + expect(tasks[3].id).toEqual('d'); + expect(tasks[3].task).toEqual('task D'); + }); it.each(convert` tags | milestone | done | crit | active ${'milestone'} | ${true} | ${false} | ${false} | ${false} From 9fadf621a826ba429e72b6ca2ca817da42251574 Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Sat, 27 Jan 2024 12:05:23 +0000 Subject: [PATCH 05/11] adapt e2e tests to include new 'until' keyword in gantt chart --- cypress/integration/rendering/gantt.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index 73ff4ee005..e045691ef1 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -25,7 +25,8 @@ describe('Gantt diagram', () => { Create tests for parser :crit, active, 3d Future task in critical line :crit, 5d Create tests for renderer :2d - Add to mermaid :1d + Add to mermaid :adding, 1d + Thinking about adding to mermaid :after des1, until adding section Documentation Describe gantt syntax :active, a1, after des1, 3d @@ -88,6 +89,7 @@ describe('Gantt diagram', () => { apple :a, 2017-07-20, 1w banana :crit, b, 2017-07-23, 1d cherry :active, c, after b a, 1d + kiwi :d, 2017-07-20, until b c `, {} ); From cc4dfeab1a5c3e4cb0ba069820f7d018928c398f Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Sat, 27 Jan 2024 12:32:15 +0000 Subject: [PATCH 06/11] fix minor mistake in parsing test --- packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js b/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js index dc5ee4de90..6665765a4b 100644 --- a/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js +++ b/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js @@ -135,8 +135,8 @@ describe('when parsing a gantt diagram it', function () { expect(tasks[0].startTime).toEqual(new Date(2024, 0, 27)); expect(tasks[0].endTime).toEqual(new Date(2024, 0, 28)); - expect(tasks[0].id).toEqual('b'); - expect(tasks[0].task).toEqual('task B'); + expect(tasks[0].id).toEqual('a'); + expect(tasks[0].task).toEqual('task A'); expect(tasks[1].startTime).toEqual(new Date(2024, 0, 28)); expect(tasks[1].endTime).toEqual(new Date(2024, 0, 30)); expect(tasks[1].id).toEqual('b'); From c1b5d527df06a7305401749ab327fac3a7b4c59b Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Sat, 27 Jan 2024 13:24:12 +0000 Subject: [PATCH 07/11] modify invalid e2e test for gantt chart --- cypress/integration/rendering/gantt.spec.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index 73ebc325fd..e14f0815dc 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -14,19 +14,18 @@ describe('Gantt diagram', () => { excludes weekdays 2014-01-10 section A section - Completed task :done, des1, 2014-01-06,2014-01-08 - Active task :active, des2, 2014-01-09, 3d - Future task : des3, after des2, 5d - Future task2 : des4, after des3, 5d + Completed task :done, des1, 2014-01-06,2014-01-08 + Active task :active, des2, 2014-01-09, 3d + Future task :des3, after des2, 5d + Future task2 :des4, after des3, 5d + Waiting for task 2 :after des1, until des4 section Critical tasks Completed task in the critical line :crit, done, 2014-01-06,24h - Implement parser and jison :crit, done, after des1, 2d + Implement parser and jison :crit, done, after des1, 2d Create tests for parser :crit, active, 3d Future task in critical line :crit, 5d Create tests for renderer :2d - Add to mermaid :adding, 1d - Thinking about adding to mermaid :after des1, until adding section Documentation Describe gantt syntax :active, a1, after des1, 3d From 069a132fe1906adc1dcd08ba0eeda91a1da7b3f6 Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Sat, 27 Jan 2024 16:05:35 +0000 Subject: [PATCH 08/11] revert changes on existing e2e tests; add new e2e test for nez until keyword --- cypress/integration/rendering/gantt.spec.js | 38 +++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index e14f0815dc..7566110082 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -14,18 +14,18 @@ describe('Gantt diagram', () => { excludes weekdays 2014-01-10 section A section - Completed task :done, des1, 2014-01-06,2014-01-08 - Active task :active, des2, 2014-01-09, 3d - Future task :des3, after des2, 5d - Future task2 :des4, after des3, 5d - Waiting for task 2 :after des1, until des4 + Completed task :done, des1, 2014-01-06,2014-01-08 + Active task :active, des2, 2014-01-09, 3d + Future task : des3, after des2, 5d + Future task2 : des4, after des3, 5d section Critical tasks Completed task in the critical line :crit, done, 2014-01-06,24h - Implement parser and jison :crit, done, after des1, 2d + Implement parser and jison :crit, done, after des1, 2d Create tests for parser :crit, active, 3d Future task in critical line :crit, 5d Create tests for renderer :2d + Add to mermaid :1d section Documentation Describe gantt syntax :active, a1, after des1, 3d @@ -88,7 +88,31 @@ describe('Gantt diagram', () => { apple :a, 2017-07-20, 1w banana :crit, b, 2017-07-23, 1d cherry :active, c, after b a, 1d - kiwi :d, 2017-07-20, until b c + `, + {} + ); + }); + it('should handle multiple dependencies syntax with after and until', () => { + imgSnapshotTest( + ` + gantt + dateFormat YYYY-MM-DD + axisFormat %d/%m + title Adding GANTT diagram to mermaid + excludes weekdays 2014-01-10 + todayMarker off + + section team's critical event + deadline A :milestone, crit, deadlineA, 2024-02-01, 0 + deadline B :milestone, crit, deadlineB, 2024-02-15, 0 + boss on leave :bossaway, 2024-01-28, 2024-02-11 + + section new intern + onboarding :onboarding, 2024-01-02, 1w + literature review :litreview, 2024-01-02, 10d + project A :projectA, after onboarding litreview, until deadlineA bossaway + chilling :chilling, after projectA, until deadlineA + project B :projectB, after deadlineA, until deadlineB `, {} ); From 8d2605d5374a290644e4e69270423ab451d6fc62 Mon Sep 17 00:00:00 2001 From: Franck Zagala Date: Sat, 27 Jan 2024 16:33:57 +0000 Subject: [PATCH 09/11] minor stylistic changes --- packages/mermaid/src/diagrams/gantt/ganttDb.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.js b/packages/mermaid/src/diagrams/gantt/ganttDb.js index b54fe821c7..7a9194e2f0 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.js +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.js @@ -271,11 +271,10 @@ const getStartDate = function (prevTime, dateFormat, str) { if (latestTask) { return latestTask.endTime; - } else { - const today = new Date(); - today.setHours(0, 0, 0, 0); - return today; } + const today = new Date(); + today.setHours(0, 0, 0, 0); + return today; } // Check for actual date set @@ -353,11 +352,10 @@ const getEndDate = function (prevTime, dateFormat, str, inclusive = false) { if (earliestTask) { return earliestTask.startTime; - } else { - const today = new Date(); - today.setHours(0, 0, 0, 0); - return today; } + const today = new Date(); + today.setHours(0, 0, 0, 0); + return today; } // check for actual date From 4336b91dbd7053d8ce5d9e298022a8accf72b852 Mon Sep 17 00:00:00 2001 From: Bruno Macherel Date: Tue, 19 Dec 2023 10:35:15 +0100 Subject: [PATCH 10/11] Fix color and arrow for merge commit --- .../integration/rendering/gitGraph.spec.js | 70 +++++++++++++++ .../src/diagrams/git/gitGraphRenderer.js | 89 ++++++++++--------- 2 files changed, 117 insertions(+), 42 deletions(-) diff --git a/cypress/integration/rendering/gitGraph.spec.js b/cypress/integration/rendering/gitGraph.spec.js index 19ddde31d4..60800e809b 100644 --- a/cypress/integration/rendering/gitGraph.spec.js +++ b/cypress/integration/rendering/gitGraph.spec.js @@ -943,4 +943,74 @@ gitGraph TB: { gitGraph: { parallelCommits: true } } ); }); + it('46: should render GitGraph with merge back and merge forward', () => { + imgSnapshotTest( + `gitGraph LR: + commit + + branch branch-A + branch branch-B + commit + + checkout branch-A + merge branch-B + + checkout branch-B + merge branch-A + `, + { gitGraph: { parallelCommits: true } } + ); + }); + it('47: should render GitGraph with merge back and merge forward | Vertical Branch', () => { + imgSnapshotTest( + `gitGraph TB: + commit + + branch branch-A + branch branch-B + commit + + checkout branch-A + merge branch-B + + checkout branch-B + merge branch-A + `, + { gitGraph: { parallelCommits: true } } + ); + }); + it('48: should render GitGraph with merge on a new branch | Vertical Branch', () => { + imgSnapshotTest( + `gitGraph LR: + commit + + branch branch-B order: 2 + commit + + branch branch-A + merge main + + checkout branch-B + merge branch-A + `, + { gitGraph: { parallelCommits: true } } + ); + }); + it('49: should render GitGraph with merge on a new branch | Vertical Branch', () => { + imgSnapshotTest( + `gitGraph TB: + commit + + branch branch-B order: 2 + commit + + branch branch-A + merge main + + checkout branch-B + merge branch-A + `, + { gitGraph: { parallelCommits: true } } + ); + }); }); diff --git a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js index 84b8f41a16..fbcaa547a4 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js +++ b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js @@ -456,6 +456,10 @@ const drawArrow = (svg, commitA, commitB, allCommits) => { let radius = 0; let offset = 0; let colorClassNum = branchPos[commitB.branch].index; + if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) { + colorClassNum = branchPos[commitA.branch].index; + } + let lineDef; if (arrowNeedsRerouting) { arc = 'A 10 10, 0, 0, 0,'; @@ -470,7 +474,6 @@ const drawArrow = (svg, commitA, commitB, allCommits) => { if (p1.x < p2.x) { // Source commit is on branch position left of destination commit // so render arrow rightward with colour of destination branch - colorClassNum = branchPos[commitB.branch].index; lineDef = `M ${p1.x} ${p1.y} L ${lineX - radius} ${p1.y} ${arc2} ${lineX} ${ p1.y + offset } L ${lineX} ${p2.y - radius} ${arc} ${lineX + offset} ${p2.y} L ${p2.x} ${p2.y}`; @@ -486,7 +489,6 @@ const drawArrow = (svg, commitA, commitB, allCommits) => { if (p1.y < p2.y) { // Source commit is on branch positioned above destination commit // so render arrow downward with colour of destination branch - colorClassNum = branchPos[commitB.branch].index; lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${lineY - radius} ${arc} ${ p1.x + offset } ${lineY} L ${p2.x - radius} ${lineY} ${arc2} ${p2.x} ${lineY + offset} L ${p2.x} ${p2.y}`; @@ -500,19 +502,22 @@ const drawArrow = (svg, commitA, commitB, allCommits) => { } } } else { + arc = 'A 20 20, 0, 0, 0,'; + arc2 = 'A 20 20, 0, 0, 1,'; + radius = 20; + offset = 20; + if (dir === 'TB') { if (p1.x < p2.x) { - arc = 'A 20 20, 0, 0, 0,'; - arc2 = 'A 20 20, 0, 0, 1,'; - radius = 20; - offset = 20; - - // Figure out the color of the arrow,arrows going down take the color from the destination branch - colorClassNum = branchPos[commitB.branch].index; - - lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${ - p1.y + offset - } L ${p2.x} ${p2.y}`; + if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) { + lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc} ${p1.x + offset} ${ + p2.y + } L ${p2.x} ${p2.y}`; + } else { + lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${ + p1.y + offset + } L ${p2.x} ${p2.y}`; + } } if (p1.x > p2.x) { arc = 'A 20 20, 0, 0, 0,'; @@ -520,46 +525,46 @@ const drawArrow = (svg, commitA, commitB, allCommits) => { radius = 20; offset = 20; - // Arrows going up take the color from the source branch - colorClassNum = branchPos[commitA.branch].index; - lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc2} ${p1.x - offset} ${ - p2.y - } L ${p2.x} ${p2.y}`; + if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) { + lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc2} ${p1.x - offset} ${ + p2.y + } L ${p2.x} ${p2.y}`; + } else { + lineDef = `M ${p1.x} ${p1.y} L ${p2.x + radius} ${p1.y} ${arc} ${p2.x} ${ + p1.y + offset + } L ${p2.x} ${p2.y}`; + } } if (p1.x === p2.x) { - colorClassNum = branchPos[commitA.branch].index; - lineDef = `M ${p1.x} ${p1.y} L ${p1.x + radius} ${p1.y} ${arc} ${p1.x + offset} ${ - p2.y + radius - } L ${p2.x} ${p2.y}`; + lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`; } } else { if (p1.y < p2.y) { - arc = 'A 20 20, 0, 0, 0,'; - radius = 20; - offset = 20; - // Arrows going up take the color from the target branch - colorClassNum = branchPos[commitB.branch].index; - lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc} ${p1.x + offset} ${p2.y} L ${ - p2.x - } ${p2.y}`; + if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) { + lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${ + p1.y + offset + } L ${p2.x} ${p2.y}`; + } else { + lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc} ${p1.x + offset} ${ + p2.y + } L ${p2.x} ${p2.y}`; + } } if (p1.y > p2.y) { - arc = 'A 20 20, 0, 0, 0,'; - radius = 20; - offset = 20; - // Arrows going up take the color from the source branch - colorClassNum = branchPos[commitA.branch].index; - lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc} ${p2.x} ${p1.y - offset} L ${ - p2.x - } ${p2.y}`; + if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) { + lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc} ${p2.x} ${ + p1.y - offset + } L ${p2.x} ${p2.y}`; + } else { + lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y + radius} ${arc2} ${p1.x + offset} ${ + p2.y + } L ${p2.x} ${p2.y}`; + } } if (p1.y === p2.y) { - colorClassNum = branchPos[commitA.branch].index; - lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc} ${p1.x + offset} ${p2.y} L ${ - p2.x - } ${p2.y}`; + lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`; } } } From a9e67e42666b03817f1507976f6e5d9f7c39dc10 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 27 Feb 2024 15:33:28 +0530 Subject: [PATCH 11/11] Fix spelling --- docs/syntax/gantt.md | 4 +++- packages/mermaid/src/docs/syntax/gantt.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/syntax/gantt.md b/docs/syntax/gantt.md index d69cb9cc26..d1a13c6fa5 100644 --- a/docs/syntax/gantt.md +++ b/docs/syntax/gantt.md @@ -140,7 +140,7 @@ After processing the tags, the remaining metadata items are interpreted as follo | `after , until ` | End date of previously specified task `otherTaskID` | Start date of previously specified task `otherTaskID` | n/a | | `` | End date of preceding task | `enddate` as interpreted using `dateformat` | n/a | | `` | End date of preceding task | Start date + `length` | n/a | -| `until ` | End date of preceding task | Start date of previously specified task `otherTaskID` | n/a | +| `until ` | End date of preceding task | Start date of previously specified task `otherTaskID` | n/a | > **Note** > Support for keyword `until` was added in (v\+). This can be used to define a task which is running until some other specific task or milestone starts. @@ -559,3 +559,5 @@ gantt section Issue1300 5 : 0, 5 ``` + + diff --git a/packages/mermaid/src/docs/syntax/gantt.md b/packages/mermaid/src/docs/syntax/gantt.md index c9f5fb0b8a..a1139d3789 100644 --- a/packages/mermaid/src/docs/syntax/gantt.md +++ b/packages/mermaid/src/docs/syntax/gantt.md @@ -89,7 +89,7 @@ After processing the tags, the remaining metadata items are interpreted as follo | `after , until ` | End date of previously specified task `otherTaskID` | Start date of previously specified task `otherTaskID` | n/a | | `` | End date of preceding task | `enddate` as interpreted using `dateformat` | n/a | | `` | End date of preceding task | Start date + `length` | n/a | -| `until ` | End date of preceding task | Start date of previously specified task `otherTaskID` | n/a | +| `until ` | End date of preceding task | Start date of previously specified task `otherTaskID` | n/a | ```note Support for keyword `until` was added in (v+). This can be used to define a task which is running until some other specific task or milestone starts. @@ -449,3 +449,5 @@ gantt section Issue1300 5 : 0, 5 ``` + +