Created
May 30, 2022 20:56
-
-
Save QWxleA/1b0b3483bc0b23a45da94520d1194d9f to your computer and use it in GitHub Desktop.
Logseq graph chocolate milk edition: /src/main/frontend/extensions/graph/pixi.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn layout! | |
[nodes links] | |
(let [nodes-count (count nodes) ;; no of pages | |
simulation (forceSimulation nodes) | |
qwxlea_distanceMax_large 4000 ;; Default: 4000 | |
qwxlea_distanceMax_small 2200 ;; Default: 600 - larger better with long filenames | |
qwxlea_link_distance 280 ;; Default: 180 - legth of sticks(?) | |
qwxlea_charge_strength -2600 ;; Default: -600 - lower = further apart | |
qwxlea_forceXY 0.5 ;; Default: 0.02 - A value outside the range [0,1] is not recommended | |
;; higher turns graph in a ball | |
qwxlea_velocityDecay 0.8 ;; Default: 0.8 | |
] | |
(-> simulation | |
(.force "link" | |
(-> (forceLink) | |
(.id (fn [d] (.-id d))) | |
(.distance qwxlea_link_distance) | |
(.links links))) | |
(.force "charge" | |
(-> (forceManyBody) | |
(.distanceMax (if (> nodes-count 500) qwxlea_distanceMax_large qwxlea_distanceMax_small)) | |
(.theta 0.5) | |
(.strength qwxlea_charge_strength))) | |
(.force "collision" | |
(-> (forceCollide) | |
(.radius (+ 8 18)) | |
(.iterations 2))) | |
(.force "x" (-> (forceX 0) (.strength qwxlea_forceXY))) | |
(.force "y" (-> (forceY 0) (.strength qwxlea_forceXY))) | |
;; (.force "center" (forceCenter)) | |
(.force "center" | |
(-> (forceCenter) | |
(.strength 0.1))) | |
(.velocityDecay qwxlea_velocityDecay)) | |
(reset! *simulation simulation) | |
simulation)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment