summaryrefslogtreecommitdiff
path: root/util/nodeSize.ts
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2022-09-27 15:09:17 +0200
committerThomas F. K. Jorna <[email protected]>2022-09-27 15:09:17 +0200
commita575d14b6621d5464d33d52ca642f2db70c3e370 (patch)
tree5a1d38227a93b1bf2b152ed4af5820a59c34cf91 /util/nodeSize.ts
parentfa84c052b221d157fa869cd4912acd538b5005a0 (diff)
fix: move a ton of functions to separate files
Diffstat (limited to 'util/nodeSize.ts')
-rw-r--r--util/nodeSize.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/util/nodeSize.ts b/util/nodeSize.ts
new file mode 100644
index 0000000..3601c1e
--- /dev/null
+++ b/util/nodeSize.ts
@@ -0,0 +1,34 @@
+import { filter } from '@chakra-ui/react'
+import { initialVisuals } from '../components/config'
+import { LinksByNodeId } from '../pages'
+import { NodeObject } from 'force-graph'
+
+export const nodeSize = ({
+ linksByNodeId,
+ visuals,
+ highlightedNodes,
+ previouslyHighlightedNodes,
+ opacity,
+ node,
+}: {
+ node: NodeObject
+ visuals: typeof initialVisuals
+
+ highlightedNodes: Record<string, any>
+ previouslyHighlightedNodes: Record<string, any>
+ opacity: number
+ linksByNodeId: LinksByNodeId
+}) => {
+ const links = linksByNodeId[node.id!] ?? []
+ const parentNeighbors = links.length ? links.filter((link) => link.type === 'parent').length : 0
+ const basicSize =
+ 3 + links.length * visuals.nodeSizeLinks - (!filter.parent ? parentNeighbors : 0)
+ if (visuals.highlightNodeSize === 1) {
+ return basicSize
+ }
+ const highlightSize =
+ highlightedNodes[node.id!] || previouslyHighlightedNodes[node.id!]
+ ? 1 + opacity * (visuals.highlightNodeSize - 1)
+ : 1
+ return basicSize * highlightSize
+}