summaryrefslogtreecommitdiff
path: root/util/getNodeColor.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/getNodeColor.ts
parentfa84c052b221d157fa869cd4912acd538b5005a0 (diff)
fix: move a ton of functions to separate files
Diffstat (limited to 'util/getNodeColor.ts')
-rw-r--r--util/getNodeColor.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/util/getNodeColor.ts b/util/getNodeColor.ts
new file mode 100644
index 0000000..f25a15b
--- /dev/null
+++ b/util/getNodeColor.ts
@@ -0,0 +1,75 @@
+import { OrgRoamNode } from '../api'
+import { initialColoring, initialVisuals } from '../components/config'
+import { LinksByNodeId } from '../pages'
+import { getNodeColorById } from './getNodeColorById'
+import { getThemeColor } from './getThemeColor'
+
+export const getNodeColor = ({
+ node,
+ theme,
+ highlightedNodes,
+ previouslyHighlightedNodes,
+ visuals,
+ tagColors,
+ highlightColors,
+ opacity,
+ emacsNodeId,
+ linksByNodeId,
+ cluster,
+ coloring,
+}: {
+ node: OrgRoamNode
+ theme: any
+ visuals: typeof initialVisuals
+ highlightedNodes: Record<string, any>
+ previouslyHighlightedNodes: Record<string, any>
+ tagColors: Record<string, any>
+ highlightColors: Record<string, any>
+ opacity: number
+ emacsNodeId: string | null
+ linksByNodeId: LinksByNodeId
+ cluster: any
+ coloring: typeof initialColoring
+}) => {
+ const needsHighlighting = highlightedNodes[node.id!] || previouslyHighlightedNodes[node.id!]
+ //const needsHighlighting = hoverNode?.id === node.id! || lastHoverNode?.current?.id === node.id
+ // if we are matching the node color and don't have a highlight color
+ // or we don't have our own scheme and we're not being highlighted
+ if (visuals.emacsNodeColor && node.id === emacsNodeId) {
+ return getThemeColor(visuals.emacsNodeColor, theme)
+ }
+ if (tagColors && node?.tags.some((tag) => tagColors[tag])) {
+ const tagColor = tagColors[node?.tags.filter((tag) => tagColors[tag])[0]]
+ return needsHighlighting
+ ? highlightColors[tagColor][tagColor](visuals.highlightFade * opacity)
+ : highlightColors[tagColor][visuals.backgroundColor](visuals.highlightFade * opacity)
+ }
+ if (visuals.citeNodeColor && node?.properties?.ROAM_REFS && node?.properties?.FILELESS) {
+ return needsHighlighting
+ ? getThemeColor(visuals.citeNodeColor, theme)
+ : highlightColors[visuals.citeNodeColor][visuals.backgroundColor](
+ visuals.highlightFade * opacity,
+ )
+ }
+ if (visuals.refNodeColor && node.properties.ROAM_REFS) {
+ return needsHighlighting
+ ? getThemeColor(visuals.refNodeColor, theme)
+ : highlightColors[visuals.refNodeColor][visuals.backgroundColor](
+ visuals.highlightFade * opacity,
+ )
+ }
+ if (!needsHighlighting) {
+ return highlightColors[
+ getNodeColorById({ id: node.id as string, cluster, coloring, linksByNodeId, visuals })
+ ][visuals.backgroundColor](visuals.highlightFade * opacity)
+ }
+ if (!visuals.nodeHighlight) {
+ return getThemeColor(
+ getNodeColorById({ id: node.id as string, cluster, coloring, linksByNodeId, visuals }),
+ theme,
+ )
+ }
+ return highlightColors[
+ getNodeColorById({ id: node.id as string, cluster, coloring, linksByNodeId, visuals })
+ ][visuals.nodeHighlight](opacity)
+}