mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 07:49:43 +02:00
Fix for the issue 1005
(https://github.com/mermaid-js/mermaid/issues/1005) A new attribute 'order' has been introduced in the task which records the serial number of task in the script. In ganttRenderer.js, the tasks are sorted by stratTime attribute. The function which calculates 'y' for task rectangles, lables etc. has been modified to correctly position it.
This commit is contained in:
@@ -80,6 +80,23 @@ export const draw = function(text, id) {
|
||||
|
||||
categories = checkUnique(categories);
|
||||
|
||||
function taskCompare(a, b) {
|
||||
const taskA = a.startTime;
|
||||
const taskB = b.startTime;
|
||||
|
||||
let result = 0;
|
||||
if (taskA > taskB) {
|
||||
result = 1;
|
||||
} else if (taskA < taskB) {
|
||||
result = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Sort the task array using the above taskCompare() so that
|
||||
// tasks are created based on their order of startTime
|
||||
taskArray.sort(taskCompare);
|
||||
|
||||
makeGant(taskArray, w, h);
|
||||
if (typeof conf.useWidth !== 'undefined') {
|
||||
elem.setAttribute('width', w);
|
||||
@@ -119,7 +136,7 @@ export const draw = function(text, id) {
|
||||
.append('rect')
|
||||
.attr('x', 0)
|
||||
.attr('y', function(d, i) {
|
||||
return i * theGap + theTopPad - 2;
|
||||
return d.order * theGap + theTopPad - 2;
|
||||
})
|
||||
.attr('width', function() {
|
||||
return w - conf.rightPadding / 2;
|
||||
@@ -160,7 +177,7 @@ export const draw = function(text, id) {
|
||||
return timeScale(d.startTime) + theSidePad;
|
||||
})
|
||||
.attr('y', function(d, i) {
|
||||
return i * theGap + theTopPad;
|
||||
return d.order * theGap + theTopPad;
|
||||
})
|
||||
.attr('width', function(d) {
|
||||
if (d.milestone) {
|
||||
@@ -263,7 +280,7 @@ export const draw = function(text, id) {
|
||||
}
|
||||
})
|
||||
.attr('y', function(d, i) {
|
||||
return i * theGap + conf.barHeight / 2 + (conf.fontSize / 2 - 2) + theTopPad;
|
||||
return d.order * theGap + conf.barHeight / 2 + (conf.fontSize / 2 - 2) + theTopPad;
|
||||
})
|
||||
.attr('text-height', theBarHeight)
|
||||
.attr('class', function(d) {
|
||||
@@ -280,6 +297,7 @@ export const draw = function(text, id) {
|
||||
}
|
||||
|
||||
let secNum = 0;
|
||||
console.log(conf);
|
||||
for (let i = 0; i < categories.length; i++) {
|
||||
if (d.type === categories[i]) {
|
||||
secNum = i % conf.numberSectionStyles;
|
||||
|
Reference in New Issue
Block a user