diff options
Diffstat (limited to 'pages')
-rw-r--r-- | pages/index.tsx | 85 |
1 files changed, 57 insertions, 28 deletions
diff --git a/pages/index.tsx b/pages/index.tsx index 7d947e0..c829fef 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -92,7 +92,7 @@ export function GraphPage() { const tagsRef = useRef<Tags>([]) const updateGraphData = (orgRoamGraphData: OrgRoamGraphReponse) => { - tagsRef.current = orgRoamGraphData.tags + tagsRef.current = orgRoamGraphData.tags ?? [] const nodesByFile = orgRoamGraphData.nodes.reduce<NodesByFile>((acc, node) => { return { ...acc, @@ -417,44 +417,64 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { ) }, [centralHighlightedNode.current, linksByNodeId]) + const hiddenNodeIdsRef = useRef<NodeById>({}) const filteredGraphData = useMemo(() => { - const filteredNodes = graphData.nodes.filter((nodeArg) => { - const node = nodeArg as OrgRoamNode - const links = linksByNodeId[node.id as string] ?? [] - if (filter.tags.length && node.tags.length) { - return !filter.tags.some((tag) => node.tags.indexOf(tag) > -1) - } - if (filter.fileless_cites && node.properties.FILELESS) { - return false + hiddenNodeIdsRef.current = {} + const filteredNodes = graphData.nodes + .filter((nodeArg) => { + const node = nodeArg as OrgRoamNode + if ( + filter.tagsBlacklist.length && + filter.tagsBlacklist.some((tag) => node.tags.indexOf(tag) > -1) + ) { + hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } + return false + } + if ( + filter.tagsWhitelist.length > 0 && + !filter.tagsWhitelist.some((tag) => node.tags.indexOf(tag) > -1) + ) { + hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } + return false + } + if (filter.fileless_cites && node.properties.FILELESS) { + hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node } + return false } - - if (!filter.orphans) { return true - } + }) + .filter((nodeArg) => { + const node = nodeArg as OrgRoamNode + const links = linksByNodeId[node.id as string] ?? [] + const unhiddenLinks = links.filter( + (link) => + !hiddenNodeIdsRef.current[link.source] && !hiddenNodeIdsRef.current[link.target], + ) - if (filter.parents) { - return links.length !== 0 - } + if (!filter.orphans) { + return true + } - if (links.length === 0) { - return false - } + if (filter.parents) { + return unhiddenLinks.length !== 0 + } - return links.some((link) => !['parent', 'ref'].includes(link.type)) - }) + if (unhiddenLinks.length === 0) { + return false + } + + return unhiddenLinks.some((link) => !['parent', 'ref'].includes(link.type)) + }) const filteredNodeIds = filteredNodes.map((node) => node.id as string) const filteredLinks = graphData.links.filter((link) => { const [sourceId, targetId] = normalizeLinkEnds(link) - if ( - !( + if (filter.tagsBlacklist.length || filter.tagsWhitelist.length){ + return ( filteredNodeIds.includes(sourceId as string) && filteredNodeIds.includes(targetId as string) ) - ) { - return false } - const linkRoam = link as OrgRoamLink return filter.parents || linkRoam.type !== 'parent' }) @@ -571,6 +591,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { visuals.nodeHighlight || [], visuals.citeNodeColor || [], visuals.citeLinkColor || [], + visuals.citeLinkHighlightColor || [], ) return Object.fromEntries( @@ -711,7 +732,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { nodeVal: (node) => { const links = linksByNodeId[node.id!] ?? [] const parentNeighbors = links.length - ? links.filter((link) => link.type === 'parent' || link.type === 'cite').length + ? links.filter((link) => link.type === 'parent').length : 0 const basicSize = 3 + links.length - (!filter.parents ? parentNeighbors : 0) const highlightSize = @@ -799,10 +820,18 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { const needsHighlighting = linkIsHighlighted || linkWasHighlighted const roamLink = link as OrgRoamLink if (visuals.refLinkColor && roamLink.type === 'ref') { - return getThemeColor(visuals.refLinkColor) + return needsHighlighting && (visuals.refLinkHighlightColor || visuals.linkHighlight) + ? highlightColors[visuals.refLinkColor][ + visuals.refLinkHighlightColor || visuals.linkHighlight + ](opacity) + : getThemeColor(visuals.refLinkColor) } if (visuals.citeLinkColor && roamLink.type === 'cite') { - return getThemeColor(visuals.citeLinkColor) + return needsHighlighting && (visuals.citeLinkHighlightColor || visuals.linkHighlight) + ? highlightColors[visuals.citeLinkColor][ + visuals.citeLinkHighlightColor || visuals.linkHighlight + ](opacity) + : getThemeColor(visuals.citeLinkColor) } return getLinkColor(sourceId as string, targetId as string, needsHighlighting) |