in src/gantt.ts [1475:1604]
public update(options: VisualUpdateOptions): void {
if (!options || !options.dataViews || !options.dataViews[0]) {
this.clearViewport();
return;
}
this.viewModel = Gantt.converter(options.dataViews[0], this.host, this.colors, this.colorHelper, this.localizationManager);
// for dublicated milestone types
if (this.viewModel && this.viewModel.milestonesData) {
let newMilestoneData: MilestoneData = this.viewModel.milestonesData;
const milestonesWithoutDublicates = Gantt.getUniqueMilestones(newMilestoneData.dataPoints);
newMilestoneData.dataPoints.forEach((dataPoint: MilestoneDataPoint) => {
if (dataPoint.name) {
const theSameUniqDataPoint: MilestoneDataPoint = milestonesWithoutDublicates[dataPoint.name];
dataPoint.color = theSameUniqDataPoint.color;
dataPoint.shapeType = theSameUniqDataPoint.shapeType;
}
});
this.viewModel.milestonesData = newMilestoneData;
}
if (!this.viewModel || !this.viewModel.tasks || this.viewModel.tasks.length <= 0) {
this.clearViewport();
return;
}
this.viewport = _.clone(options.viewport);
this.margin = Gantt.DefaultMargin;
this.eventService.renderingStarted(options);
this.renderLegend();
this.updateChartSize();
const visibleTasks = this.viewModel.tasks
.filter((task: Task) => task.visibility);
const tasks: Task[] = visibleTasks
.map((task: Task, i: number) => {
task.index = i;
return task;
});
if (this.interactivityService) {
this.interactivityService.applySelectionStateToData(tasks);
}
if (tasks.length < Gantt.MinTasks) {
return;
}
let settings = this.viewModel.settings;
this.collapsedTasks = JSON.parse(settings.collapsedTasks.list);
let groupedTasks: GroupedTask[] = this.groupTasks(tasks);
// do smth with task ids
this.updateCommonTasks(groupedTasks);
this.updateCommonMilestones(groupedTasks);
let tasksAfterGrouping: Task[] = [];
groupedTasks.forEach((t: GroupedTask) => tasksAfterGrouping = tasksAfterGrouping.concat(t.tasks));
const minDateTask: Task = _.minBy(tasksAfterGrouping, (t) => t && t.start);
const maxDateTask: Task = _.maxBy(tasksAfterGrouping, (t) => t && t.end);
this.hasNotNullableDates = !!minDateTask && !!maxDateTask;
let axisLength: number = 0;
if (this.hasNotNullableDates) {
let startDate: Date = minDateTask.start;
let endDate: Date = maxDateTask.end;
if (startDate.toString() === endDate.toString()) {
endDate = new Date(endDate.valueOf() + (24 * 60 * 60 * 1000));
}
let dateTypeMilliseconds: number = Gantt.getDateType(settings.dateType.type);
let ticks: number = Math.ceil(Math.round(endDate.valueOf() - startDate.valueOf()) / dateTypeMilliseconds);
ticks = ticks < 2 ? 2 : ticks;
axisLength = ticks * Gantt.DefaultTicksLength;
axisLength = this.scaleAxisLength(axisLength);
let viewportIn: IViewport = {
height: this.viewport.height,
width: axisLength
};
let xAxisProperties: IAxisProperties = this.calculateAxes(viewportIn, this.textProperties, startDate, endDate, ticks, false);
this.timeScale = <timeScale<Date, Date>>xAxisProperties.scale;
this.renderAxis(xAxisProperties);
}
axisLength = this.scaleAxisLength(axisLength);
this.setDimension(groupedTasks, axisLength, settings);
this.renderTasks(groupedTasks);
this.updateTaskLabels(groupedTasks, settings.taskLabels.width);
this.updateElementsPositions(this.margin);
this.createMilestoneLine(groupedTasks);
if (settings.general.scrollToCurrentTime && this.hasNotNullableDates) {
this.scrollToMilestoneLine(axisLength);
}
if (this.interactivityService) {
const behaviorOptions: BehaviorOptions = {
clearCatcher: this.clearCatcher,
taskSelection: this.taskGroup.selectAll(Selectors.SingleTask.selectorName),
legendSelection: this.body.selectAll(Selectors.LegendItems.selectorName),
subTasksCollapse: {
selection: this.body.selectAll(Selectors.ClickableArea.selectorName),
callback: this.subTasksCollapseCb.bind(this)
},
allSubtasksCollapse: {
selection: this.body
.selectAll(Selectors.CollapseAllArrow.selectorName),
callback: this.subTasksCollapseAll.bind(this)
},
interactivityService: this.interactivityService,
behavior: this.behavior,
dataPoints: tasks
};
this.interactivityService.bind(behaviorOptions);
this.behavior.renderSelection(false);
}
this.eventService.renderingFinished(options);
}