summaryrefslogtreecommitdiff
path: root/util/getNodeColorById.ts
blob: d2c198b6ba3b698ccebc377bfc001dcb081e94a6 (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
import { initialColoring, initialVisuals } from '../components/config'
import { LinksByNodeId } from '../pages'
import { numberWithinRange } from './numberWithinRange'

export const getNodeColorById = ({
  id,
  linksByNodeId,
  visuals,
  coloring,
  cluster,
}: {
  id: string
  linksByNodeId: LinksByNodeId
  visuals: typeof initialVisuals
  cluster: any
  coloring: typeof initialColoring
}) => {
  const linklen = linksByNodeId[id!]?.length ?? 0
  if (coloring.method === 'degree') {
    return visuals.nodeColorScheme[
      numberWithinRange(linklen, 0, visuals.nodeColorScheme.length - 1)
    ]
  }
  return visuals.nodeColorScheme[linklen && cluster[id] % visuals.nodeColorScheme.length]
}