diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-08-03 16:11:49 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-08-03 16:11:49 +0200 |
commit | 57ff943843831fbe041ec2e2a923fa70a2f805f3 (patch) | |
tree | 4b26429e343d3c6ef5df977b27367bd6ed3eb904 /pages | |
parent | a0f0e5aabee5b3bad68afb7eab092b684275e6fa (diff) |
feature: tagwhitelist + better compatibility with existing filters
Diffstat (limited to 'pages')
-rw-r--r-- | pages/index.tsx | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/pages/index.tsx b/pages/index.tsx index b31e533..70f895a 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -409,32 +409,53 @@ 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.orphans) { + 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 + } 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) => { - if (filter.tags.length) { + if (filter.tagsBlacklist.length || filter.tagsWhitelist.length) { const sourceId = typeof link.source === 'object' ? link.source.id! : (link.source as string) const targetId = typeof link.target === 'object' ? link.target.id! : (link.target as string) return ( @@ -696,7 +717,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 = @@ -784,7 +805,9 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { const needsHighlighting = linkIsHighlighted || linkWasHighlighted const roamLink = link as OrgRoamLink if (visuals.citeLinkColor && roamLink.type === 'cite') { - return getThemeColor(visuals.citeLinkColor) + return needsHighlighting + ? '#ffffff' /*highlightColors[visuals.citeLinkColor][visuals.citeLinkHighlightColor] */ + : getThemeColor(visuals.citeLinkColor) } return getLinkColor(sourceId as string, targetId as string, needsHighlighting) |