Skip to content

Commit 0b9f79e

Browse files
authored
feat(graph): obsidianLikeFocusOnHover (#1017)
* feat(graph): obsidianLikeFocusOnHover * fix: prettier * fix: remove option from config * fix: for when opacityOld < 0.2 * fix: prettier
1 parent 94fbf5b commit 0b9f79e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

quartz/components/scripts/graph.inline.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
223223
.transition()
224224
.duration(200)
225225
.style("opacity", 0.2)
226+
227+
d3.selectAll<HTMLElement, NodeData>(".node")
228+
.filter((d) => !connectedNodes.includes(d.id))
229+
.nodes()
230+
.map((it) => d3.select(it.parentNode as HTMLElement).select("text"))
231+
.forEach((it) => {
232+
let opacity = parseFloat(it.style("opacity"))
233+
it.transition()
234+
.duration(200)
235+
.attr("opacityOld", opacity)
236+
.style("opacity", Math.min(opacity, 0.2))
237+
})
226238
}
227239

228240
// highlight links
@@ -245,6 +257,12 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
245257
if (focusOnHover) {
246258
d3.selectAll<HTMLElement, NodeData>(".link").transition().duration(200).style("opacity", 1)
247259
d3.selectAll<HTMLElement, NodeData>(".node").transition().duration(200).style("opacity", 1)
260+
261+
d3.selectAll<HTMLElement, NodeData>(".node")
262+
.filter((d) => !connectedNodes.includes(d.id))
263+
.nodes()
264+
.map((it) => d3.select(it.parentNode as HTMLElement).select("text"))
265+
.forEach((it) => it.transition().duration(200).style("opacity", it.attr("opacityOld")))
248266
}
249267
const currentId = d.id
250268
const linkNodes = d3

0 commit comments

Comments
 (0)