From 7994a930154aecf7a6c61aa767b7f99c54d218c6 Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Wed, 1 Feb 2023 14:21:03 +0600 Subject: [PATCH] some enhancements --- src/site/_includes/components/graphScript.njk | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/site/_includes/components/graphScript.njk b/src/site/_includes/components/graphScript.njk index 3dd645b..505275d 100644 --- a/src/site/_includes/components/graphScript.njk +++ b/src/site/_includes/components/graphScript.njk @@ -49,13 +49,17 @@ var Graph; - function renderGraph(graphData, id, width, height) { + function renderGraph(graphData, id, width, height, delay) { let Graph = ForceGraph() (document.getElementById(id)) .graphData(graphData) .nodeId('id') .nodeLabel('title') .linkSource('source') + .linkTarget('target') + .d3AlphaDecay(0.10) + .width(width) + .height(height) .linkDirectionalArrowLength(2) .linkDirectionalArrowRelPos(0.5) .nodeCanvasObject((node, ctx) => { @@ -79,8 +83,10 @@ .linkColor(() => getCssVar("--text-muted") || getCssVar("--text-normal")) .onNodeClick(node => { window.location = node.url; - }) - .linkTarget('target').width(width).height(height); + }); + setTimeout(() => { + Graph.zoomToFit(5, 75); + }, delay); return Graph; } @@ -102,7 +108,7 @@ Graph._destructor(); Graph = null; } - renderGraph(filterToDepth(JSON.parse(JSON.stringify(window.graphData))), "link-graph", 330, 330); + renderGraph(filterToDepth(JSON.parse(JSON.stringify(window.graphData))), "link-graph", 330, 330, 1); }) window.fullGraph = null; @@ -118,8 +124,7 @@ g.classList.add('show'); document.body.appendChild(g); g.innerHTML = '
'; - - window.fullGraph = renderGraph(graphData, "full-graph-container", g.offsetWidth, g.offsetHeight); + window.fullGraph = renderGraph(graphData, "full-graph-container", g.offsetWidth, g.offsetHeight, 200); document.getElementById('full-graph-close').addEventListener('click', (evt) => { g.classList.remove('show'); window.fullGraph._destructor();