Skip to content

Commit

Permalink
Chore: Refactor view render function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIchenskiy committed Feb 20, 2024
1 parent 5a147ef commit fd48313
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/views/orb-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export interface IOrbViewSettings<N extends INodeBase, E extends IEdgeBase> {
zoomFitTransitionMs: number;
isOutOfBoundsDragEnabled: boolean;
areCoordinatesRounded: boolean;
isSimulationAnimated: boolean;
areCollapsedContainerDimensionsAllowed: boolean;
}

Expand Down Expand Up @@ -71,7 +70,6 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
zoomFitTransitionMs: 200,
isOutOfBoundsDragEnabled: false,
areCoordinatesRounded: true,
isSimulationAnimated: true,
areCollapsedContainerDimensionsAllowed: false,
...settings,
simulation: {
Expand Down Expand Up @@ -160,9 +158,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
this._simulator.on(SimulatorEventType.SIMULATION_PROGRESS, (data) => {
this._graph.setNodePositions(data.nodes);
this._events.emit(OrbEventType.SIMULATION_STEP, { progress: data.progress });
if (this._settings.isSimulationAnimated) {
this._renderer.render(this._graph);
}
this.render();
});
this._simulator.on(SimulatorEventType.SIMULATION_END, (data) => {
this._graph.setNodePositions(data.nodes);
Expand All @@ -174,11 +170,11 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
});
this._simulator.on(SimulatorEventType.SIMULATION_STEP, (data) => {
this._graph.setNodePositions(data.nodes);
this._renderer.render(this._graph);
this.render();
});
this._simulator.on(SimulatorEventType.NODE_DRAG, (data) => {
this._graph.setNodePositions(data.nodes);
this._renderer.render(this._graph);
this.render();
});
this._simulator.on(SimulatorEventType.SETTINGS_UPDATE, (data) => {
this._settings.simulation = data.settings;
Expand Down Expand Up @@ -323,10 +319,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
.duration(this._settings.zoomFitTransitionMs)
.ease(easeLinear)
.call(this._d3Zoom.scaleBy, 0.8)
.call(() => {
this._renderer.render(this._graph);
onRendered?.();
});
.call(() => this.render(onRendered));
}

destroy() {
Expand Down Expand Up @@ -413,7 +406,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
}
this._renderer.transform = event.transform;
setTimeout(() => {
this._renderer.render(this._graph);
this.render();
this._events.emit(OrbEventType.TRANSFORM, { transform: event.transform });
}, 1);
};
Expand Down Expand Up @@ -476,7 +469,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
});

if (response.isStateChanged) {
this._renderer.render(this._graph);
this.render();
}
};

Expand Down Expand Up @@ -514,7 +507,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
});

if (response.isStateChanged || response.changedSubject) {
this._renderer.render(this._graph);
this.render();
}
};

Expand Down Expand Up @@ -552,7 +545,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
});

if (response.isStateChanged || response.changedSubject) {
this._renderer.render(this._graph);
this.render();
}
};

Expand Down Expand Up @@ -590,7 +583,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
});

if (response.isStateChanged || response.changedSubject) {
this._renderer.render(this._graph);
this.render();
}
};

Expand All @@ -611,7 +604,7 @@ export class OrbView<N extends INodeBase, E extends IEdgeBase> implements IOrbVi
this._renderer.width = containerSize.width;
this._renderer.height = containerSize.height;
if (this._renderer.isInitiallyRendered) {
this._renderer.render(this._graph);
this.render();
}
}

Expand Down

0 comments on commit fd48313

Please sign in to comment.