summaryrefslogtreecommitdiff
path: root/util/nodeSize.ts
blob: 3601c1e3c8edfdd801f3392038e714cb9d6a40d1 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
}