Skip to content

Commit

Permalink
use set-position to assoc position
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Jan 13, 2024
1 parent 1ec0abb commit da6b4c0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/shimmers/sketches/graph_traces.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
(defn position [nodes n]
(get nodes n))

(defn set-position [graph node pos]
(assoc-in graph [:nodes node] pos))

(defn update-position [graph node & f]
(apply update-in graph [:nodes node] f))

Expand Down Expand Up @@ -100,7 +103,8 @@
force (tm/* (tm/- pos closest) (* 0.5 (/ dt (g/dist-squared pos closest))))]
(if (g/contains-point? rect pos)
(update-position graph node tm/+ force)
(assoc-in graph [:nodes node] (g/closest-point (g/scale-size rect 0.98) pos)))))
(set-position graph node
(g/closest-point (g/scale-size rect 0.98) pos)))))

(defn update-graph [{:keys [nodes edges] :as graph} dt]
(let [ranked-edges (sort-by (fn [{:keys [p q]}]
Expand Down

0 comments on commit da6b4c0

Please sign in to comment.