Skip to content
Snippets Groups Projects
Commit a750681b authored by Dennis Collaris's avatar Dennis Collaris
Browse files

perf: do not show edge labels when number of nodes exceeds configurable threshold

parent e51f24f2
No related branches found
No related tags found
No related merge requests found
Pipeline #137522 passed
...@@ -96,6 +96,8 @@ export const NLPixi = (props: Props) => { ...@@ -96,6 +96,8 @@ export const NLPixi = (props: Props) => {
width: 1000, width: 1000,
height: 1000, height: 1000,
LABEL_MAX_NODES: 1000,
LAYOUT_ALGORITHM: Layouts.FORCEATLAS2WEBWORKER, LAYOUT_ALGORITHM: Layouts.FORCEATLAS2WEBWORKER,
NODE_RADIUS: 5, NODE_RADIUS: 5,
...@@ -205,22 +207,24 @@ export const NLPixi = (props: Props) => { ...@@ -205,22 +207,24 @@ export const NLPixi = (props: Props) => {
onZoom(event: FederatedPointerEvent) { onZoom(event: FederatedPointerEvent) {
const scale = viewport.current!.transform.scale.x; const scale = viewport.current!.transform.scale.x;
labelLayer.alpha = (scale > 2) ? Math.min(1, (scale - 2) * 3) : 0; if (graph.current.nodes.length < config.LABEL_MAX_NODES) {
labelLayer.alpha = (scale > 2) ? Math.min(1, (scale - 2) * 3) : 0;
if (labelLayer.alpha > 0) {
labelLayer.renderable = true; if (labelLayer.alpha > 0) {
labelLayer.renderable = true;
const scale = 1 / viewport.current!.scale.x; // starts from 0.5 down to 0.
const scale = 1 / viewport.current!.scale.x; // starts from 0.5 down to 0.
// Only change the fontSize for specific intervals, continuous change has too big of an impact on performance
const fontSize = (scale < 0.1) ? 30 : (scale < 0.2) ? 40 : (scale < 0.3) ? 50 : 60; // Only change the fontSize for specific intervals, continuous change has too big of an impact on performance
const strokeWidth = fontSize / 2; const fontSize = (scale < 0.1) ? 30 : (scale < 0.2) ? 40 : (scale < 0.3) ? 50 : 60;
labelMap.current.forEach((text) => { const strokeWidth = fontSize / 2;
text.style.fontSize = fontSize; labelMap.current.forEach((text) => {
text.style.strokeThickness = strokeWidth; text.style.fontSize = fontSize;
}); text.style.strokeThickness = strokeWidth;
} else { });
labelLayer.renderable = false; } else {
labelLayer.renderable = false;
}
} }
} }
})); }));
...@@ -662,13 +666,15 @@ export const NLPixi = (props: Props) => { ...@@ -662,13 +666,15 @@ export const NLPixi = (props: Props) => {
} }
}); });
graph.current.links.forEach((link) => { if (graph.current.nodes.length < config.LABEL_MAX_NODES) {
if (!forceClear && labelMap.current.has(link._id)) { graph.current.links.forEach((link) => {
updateLinkLabel(link); if (!forceClear && labelMap.current.has(link._id)) {
} else { updateLinkLabel(link);
createLinkLabel(link); } else {
} createLinkLabel(link);
}); }
});
}
// // update text colour (written after nodes so that text appears on top of nodes) // // update text colour (written after nodes so that text appears on top of nodes)
// nodes.forEach((node: NodeType) => { // nodes.forEach((node: NodeType) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment