summaryrefslogtreecommitdiff
path: root/pages
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-07-29 13:50:17 +0200
committerThomas F. K. Jorna <[email protected]>2021-07-29 13:50:17 +0200
commit1af5088eccd00fa16bdf930a356893c99c7411fe (patch)
treea0e40a8f89c129c9c3b90a7f076e3a9935715d11 /pages
parent1541dde979d201860f7f43e369f050d4ece00574 (diff)
made websocket automatically reconnect
Diffstat (limited to 'pages')
-rw-r--r--pages/index.tsx28
1 files changed, 14 insertions, 14 deletions
diff --git a/pages/index.tsx b/pages/index.tsx
index a99bb0b..56e287a 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -32,6 +32,9 @@ import { Tweaks } from '../components/tweaks'
import { ThemeContext, ThemeContextProps } from './themecontext'
import SpriteText from 'three-spritetext'
+
+import ReconnectingWebSocket from 'reconnecting-websocket'
+
// react-force-graph fails on import when server-rendered
// https://github.com/vasturiano/react-force-graph/issues/155
const ForceGraph2D = (
@@ -131,7 +134,7 @@ export function GraphPage() {
}
const { setEmacsTheme } = useContext(ThemeContext)
useEffect(() => {
- const socket = new WebSocket('ws://localhost:35903')
+ const socket = new ReconnectingWebSocket('ws://localhost:35903')
socket.addEventListener('open', (event) => {
console.log('Connection with Emacs established')
})
@@ -271,9 +274,6 @@ export const Graph = function (props: GraphProps) {
const getNeighborNodes = (id: string) => {
const links = linksByNodeId[id]! ?? []
- if (!links.length) {
- return [id]
- }
return Object.fromEntries(
[id as string, ...links.flatMap((link) => [link.source, link.target])].map((nodeId) => [
nodeId,
@@ -387,23 +387,23 @@ export const Graph = function (props: GraphProps) {
const fg = threeDim ? graph3dRef.current : graph2dRef.current
const d3 = await d3promise
if (physics.gravityOn) {
- fg.d3Force(0, d3.forceX().strength(physics.gravity))
- fg.d3Force(0, d3.forceY().strength(physics.gravity))
+ fg.d3Force('x', d3.forceX().strength(physics.gravity))
+ fg.d3Force('y', d3.forceY().strength(physics.gravity))
if (threeDim) {
if (physics.galaxy) {
- fg.d3Force(0, d3.forceX().strength(physics.gravity / 5))
- fg.d3Force(0, d3.forceZ().strength(physics.gravity / 5))
+ fg.d3Force('x', d3.forceX().strength(physics.gravity / 5))
+ fg.d3Force('z', d3.forceZ().strength(physics.gravity / 5))
} else {
- fg.d3Force(0, d3.forceX().strength(physics.gravity))
- fg.d3Force(0, d3.forceZ().strength(physics.gravity))
+ fg.d3Force('x', d3.forceX().strength(physics.gravity))
+ fg.d3Force('z', d3.forceZ().strength(physics.gravity))
}
} else {
- fg.d3Force(0, null)
+ fg.d3Force('z', null)
}
} else {
- fg.d3Force(0, null)
- fg.d3Force(0, null)
- threeDim ? fg.d3Force(0, null) : null
+ fg.d3Force('x', null)
+ fg.d3Force('y', null)
+ threeDim ? fg.d3Force('z', null) : null
}
physics.centering
? fg.d3Force('center', d3.forceCenter().strength(physics.centeringStrength))