Hi Walter,
I created a separate topic for the issue I am facing when zooming/panning in my diagram, as you suggested in Performance issue when adding nodes using a LayeredDigraphLayout in GoJS 3.0.8 - #4 by walter
I created the following profile, which suggests that a lot of time goes into updating the model. Please note, that this is an extreme case concerning the runtime. There are also cases where this takes half a second, but I wanted to show a case where every performed step is clearly visible.
The callbacks for the viewport change that are visible in the profile which I implemented are the following:
onViewportBoundsChanged
private onViewportBoundsChanged(event: go.DiagramEvent) {
this.syncRowHeaderDiagramWithHistoryGraphDiagram();
const oldScale: number = event.subject.scale;
const newScale: number = this.historyGraphDiagram.scale;
if (oldScale.toFixed(1) !== newScale.toFixed(1)) {
// Calculate the padding dependent on the scale. This way, the given target width is
// always translated into the correct document width.
// The fixed target width is the width of the filter panel. See the corresponding style sheet.
// Might be better to get that value from the filter panel component.
// However, this needs further changes.
this.historyGraphDiagram.padding = HistoryGraphComponent.calculateMargin(
500, newScale,
);
// Update the link scale when the diagram layout has changed, e.g. when new links were added,
// so that those links get the diagram link scale.
this.updateDiagramLinkScale(newScale);
}
}
syncRowHeaderDiagramWithHistoryGraphDiagram
// Ensures, that row header diagram and history graph diagram have the same vertical position and scale,
// after the viewport bounds of the history graph diagram have changed.
private syncRowHeaderDiagramWithHistoryGraphDiagram() {
if (this.syncingViewPorts) {
return;
}
this.syncingViewPorts = true;
this.rowHeaderDiagram.scale = this.historyGraphDiagram.scale;
this.rowHeaderDiagram.position = new go.Point(0, this.historyGraphDiagram.position.y + SYNC_DIAGRAMS_POSITION_Y_OFFSET);
this.rowHeaderDiagram.minScale = this.historyGraphDiagram.minScale;
this.rowHeaderDiagram.maxScale = this.historyGraphDiagram.maxScale;
this.syncingViewPorts = false;
}
updateDiagramLinkScale
``
// Update the scale for drawing the links with the given diagram scale.
private updateDiagramLinkScale(scale: number): void {
if (scale > 1) {
// Skip update, since the maximum scale for the links should be 1 in order
// to prevent links getting too wide when zooming closer into the diagram.
return;
}
const model = this.historyGraphDiagram.model as go.GraphLinksModel;
// Update the model property in order to notify the link template that data
// has changed and redrawing is necessary. See also
// https://forum.nwoods.com/t/problem-with-refresh-link-lines-color-and-dashed/5740.
model.setDataProperty(model.modelData, 'diagramLinkScale', scale);
}
// Ensures, that row header diagram and history graph diagram have the same vertical position and scale,
// after the viewport bounds of the row header diagram have changed.
private syncHistoryGraphDiagramWithRowHeaderDiagram() {
if (this.syncingViewPorts) {
return;
}
this.syncingViewPorts = true;
this.historyGraphDiagram.scale = this.rowHeaderDiagram.scale;
this.historyGraphDiagram.position = new go.Point(
this.historyGraphDiagram.viewportBounds.x, this.rowHeaderDiagram.position.y - SYNC_DIAGRAMS_POSITION_Y_OFFSET
);
this.syncingViewPorts = false;
}
Thanks in advance for your help.
My best,
Manuel