Skip to content

Commit

Permalink
fix: Performance issue in Gantt diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Sep 26, 2023
1 parent a3456ec commit 5f5b216
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions packages/mermaid/src/diagrams/gantt/ganttRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,20 +497,37 @@ export const draw = function (text, id, version, diagObj) {
* @param w
* @param h
* @param tasks
* @param excludes
* @param includes
* @param {unknown[]} excludes
* @param {unknown[]} includes
*/
function drawExcludeDays(theGap, theTopPad, theSidePad, w, h, tasks, excludes, includes) {
const minTime = tasks.reduce(
(min, { startTime }) => (min ? Math.min(min, startTime) : startTime),
0
);
const maxTime = tasks.reduce((max, { endTime }) => (max ? Math.max(max, endTime) : endTime), 0);
const dateFormat = diagObj.db.getDateFormat();
if (excludes.length === 0 && includes.length === 0) {
return;
}

let minTime;
let maxTime;
for (const { startTime, endTime } of tasks) {
if (minTime === undefined || startTime < minTime) {
minTime = startTime;
}
if (maxTime === undefined || endTime > maxTime) {
maxTime = endTime;
}
}

if (!minTime || !maxTime) {
return;
}

if (dayjs(maxTime).diff(dayjs(minTime), 'year') > 10) {
console.warn(

Check failure on line 524 in packages/mermaid/src/diagrams/gantt/ganttRenderer.js

View workflow job for this annotation

GitHub Actions / lint (18.x)

Unexpected console statement
'The difference between the min and max time is more than 10 years. This will cause performance issues. Skipping drawing exclude days.'
);
return;
}

const dateFormat = diagObj.db.getDateFormat();
const excludeRanges = [];
let range = null;
let d = dayjs(minTime);
Expand Down

0 comments on commit 5f5b216

Please sign in to comment.