diff options
author | Thomas F. K. Jorna <[email protected]> | 2022-09-27 16:32:13 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-09-27 16:32:13 +0200 |
commit | 6f783297f37e95d083b32a7160afcb55e309e883 (patch) | |
tree | af9fdc3db50ecbc61036d88c81eeea3703ff17cc /util/nodeSize.ts | |
parent | 16a8da9e5107833032893bc4c0680b368ac423ac (diff) | |
parent | 1936250b99b8747d841edd83002ed20ec12aa793 (diff) |
feat: add ability to add/remove nodes to/from the local graph from emacs
Adds the commands `org-roam-ui-add-to-local-graph` and `org-roam-ui-remove-from-local-graph`
Diffstat (limited to 'util/nodeSize.ts')
-rw-r--r-- | util/nodeSize.ts | 34 |
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 +} |