From 8844a10cdd42dd39b4d4dbe058910b4612d9518c Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Tue, 27 Jul 2021 18:18:38 +0200 Subject: more refactoring --- pages/index.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index c27a0a3..f35e48c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -351,13 +351,12 @@ export const Graph = function (props: GraphProps) { const lastHoverNode = useRef(null) useEffect(() => { - if (hoverNode) { - lastHoverNode.current = hoverNode - } if (!physics.highlightAnim) { return hoverNode ? setOpacity(1) : setOpacity(0) } - + if (hoverNode) { + lastHoverNode.current = hoverNode + } if (hoverNode) { fadeIn() } else { @@ -376,6 +375,7 @@ export const Graph = function (props: GraphProps) { () => d3int.interpolate(theme.colors.gray[500], theme.colors.gray[400]), [theme], ) + const graphCommonProps: ComponentPropsWithoutRef = { graphData: scopedGraphData, width: windowWidth, @@ -383,12 +383,12 @@ export const Graph = function (props: GraphProps) { backgroundColor: theme.white, nodeLabel: (node) => (node as OrgRoamNode).title, nodeColor: (node) => { + const links = linksByNodeId[node.id!] ?? [] + const wasHighlightedNode = links.some((link) => + isLinkRelatedToNode(link, lastHoverNode.current), + ) if (!physics.colorful) { - return Object.keys(highlightedNodes).length === 0 - ? lastHoverNode.current?.id! === node.id! - ? interPurple(opacity) - : interGray(opacity) - : highlightedNodes[node.id!] + return wasHighlightedNode || highlightedNodes[node.id!] ? interPurple(opacity) : interGray(opacity) } -- cgit v1.2.3