From 4e3d884c402b7dc7d12f0cae88a9a312b10f166f Mon Sep 17 00:00:00 2001 From: Kirill Rogovoy Date: Thu, 29 Jul 2021 17:18:52 +0300 Subject: Minor refactoring --- pages/index.tsx | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 51b21fc..e0e8b6e 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -246,25 +246,19 @@ export const Graph = function (props: GraphProps) { const filteredNodes = useMemo(() => { return graphData.nodes.filter((node) => { const links = linksByNodeId[node.id as string] ?? [] - let showNode = true - if (filter.orphans) { - if (filter.parents) { - showNode = links.length !== 0 - } else { - if (links.length === 0) { - showNode = false - } else { - if ( - links.length - - links.filter((link) => link.type === 'parent' || link.type === 'cite').length === - 0 - ) { - showNode = false - } - } - } + if (!filter.orphans) { + return true } - return showNode + + if (filter.parents) { + return links.length !== 0 + } + + if (links.length === 0) { + return false + } + + return !links.some(link => !['parent', 'cite'].includes(link.type)) }) }, [filter, graphData.nodes, linksByNodeId]) @@ -491,7 +485,7 @@ export const Graph = function (props: GraphProps) { if (!visuals.linkColorScheme) { return highlightColors[getLinkNodeColor(sourceId, targetId)][visuals.linkHighlight](opacity) } - + return highlightColors[visuals.linkColorScheme][visuals.linkHighlight](opacity) } -- cgit v1.2.3