From 45c0c5fee0921cbc727d8d01426251ac575987cc Mon Sep 17 00:00:00 2001 From: Jeremy Funk Date: Thu, 23 Mar 2023 22:54:58 +0100 Subject: [PATCH] Bugfix --- demos/gantt.html | 32 +++++----- .../src/diagrams/gantt/ganttRenderer.js | 62 +++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/demos/gantt.html b/demos/gantt.html index aa855a650..62f30badb 100644 --- a/demos/gantt.html +++ b/demos/gantt.html @@ -174,24 +174,24 @@ compact section DB Clean - Clean: 12:00:00 , 10m - 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 + Clean: 12:00:00, 10m + 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: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 , 12m - G: 13:32:00 , 18m - H: 13:50:00 , 20m - I: 14:10:00 , 10m + 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, 12m + G: 13:32:00, 18m + H: 13:50:00, 20m + I: 14:10:00, 10m
diff --git a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js index 563ed6605..f4b606d89 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js +++ b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js @@ -24,6 +24,37 @@ export const setConf = function () { log.debug('Something is calling, setConf, remove the call'); }; +/** + * For this issue: + * https://github.com/mermaid-js/mermaid/issues/1618 + * + * Finds the number of intersections between tasks that happen at any point in time. + * Used to figure out how many rows are needed to display the tasks when the compact + * flag is set to true. + * + * @param tasks + * @param orderOffset + */ +const getMaxIntersections = (tasks, orderOffset) => { + let timeline = [...tasks].map(() => -1); + let sorted = [...tasks].sort((a, b) => a.startTime - b.startTime || a.order - b.order); + let maxIntersections = 0; + for (const element of sorted) { + for (let j = 0; j < timeline.length; j++) { + if (element.startTime >= timeline[j]) { + timeline[j] = element.endTime; + element.order = j + orderOffset; + if (j > maxIntersections) { + maxIntersections = j; + } + break; + } + } + } + + return maxIntersections; +}; + let w; export const draw = function (text, id, version, diagObj) { const conf = getConfig().gantt; @@ -704,37 +735,6 @@ export const draw = function (text, id, version, diagObj) { } return result; } - - /** - * For this issue: - * https://github.com/mermaid-js/mermaid/issues/1618 - * - * Finds the number of intersections between tasks that happen at any point in time. - * Used to figure out how many rows are needed to display the tasks when the compact - * flag is set to true. - * - * @param tasks - * @param orderOffset - */ - const getMaxIntersections = (tasks, orderOffset) => { - let timeline = [...tasks].map(() => -1); - let sorted = [...tasks].sort((a, b) => a.startTime - b.startTime || a.order - b.order); - let maxIntersections = 0; - for (const element of sorted) { - for (let j = 0; j < timeline.length; j++) { - if (element.startTime >= timeline[j]) { - timeline[j] = element.endTime; - element.order = j + orderOffset; - if (j > maxIntersections) { - maxIntersections = j; - } - break; - } - } - } - - return maxIntersections; - }; }; export default {