aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/graph/DotGraphVisualizer.tsx
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-09-04 16:28:20 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-09-04 16:28:20 +0200
commit20cd0081fbb1fd569a4679ccbd8bda959f022fa3 (patch)
tree259e8c40cc2976579c178e56ce6636a9036b802d /subprojects/frontend/src/graph/DotGraphVisualizer.tsx
parentbuild: add Dockerfile (diff)
downloadrefinery-20cd0081fbb1fd569a4679ccbd8bda959f022fa3.tar.gz
refinery-20cd0081fbb1fd569a4679ccbd8bda959f022fa3.tar.zst
refinery-20cd0081fbb1fd569a4679ccbd8bda959f022fa3.zip
refactor(frontend): graph visualizer performance
Also show scopes unconditionally if enabled.
Diffstat (limited to 'subprojects/frontend/src/graph/DotGraphVisualizer.tsx')
-rw-r--r--subprojects/frontend/src/graph/DotGraphVisualizer.tsx25
1 files changed, 21 insertions, 4 deletions
diff --git a/subprojects/frontend/src/graph/DotGraphVisualizer.tsx b/subprojects/frontend/src/graph/DotGraphVisualizer.tsx
index 41fd7225..02f31085 100644
--- a/subprojects/frontend/src/graph/DotGraphVisualizer.tsx
+++ b/subprojects/frontend/src/graph/DotGraphVisualizer.tsx
@@ -29,13 +29,17 @@ function DotGraphVisualizer({
29 graph, 29 graph,
30 fitZoom, 30 fitZoom,
31 transitionTime, 31 transitionTime,
32 animateThreshold,
32}: { 33}: {
33 graph: GraphStore; 34 graph: GraphStore;
34 fitZoom?: FitZoomCallback; 35 fitZoom?: FitZoomCallback;
35 transitionTime?: number; 36 transitionTime?: number;
37 animateThreshold?: number;
36}): JSX.Element { 38}): JSX.Element {
37 const transitionTimeOrDefault = 39 const transitionTimeOrDefault =
38 transitionTime ?? DotGraphVisualizer.defaultProps.transitionTime; 40 transitionTime ?? DotGraphVisualizer.defaultProps.transitionTime;
41 const animateThresholdOrDefault =
42 animateThreshold ?? DotGraphVisualizer.defaultProps.animateThreshold;
39 const disposerRef = useRef<IReactionDisposer | undefined>(); 43 const disposerRef = useRef<IReactionDisposer | undefined>();
40 const graphvizRef = useRef< 44 const graphvizRef = useRef<
41 Graphviz<BaseType, unknown, null, undefined> | undefined 45 Graphviz<BaseType, unknown, null, undefined> | undefined
@@ -75,6 +79,8 @@ function DotGraphVisualizer({
75 Workaround for error in `@types/d3-graphviz`. 79 Workaround for error in `@types/d3-graphviz`.
76 */ 80 */
77 renderer.transition(transition as any); 81 renderer.transition(transition as any);
82 let animate = true;
83 let previousSize = 0;
78 let newViewBox = { width: 0, height: 0 }; 84 let newViewBox = { width: 0, height: 0 };
79 renderer.onerror(LOG.error.bind(LOG)); 85 renderer.onerror(LOG.error.bind(LOG));
80 renderer.on( 86 renderer.on(
@@ -106,17 +112,27 @@ function DotGraphVisualizer({
106 } 112 }
107 disposerRef.current = reaction( 113 disposerRef.current = reaction(
108 () => dotSource(graph), 114 () => dotSource(graph),
109 (source) => { 115 (result) => {
110 if (source !== undefined) { 116 if (result === undefined) {
111 renderer.renderDot(source); 117 return;
112 } 118 }
119 const [source, size] = result;
120 // Disable tweening for large graphs to improve performance.
121 // See https://github.com/magjac/d3-graphviz/issues/232#issuecomment-1157555213
122 const newAnimate = size + previousSize < animateThresholdOrDefault;
123 if (animate !== newAnimate) {
124 renderer.tweenPaths(newAnimate);
125 animate = newAnimate;
126 }
127 previousSize = size;
128 renderer.renderDot(source);
113 }, 129 },
114 { fireImmediately: true }, 130 { fireImmediately: true },
115 ); 131 );
116 graphvizRef.current = renderer; 132 graphvizRef.current = renderer;
117 } 133 }
118 }, 134 },
119 [graph, fitZoom, transitionTimeOrDefault], 135 [graph, fitZoom, transitionTimeOrDefault, animateThresholdOrDefault],
120 ); 136 );
121 137
122 return <GraphTheme ref={setElement} />; 138 return <GraphTheme ref={setElement} />;
@@ -125,6 +141,7 @@ function DotGraphVisualizer({
125DotGraphVisualizer.defaultProps = { 141DotGraphVisualizer.defaultProps = {
126 fitZoom: undefined, 142 fitZoom: undefined,
127 transitionTime: 250, 143 transitionTime: 250,
144 animateThreshold: 50,
128}; 145};
129 146
130export default observer(DotGraphVisualizer); 147export default observer(DotGraphVisualizer);