summaryrefslogtreecommitdiff
path: root/util/getNodeColorById.ts
diff options
context:
space:
mode:
Diffstat (limited to 'util/getNodeColorById.ts')
-rw-r--r--util/getNodeColorById.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/util/getNodeColorById.ts b/util/getNodeColorById.ts
new file mode 100644
index 0000000..d2c198b
--- /dev/null
+++ b/util/getNodeColorById.ts
@@ -0,0 +1,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]
+}