From dbe9b338ccc5df23882ebfa26c9020fb863a4124 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Mon, 27 Dec 2021 22:44:39 +0000
Subject: [PATCH] fix capitalization
---
layouts/partials/graph.html | 46 ++++++++++++++++++++++++++++++++++------------
1 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/layouts/partials/graph.html b/layouts/partials/graph.html
index dbd33d1..e8cd966 100644
--- a/layouts/partials/graph.html
+++ b/layouts/partials/graph.html
@@ -13,14 +13,38 @@
<script>
const index = {{$.Site.Data.linkIndex.index}}
const links = {{$.Site.Data.linkIndex.links}}
+ const content = {{$.Site.Data.contentIndex}}
const curPage = {{ strings.TrimRight "/" .Page.RelPermalink }}
const pathColors = {{$.Site.Data.graphConfig.paths}}
+ let depth = {{$.Site.Data.graphConfig.depth}}
const parseIdsFromLinks = (links) => [...(new Set(links.flatMap(link => ([link.source, link.target]))))]
+ const neighbours = new Set()
+ const wl = [curPage || "/", "__SENTINEL"]
+ if (depth >= 0) {
+ while (depth >= 0 && wl.length > 0) {
+ // compute neighbours
+ const cur = wl.shift()
+ console.log(depth, cur, wl)
+ if (cur === "__SENTINEL") {
+ depth--
+ wl.push("__SENTINEL")
+ } else {
+ neighbours.add(cur)
+ const outgoing = index.links[cur] || []
+ const incoming = index.backlinks[cur] || []
+ console.log(incoming)
+ wl.push(...outgoing.map(l => l.target), ...incoming.map(l => l.source))
+ }
+ }
+ } else {
+ parseIdsFromLinks(links).forEach(id => neighbours.add(id))
+ }
+
const data = {
- nodes: parseIdsFromLinks(links).map(id => ({id})),
- links,
+ nodes: [...neighbours].map(id => ({id})),
+ links: links.filter(l => neighbours.has(l.source) && neighbours.has(l.target)),
}
const color = (d) => {
@@ -69,10 +93,8 @@
const width = document.getElementById("graph-container").offsetWidth
const simulation = d3.forceSimulation(data.nodes)
- .force("charge", d3.forceManyBody().strength(-20))
- .force("link", d3.forceLink(data.links)
- .id(d => d.id)
- )
+ .force("charge", d3.forceManyBody().strength(-30))
+ .force("link", d3.forceLink(data.links).id(d => d.id))
.force("center", d3.forceCenter());
const svg = d3.select('#graph-container')
@@ -137,7 +159,7 @@
const neighbours = parseIdsFromLinks([...(index.links[d.id] || []), ...(index.backlinks[d.id] || [])])
const neighbourNodes = d3.selectAll(".node").filter(d => neighbours.includes(d.id))
const currentId = d.id
- const links = d3.selectAll(".link").filter(d => d.source.id === currentId || d.target.id === currentId)
+ const linkNodes = d3.selectAll(".link").filter(d => d.source.id === currentId || d.target.id === currentId)
// highlight neighbour nodes
neighbourNodes
@@ -146,7 +168,7 @@
.attr("fill", color)
// highlight links
- links
+ linkNodes
.transition()
.duration(200)
.attr("stroke", "var(--g-link-active)")
@@ -165,9 +187,9 @@
.attr("fill", color)
const currentId = d.id
- const links = d3.selectAll(".link").filter(d => d.source.id === currentId || d.target.id === currentId)
+ const linkNodes = d3.selectAll(".link").filter(d => d.source.id === currentId || d.target.id === currentId)
- links
+ linkNodes
.transition()
.duration(200)
.attr("stroke", "var(--g-link)")
@@ -184,7 +206,7 @@
const labels = graphNode.append("text")
.attr("dx", 12)
.attr("dy", ".35em")
- .text((d) => d.id.replace("%20", "-"))
+ .text((d) => content[d.id.replace("%20", "-")]?.title || "Untitled")
.style("opacity", 0)
.style("pointer-events", "none")
.call(drag(simulation));
@@ -216,4 +238,4 @@
.attr("x", d => d.x)
.attr("y", d => d.y);
});
-</script>
\ No newline at end of file
+</script>
--
Gitblit v1.10.0