diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-07-29 16:24:47 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-07-29 16:24:47 +0200 |
commit | 590e7c40526d44aa671c578ba26b9c5e4454ec6c (patch) | |
tree | 097b4eb38d253779aacb7d7f20c4b1c323be9581 /pages | |
parent | 1dad6ddec6fd50dedee1319057b41316c578cbe9 (diff) | |
parent | 4e3d884c402b7dc7d12f0cae88a9a312b10f166f (diff) |
solve merge conflicts
Diffstat (limited to 'pages')
-rw-r--r-- | pages/index.tsx | 80 |
1 files changed, 31 insertions, 49 deletions
diff --git a/pages/index.tsx b/pages/index.tsx index ae1b4ef..3540a4c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -76,16 +76,7 @@ export function GraphPage() { const nodeByIdRef = useRef<NodeById>({}) const linksByNodeIdRef = useRef<LinksByNodeId>({}) - /* const fetchGraphData = () => { - * return fetch('http://localhost:35901/graph') - * .then((res) => res.json()) - * .then((orgRoamGraphData) => { - * console.log('fetching graphdata') - * parseGraphData(orgRoamGraphData) - * }) - * } - */ - const parseGraphData = (orgRoamGraphData: OrgRoamGraphReponse) => { + const updateGraphData = (orgRoamGraphData: OrgRoamGraphReponse) => { const nodesByFile = orgRoamGraphData.nodes.reduce<NodesByFile>((acc, node) => { return { ...acc, @@ -141,28 +132,27 @@ export function GraphPage() { const graph3dRef = useRef<any>(null) useEffect(() => { +<<<<<<< HEAD const fg = threeDim ? graph3dRef.current : graph2dRef.current const socket = new ReconnectingWebSocket('ws://localhost:35903') socket.addEventListener('open', (event) => { +======= + const socket = new WebSocket('ws://localhost:35903') + socket.addEventListener('open', () => { +>>>>>>> 4e3d884c402b7dc7d12f0cae88a9a312b10f166f console.log('Connection with Emacs established') }) socket.addEventListener('message', (event) => { const message = JSON.parse(event.data) - console.log(typeof message.type) switch (message.type) { case 'graphdata': - parseGraphData(message.data) - break + return updateGraphData(message.data) case 'theme': - console.log('Received theme data') - setEmacsTheme(message.data) - break + return setEmacsTheme(message.data) case 'command': - console.log('command') switch (message.data.commandName) { case 'follow': - setEmacsNodeId(message.data.id) - break + return setEmacsNodeId(message.data.id) case 'zoom': { console.log(message) const links = linksByNodeIdRef.current[message.data.id!] ?? [] @@ -178,19 +168,22 @@ export function GraphPage() { /* setBehavior({ ...behavior, followLocalorZoom: !behavior.followLocalOrZoom }) */ } default: - console.log('oopsie whoopsie') + return console.error('unknown message type', message.type) } } }) - // fetchGraphData() }, []) +<<<<<<< HEAD useEffect(() => { if (!emacsNodeId) { return } //fetchGraphData() }, [emacsNodeId]) +======= + const [threeDim, setThreeDim] = useState(false) +>>>>>>> 4e3d884c402b7dc7d12f0cae88a9a312b10f166f if (!graphData) { return null @@ -313,25 +306,19 @@ export const Graph = function (props: GraphProps) { const filteredNodes = useMemo(() => { return graphData.nodes.filter((node) => { const links = linksByNodeId[node.id as string] ?? [] - let showNode = true - if (filter.orphans) { - if (filter.parents) { - showNode = links.length !== 0 - } else { - if (links.length === 0) { - showNode = false - } else { - if ( - links.length - - links.filter((link) => link.type === 'parent' || link.type === 'cite').length === - 0 - ) { - showNode = false - } - } - } + if (!filter.orphans) { + return true + } + + if (filter.parents) { + return links.length !== 0 + } + + if (links.length === 0) { + return false } - return showNode + + return !links.some(link => !['parent', 'cite'].includes(link.type)) }) }, [filter, graphData.nodes, linksByNodeId]) @@ -494,7 +481,6 @@ export const Graph = function (props: GraphProps) { visuals.nodeHighlight, visuals.linkColorScheme, ]) - const highlightedLinks = useMemo(() => linksByNodeId[hoverNode?.id!] ?? [], [hoverNode]) const previouslyHighlightedLinks = useMemo( () => linksByNodeId[lastHoverNode.current?.id!] ?? [], @@ -537,14 +523,12 @@ export const Graph = function (props: GraphProps) { const nodeColor = getLinkNodeColor(sourceId, targetId) return theme.colors[nodeColor][500] } + if (!needsHighlighting && !visuals.linkColorScheme) { const nodeColor = getLinkNodeColor(sourceId, targetId) return theme.colors[nodeColor][500] } - if (!needsHighlighting && !visuals.linkColorScheme) { - const nodeColor = getLinkNodeColor(sourceId, targetId) - return theme.colors[nodeColor][500] - } + if (!needsHighlighting) { return theme.colors.gray[visuals.linkColorScheme] } @@ -553,12 +537,15 @@ export const Graph = function (props: GraphProps) { const nodeColor = getLinkNodeColor(sourceId, targetId) return theme.colors[nodeColor][500] } + if (!visuals.linkHighlight) { return theme.colors.gray[visuals.linkColorScheme] } + if (!visuals.linkColorScheme) { return highlightColors[getLinkNodeColor(sourceId, targetId)][visuals.linkHighlight](opacity) } + return highlightColors[visuals.linkColorScheme][visuals.linkHighlight](opacity) } @@ -661,11 +648,6 @@ export const Graph = function (props: GraphProps) { linkDirectionalParticles: physics.particles ? physics.particlesNumber : undefined, linkColor: (link) => { - /* if (!physics.highlight || !visuals.linkHighlight) { - * return visuals.linkColorScheme - * ? theme.colors.gray[visuals.linkColorScheme] - * : theme.colors[getLinkNodeColor(link)][500] - * } */ const sourceId = typeof link.source === 'object' ? link.source.id! : (link.source as string) const targetId = typeof link.target === 'object' ? link.target.id! : (link.target as string) const linkIsHighlighted = isLinkRelatedToNode(link, centralHighlightedNode.current) |