diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-07-28 17:57:04 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-07-28 17:57:04 +0200 |
commit | f9aac2c130dbec61c9466ae4b932aa9b4158d309 (patch) | |
tree | 8ea38cca9d5e966955194b650274d3b61416a219 | |
parent | 173963d752bc8ea9c18d4165c0bcf88097c69cbe (diff) |
added some more tweaks
-rw-r--r-- | components/config.ts | 4 | ||||
-rw-r--r-- | components/tweaks.tsx | 32 | ||||
-rw-r--r-- | org-roam-ui.el | 36 | ||||
-rw-r--r-- | pages/index.tsx | 11 |
4 files changed, 49 insertions, 34 deletions
diff --git a/components/config.ts b/components/config.ts index 3331288..d6c2296 100644 --- a/components/config.ts +++ b/components/config.ts @@ -16,7 +16,9 @@ export const initialPhysics = { enabled: true, charge: -350, collision: true, - collisionStrength: 0, + collisionStrength: 20, + centering: true, + centeringStrength: 0.05, linkStrength: 0.1, linkIts: 1, particles: false, diff --git a/components/tweaks.tsx b/components/tweaks.tsx index bfb932c..f9c58a1 100644 --- a/components/tweaks.tsx +++ b/components/tweaks.tsx @@ -207,11 +207,12 @@ export const Tweaks = (props: TweakProps) => { onChange={() => setPhysics({ ...physics, collision: !physics.collision })} > <SliderWithInfo - value={physics.collisionStrength * 10} + value={physics.collisionStrength / 5} onChange={(value) => - setPhysics({ ...physics, collisionStrength: value / 10 }) + setPhysics({ ...physics, collisionStrength: value * 5 }) } - label="Strength" + label="Collision Radius" + infoText="Easy with this one, high values can lead to a real jiggly mess" /> </EnableSection> <SliderWithInfo @@ -251,21 +252,28 @@ export const Tweaks = (props: TweakProps) => { color="gray.800" > <SliderWithInfo - label="Iterations per tick" - min={1} - max={10} - step={1} - value={physics.iterations} - onChange={(v) => setPhysics({ ...physics, iterations: v })} - infoText="Number of times the physics simulation iterates per simulation step" - /> - <SliderWithInfo label="Stabilization rate" value={physics.alphaDecay * 50} onChange={(value) => setPhysics({ ...physics, alphaDecay: value / 50 }) } /> + <EnableSection + label="Keeps nodes centered" + value={physics.centering} + onChange={() => + setPhysics({ ...physics, centering: !physics.centering }) + } + infoText="Keeps the nodes in the center of the viewport. If disabled you can drag the nodes anywhere you want." + > + <SliderWithInfo + label="Centering Strength" + value={physics.centeringStrength} + max={2} + step={0.1} + onChange={(v) => setPhysics({ ...physics, centeringStrength: v })} + /> + </EnableSection> </VStack> </AccordionPanel> </AccordionItem> diff --git a/org-roam-ui.el b/org-roam-ui.el index c218aee..12a1623 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -105,20 +105,20 @@ This serves the web-build and API over HTTP." (websocket-server 35903 :host 'local - :on-open (lambda (ws) (progn (setq oru-ws ws) (org-roam-ui--send-graphdata) (message "Connection established with org-roam-ui"))) + :on-open (lambda (ws) (progn (setq oru-ws ws) (org-roam-ui--send-graphdata) (org-roam-ui-sync-theme--advice) (message "Connection established with org-roam-ui"))) :on-close (lambda (_websocket) (setq oru-ws nil) (message "Connection with org-roam-ui closed succesfully.")))) - (if (boundp 'counsel-load-theme + (if (boundp 'counsel-load-theme) (advice-add 'counsel-load-theme :after #'org-roam-ui-sync-theme--advice) - (advice-add 'load-theme :after #'org-roam-ui-sync-theme-manually))) + (advice-add 'load-theme :after #'org-roam-ui-sync-theme-manually)) (add-hook 'post-command-hook #'org-roam-ui--update-current-node) (add-hook 'post-command-hook #'org-roam-ui-update)) (t (progn (remove-hook 'post-command-hook #'org-roam-ui-update) (remove-hook 'post-command-hook #'org-roam-ui--update-current-node) - (if (boundp 'counsel-load-theme + (if (boundp 'counsel-load-theme) (advice-remove 'counsel-load-theme #'org-roam-ui-sync-theme--advice) - (advice-remove 'load-theme #'org-roam-ui-sync-theme--advice))) + (advice-remove 'load-theme #'org-roam-ui-sync-theme--advice)) (websocket-server-close org-roam-ui-ws) (delete-process org-roam-ui-ws) (httpd-stop))))) @@ -240,19 +240,19 @@ This function is added to `post-command-hook'." )) -(defservlet* theme text/stream () - (progn) - (if org-roam-ui-sync-theme - (if (boundp 'doom-themes--colors) - (let* - ((colors (butlast doom-themes--colors (- (length doom-themes--colors) 25))) ui-theme (list nil)) - (progn - (dolist (color colors) (push (cons (car color) (car (cdr color))) ui-theme)) - ui-theme))))) - (insert (format "data: %s\n\n" (json-encode (org-roam-ui-get-theme))))) - (when org-roam-ui-custom-theme - (insert (format "data %s\n\n" (json-encode org-roam-ui-custom-theme))))) - (httpd-send-header t "text/event-stream" 200 :Access-Control-Allow-Origin "*")) +;; (defservlet* theme text/stream () +;; (progn) +;; (if org-roam-ui-sync-theme +;; (if (boundp 'doom-themes--colors) +;; (let* +;; ((colors (butlast doom-themes--colors (- (length doom-themes--colors) 25))) ui-theme (list nil)) +;; (progn +;; (dolist (color colors) (push (cons (car color) (car (cdr color))) ui-theme)) +;; ui-theme)) +;; (insert (format "data: %s\n\n" (json-encode (org-roam-ui-get-theme))))) +;; (when org-roam-ui-custom-theme +;; (insert (format "data %s\n\n" (json-encode org-roam-ui-custom-theme))))) +;; (httpd-send-header t "text/event-stream" 200 :Access-Control-Allow-Origin "*")) (provide 'org-roam-ui) ;;; org-roam-ui.el ends here diff --git a/pages/index.tsx b/pages/index.tsx index db925da..e330b91 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -360,11 +360,16 @@ export const Graph = function (props: GraphProps) { fg.d3Force('y', null) threeDim ? fg.d3Force('z', null) : null } - + physics.centering + ? fg.d3Force('center', d3.forceCenter().strength(physics.centeringStrength)) + : fg.d3Force('center', null) physics.linkStrength && fg.d3Force('link').strength(physics.linkStrength) physics.linkIts && fg.d3Force('link').iterations(physics.linkIts) physics.charge && fg.d3Force('charge').strength(physics.charge) - fg.d3Force('collide', physics.collision ? d3.forceCollide().radius(20) : null) + fg.d3Force( + 'collide', + physics.collision ? d3.forceCollide().radius(physics.collisionStrength) : null, + ) })() }) @@ -585,7 +590,7 @@ export const Graph = function (props: GraphProps) { })) }, onNodeHover: (node) => { - if (!physics.hover) { + if (!physics.highlight) { return } setHoverNode(node) |