diff --git a/README.md b/README.md index d6b11a5..e402070 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,5 @@ See the README in the plugin repo for information on how to set it up. [](https://vercel.com/new/clone?repository-url=https://github.com/oleeskild/digitalgarden) --- -## Custom Styling -I encourage you to change the default styling to make the site your own. Please modify the custom-style.scss when doing so to avoid future conflict when updating the template. \ No newline at end of file +## Docs +Docs are available at [dg-docs.ole.dev](https://dg-docs.ole.dev/) diff --git a/package-lock.json b/package-lock.json index 136691f..829d5df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -785,9 +785,9 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, "node_modules/axios": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.2.6.tgz", - "integrity": "sha512-rC/7F08XxZwjMV4iuWv+JpD3E0Ksqg9nac4IIg6RwNuF0JTeWoCo/mBNG54+tNhhI11G3/VDRbdDQTs9hGp4pQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.2.tgz", + "integrity": "sha512-1M3O703bYqYuPhbHeya5bnhpYVsDDRyQSabNja04mZtboLNSuZ4YrltestrLXfHgmzua4TpUqRiVKbiQuo2epw==", "dependencies": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -5103,9 +5103,9 @@ } }, "node_modules/sass": { - "version": "1.57.1", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.57.1.tgz", - "integrity": "sha512-O2+LwLS79op7GI0xZ8fqzF7X2m/m8WFfI02dHOdsK5R2ECeS5F62zrwg/relM1rjSLy7Vd/DiMNIvPrQGsA0jw==", + "version": "1.58.0", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.58.0.tgz", + "integrity": "sha512-PiMJcP33DdKtZ/1jSjjqVIKihoDc6yWmYr9K/4r3fVVIEDAluD0q7XZiRKrNJcPK3qkLRF/79DND1H5q1LBjgg==", "dev": true, "dependencies": { "chokidar": ">=3.0.0 <4.0.0", @@ -7153,9 +7153,9 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, "axios": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.2.6.tgz", - "integrity": "sha512-rC/7F08XxZwjMV4iuWv+JpD3E0Ksqg9nac4IIg6RwNuF0JTeWoCo/mBNG54+tNhhI11G3/VDRbdDQTs9hGp4pQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.2.tgz", + "integrity": "sha512-1M3O703bYqYuPhbHeya5bnhpYVsDDRyQSabNja04mZtboLNSuZ4YrltestrLXfHgmzua4TpUqRiVKbiQuo2epw==", "requires": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -10502,9 +10502,9 @@ } }, "sass": { - "version": "1.57.1", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.57.1.tgz", - "integrity": "sha512-O2+LwLS79op7GI0xZ8fqzF7X2m/m8WFfI02dHOdsK5R2ECeS5F62zrwg/relM1rjSLy7Vd/DiMNIvPrQGsA0jw==", + "version": "1.58.0", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.58.0.tgz", + "integrity": "sha512-PiMJcP33DdKtZ/1jSjjqVIKihoDc6yWmYr9K/4r3fVVIEDAluD0q7XZiRKrNJcPK3qkLRF/79DND1H5q1LBjgg==", "dev": true, "requires": { "chokidar": ">=3.0.0 <4.0.0", diff --git a/src/site/_includes/components/graphScript.njk b/src/site/_includes/components/graphScript.njk index 1e8f970..33072a3 100644 --- a/src/site/_includes/components/graphScript.njk +++ b/src/site/_includes/components/graphScript.njk @@ -50,9 +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-muted"); + let Graph = ForceGraph() - (document.getElementById(id)) + (el) .graphData(graphData) .nodeId('id') .nodeLabel('title') @@ -63,15 +71,34 @@ .height(height) .linkDirectionalArrowLength(2) .linkDirectionalArrowRelPos(0.5) - .linkColor(() => getCssVar("--text-muted") || getCssVar("--text-normal")) + .autoPauseRedraw(false) + .linkColor((link) => { + if (hoverNode == null) { + return color; + } + if (link.source.id == hoverNode.id || link.target.id == hoverNode.id) { + return color; + } else { + return mutedColor; + } + + }) .nodeCanvasObject((node, ctx) => { - const color = getCssVar("--text-accent"); const numberOfNeighbours = (node.neighbors && node.neighbors.length) || 2; const nodeR = Math.min(7, Math.max(numberOfNeighbours / 2, 2)); ctx.beginPath(); ctx.arc(node.x, node.y, nodeR, 0, 2 * Math.PI, false); - ctx.fillStyle = color; + if (hoverNode == null) { + ctx.fillStyle = color; + } else { + if (node == hoverNode || highlightNodes.has(node.url)) { + ctx.fillStyle = color; + } else { + ctx.fillStyle = mutedColor; + } + } + ctx.fill(); if (node.current) { @@ -91,36 +118,48 @@ ctx.fillText(label, node.x, node.y + nodeR + 2); }) .onNodeClick(node => { - window.location = node.url; - }); - if (delay != null && graphData.nodes.length > 2) { - setTimeout(() => { - Graph.zoomToFit(5, 75); - }, delay); + window.location = node.url; + }) + .onNodeHover(node => { + highlightNodes.clear(); + if (node) { + highlightNodes.add(node); + node.neighbors.forEach(neighbor => highlightNodes.add(neighbor)); } + hoverNode = node || null; + + }); + if (delay != null && graphData.nodes.length > 4) { + setTimeout(() => { + Graph.zoomToFit(5, 75); + }, delay); + } return Graph; } 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); }); } fetchGraphData(); - window.document.getElementById('graph-depth').value = window.maxGraphDepth; - window.document.getElementById('depth-display').innerText = window.maxGraphDepth; - window.document.getElementById('graph-depth').addEventListener('input', (evt) => { - - window.maxGraphDepth = evt.target.value; - window.document.getElementById('depth-display').innerText = window.maxGraphDepth; + window.document.getElementById('graph-depth').value = window.maxGraphDepth; + window.document.getElementById('depth-display').innerText = window.maxGraphDepth; + window.document.getElementById('graph-depth').addEventListener('input', (evt) => { + + window.maxGraphDepth = evt.target.value; + window.document.getElementById('depth-display').innerText = window.maxGraphDepth; if (Graph != null) { Graph._destructor(); Graph = null; } - renderGraph(filterToDepth(JSON.parse(JSON.stringify(window.graphData))), "link-graph", 320, 320, 1); - }) + Graph = renderGraph(filterToDepth(JSON.parse(JSON.stringify(window.graphData))), "link-graph", 1); + setTimeout(() => { + Graph.zoomToFit(5, 75); + }, 1); + }); window.fullGraph = null; function renderFullGraph() { @@ -135,7 +174,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(); @@ -146,8 +185,23 @@ } - 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.offsetWidth); + } else { + el.classList.add('graph-fs'); + Graph.width(el.offsetWidth).height(el.offsetWidth); + } + setTimeout(() => { + Graph.zoomToFit(5, 75); + }, 1); + + }); + + document.getElementById('global-graph-btn').addEventListener('click', (evt) => { + if (!window.fullGraph) { renderFullGraph(); } }); diff --git a/src/site/_includes/components/searchScript.njk b/src/site/_includes/components/searchScript.njk index ecadf2a..6b70d32 100644 --- a/src/site/_includes/components/searchScript.njk +++ b/src/site/_includes/components/searchScript.njk @@ -227,4 +227,4 @@ resultsHTML += ''; resultsDiv.innerHTML = resultsHTML; } - \ No newline at end of file + 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 @@ - +