I found an issue rendering projects that have the following type of dependency
- Parent task p
- Child task c
- Dependent task d, whom child task c is dependent on (i.e. c must complete before d can start)
When parent p begins before dependent task d, the “red error of death” is displayed. This project will reproduce the issue:
Parent 2011,1,26 64 0.00 Child 2011,2,2 8 0.00 222 Buster 2011,1,27 40 0.00The central issue in the bug is that the control cannot create connecting lines to tasks that happen to be below a task in the chart. Conceptually the old code that had the bug would create the chart row by row, and if you ever had a dependency in one row to a task in a lower row, that dependency would throw an error since you can’t draw a line to a node that doesn’t exist yet. The gist of the change is that I had to create all of the tasks first, then create the connecting lines. To fix this error I had to make this update to the control:
/**
-
@desc: Creation of tasks
-
@param: project - (object)project
-
@type: private
-
@topic: 4
*/
GanttChart.prototype.createTasks = function (project) {
for (var j = 0; j < project.Project.ParentTasks.length; j++) {
if (j > 0) {
project.Project.ParentTasks[j - 1].nextParentTask = project.Project.ParentTasks[j];
project.Project.ParentTasks[j].previousParentTask = project.Project.ParentTasks[j - 1];
}var task = new GanttTask(project.Project.ParentTasks[j], project, this); project.arrTasks.push(task);
}
for (var j = 0; j < project.Project.ParentTasks.length; j++) {
var task = project.arrTasks[j];
task.create();this.checkHeighPanelTasks(); if (project.Project.ParentTasks[j].ChildTasks.length > 0) { this.createChildItemControls(project.Project.ParentTasks[j].ChildTasks, project); }
}
for (var j = 0; j < project.arrTasks.length; j++) {
this.createDependencyLines(project.arrTasks[j], project);
}
};
/**
- @desc: Creation of tasks
- @param: arrChildTasks - array of child tasks
- @param: project - (object)project
- @type: private
-
@topic: 4
*/
GanttChart.prototype.createDependencyLines = function (task, project) {
task.createConnectingLines();
for (var i = 0; i < task.childTask.length; i++) {
this.createDependencyLines(task.childTask[i], project);
}
};
/**
-
@desc: creation of GanttTask
-
@type: private
-
@topic: 0
*/
GanttTask.prototype.create = function () {
var containerTasks = this.Chart.oData.firstChild;
var containerNames = null;
if (this.Chart._showTreePanel) containerNames = this.Chart.panelNames.firstChild;
var predecessorTask = this.TaskInfo.PredecessorTask;
var parentTask = this.TaskInfo.ParentTask;
var isCParentTask = (this.TaskInfo.ChildTasks.length > 0);
var self = this;this.cTaskItem = [];
this.cTaskNameItem = [];
this.cTaskOwnerItem = [];
this.cTaskStatusItem = [];//creation arrTasks
if (!parentTask) {
if (this.TaskInfo.previousParentTask) {
this.previousParentTask = this.Project.getTaskById(this.TaskInfo.previousParentTask.Id);
var lastChildTask = this.Chart.getLastChildTask(this.previousParentTask);
this.posY = parseInt(lastChildTask.cTaskItem[0].style.top) + this.Chart.heightTaskItem + 11;
this.previousParentTask.nextParentTask = this;} else { this.posY = parseInt(this.Project.projectItem[0].style.top) + this.Chart.heightTaskItem + 11; }
}
if (parentTask) {
var task = this.Project.getTaskById(this.TaskInfo.ParentTask.Id);
this.parentTask = task;if (this.TaskInfo.previousChildTask) { this.previousChildTask = this.Project.getTaskById(this.TaskInfo.previousChildTask.Id); var lastChildTask = this.Chart.getLastChildTask(this.previousChildTask); this.posY = parseInt(lastChildTask.cTaskItem[0].style.top) + this.Chart.heightTaskItem + 11; this.previousChildTask.nextChildTask = this; } else { this.posY = parseInt(task.cTaskItem[0].style.top) + this.Chart.heightTaskItem + 11; } task.childTask.push(this);
}
if (predecessorTask) {
var task = this.Project.getTaskById(predecessorTask.Id);
this.predTask = task;
task.childPredTask.push(this);
}//creation task item
this.cTaskItem.push(this.createTaskItem());
containerTasks.appendChild(this.cTaskItem[0]);if (this.Chart.panelNames) {
this.cTaskNameItem.push(this.createTaskNameItem(isCParentTask));
this.Chart.panelNames.firstChild.appendChild(this.cTaskNameItem[0]);
}if (this.Chart.panelStatus) {
this.cTaskStatusItem.push(this.createTaskStatusItem(isCParentTask));
this.Chart.panelStatus.firstChild.appendChild(this.cTaskStatusItem[0]);
}if (this.Chart.panelOwner) {
this.cTaskOwnerItem.push(this.createTaskOwnerItem(isCParentTask));
this.Chart.panelOwner.firstChild.appendChild(this.cTaskOwnerItem[0]);
}if (this.Chart.isShowDescTask) {
containerTasks.appendChild(this.createTaskDescItem());
}this.addDayInPanelTime();
return this;
};
/**
-
@desc: creation of GanttTask connecting lines
-
@type: private
-
@topic: 0
*/
GanttTask.prototype.createConnectingLines = function () {
//Create Connecting Lines
var arrConnectingLines = [];
var predecessorTask = this.TaskInfo.PredecessorTask;
if (predecessorTask) arrConnectingLines = this.createConnectingLinesDS();
this.cTaskItem.push(arrConnectingLines);if (this.Chart.panelNames) {
//Create Connecting Lines
var arrConnectingLinesNames = [];
var parentTask = this.TaskInfo.ParentTask;
if (parentTask) {
this.cTaskNameItem[0].style.left = parseInt(this.parentTask.cTaskNameItem[0].style.left) + 15 + “px”;
arrConnectingLinesNames = this.createConnectingLinesPN();
}
this.checkWidthTaskNameItem();var treeImg = null; var isCParentTask = (this.TaskInfo.ChildTasks.length > 0); if (isCParentTask) treeImg = this.createTreeImg(); this.cTaskNameItem.push(arrConnectingLinesNames); this.cTaskNameItem.push(treeImg);
}
}
Feel free to use this code to fix the chart. So far i’ve been very happy with it.
Michael