From f291e37b05d67feed3541b8267171073287e822b Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Tue, 14 Feb 2023 15:07:13 +0600 Subject: [PATCH] graph enhancements --- src/site/_includes/components/graphScript.njk | 30 +++++++++---- src/site/_includes/components/sidebar.njk | 5 ++- src/site/styles/digital-garden-base.scss | 44 +++++++++++++++++-- 3 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/site/_includes/components/graphScript.njk b/src/site/_includes/components/graphScript.njk index b3b189b..055e732 100644 --- a/src/site/_includes/components/graphScript.njk +++ b/src/site/_includes/components/graphScript.njk @@ -50,15 +50,17 @@ var Graph; - function renderGraph(graphData, id, width, height, delay) { - + function renderGraph(graphData, id, delay) { + const el = document.getElementById(id); + width = el.offsetWidth; + height = el.offsetHeight; const highlightNodes = new Set(); let hoverNode = null; const color = getCssVar("--text-accent"); const mutedColor = getCssVar("--text-faint"); let Graph = ForceGraph() - (document.getElementById(id)) + (el) .graphData(graphData) .nodeId('id') .nodeLabel('title') @@ -138,7 +140,7 @@ function fetchGraphData() { fetch('/graph.json').then(res => res.json()).then(data => { window.graphData = data; - Graph = renderGraph(filterToDepth(JSON.parse(JSON.stringify(data))), "link-graph", 320, 320, 1); + Graph = renderGraph(filterToDepth(JSON.parse(JSON.stringify(data))), "link-graph", 1); }); } @@ -153,7 +155,7 @@ Graph._destructor(); Graph = null; } - renderGraph(filterToDepth(JSON.parse(JSON.stringify(window.graphData))), "link-graph", 320, 320, 1); + renderGraph(filterToDepth(JSON.parse(JSON.stringify(window.graphData))), "link-graph", 1); }) window.fullGraph = null; @@ -169,7 +171,7 @@ g.classList.add('show'); document.body.appendChild(g); g.innerHTML = '
'; - window.fullGraph = renderGraph(graphData, "full-graph-container", g.offsetWidth, g.offsetHeight, 200); + window.fullGraph = renderGraph(graphData, "full-graph-container", 200); document.getElementById('full-graph-close').addEventListener('click', (evt) => { g.classList.remove('show'); window.fullGraph._destructor(); @@ -180,8 +182,20 @@ } - document.getElementById('graph-full-btn').addEventListener('click', (evt) => { - if (!fullGraph) { + document.getElementById('graph-fs-btn').addEventListener('click', (evt) => { + const el = document.querySelector('.graph'); + if (el.classList.contains('graph-fs')) { + el.classList.remove('graph-fs'); + Graph.width(el.offsetWidth).height(el.offsetHeight); + } else { + el.classList.add('graph-fs'); + Graph.width(el.offsetWidth).height(el.offsetHeight); + } + + }); + + document.getElementById('global-graph-btn').addEventListener('click', (evt) => { + if (!window.fullGraph) { renderFullGraph(); } }); diff --git a/src/site/_includes/components/sidebar.njk b/src/site/_includes/components/sidebar.njk index 9946350..c51cece 100644 --- a/src/site/_includes/components/sidebar.njk +++ b/src/site/_includes/components/sidebar.njk @@ -19,7 +19,10 @@ - +
+ + +
diff --git a/src/site/styles/digital-garden-base.scss b/src/site/styles/digital-garden-base.scss index a4c04bf..a632942 100644 --- a/src/site/styles/digital-garden-base.scss +++ b/src/site/styles/digital-garden-base.scss @@ -65,6 +65,33 @@ ul.task-list { display: flex; z-index: 3; max-width: 350px; + + .graph { + width: 320px; + height: 320px; + + #link-graph { + width: 100%; + height: 100%; + } + } + .graph-fs { + position: fixed; + top: 50%; + left: 50%; + height: calc(100vmin - 100px); + width: calc(100vmin - 100px); + min-height: 350px; + min-width: 350px; + transform: translate(-50%, -50%); + z-index: 9999; + display: none; + background-color: var(--background-secondary); + + .graph-title { + display: none; + } + } } .expand-line { @@ -531,15 +558,20 @@ ul.task-list { position: fixed; top: 50%; left: 50%; - height: 60vh; - width: 60vw; - min-height: 400px; - min-width: 400px; + height: calc(100vmin - 100px); + width: calc(100vmin - 100px); + min-height: 350px; + min-width: 350px; transform: translate(-50%, -50%); z-index: 9999; display: none; background-color: var(--background-secondary); + #full-graph-container { + width: 100%; + height: 100%; + } + #full-graph-close { position: absolute; top: 10px; @@ -571,6 +603,10 @@ ul.task-list { color: var(--text-accent); z-index: 9; + i { + cursor: pointer; + } + .depth-control { display: flex; flex-direction: row;