Skip to content

Commit

Permalink
move around working, memory for around 110 nodes is still too high 20…
Browse files Browse the repository at this point in the history
…0mb, fixed update node in rama
  • Loading branch information
sid597 committed May 1, 2024
1 parent a876dcb commit c072521
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 262 deletions.
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
;; by importing data.xml above according to this comment
;; https://clojurians.slack.com/archives/C7Q9GSHFV/p1704475238085959?thread_ts=1704210542.998019&cid=C7Q9GSHFV
com.google.guava/guava {:mvn/version "33.1.0-jre"}

org.clojure/data.xml {:mvn/version "0.2.0-alpha8"}
org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/clojurescript {:mvn/version "1.11.60"}
Expand All @@ -19,7 +18,8 @@
com.rpl/rama-helpers {:mvn/version "0.9.3"}
com.rpl/specter {:mvn/version "1.1.4"}
net.clojars.wkok/openai-clojure {:mvn/version "0.14.0"}
io.github.nextjournal/clojure-mode {:git/tag "v0.3.0" :git/sha "694abc7"}}
io.github.nextjournal/clojure-mode {:git/tag "v0.3.0" :git/sha "694abc7"}
org.apache.logging.log4j/log4j-slf4j2-impl {:mvn/version "2.23.1"}}
:aliases {:dev {:extra-paths ["src-dev"]
:extra-deps {io.github.clojure/tools.build {:mvn/version "0.9.6"
:exclusions [com.google.guava/guava ; Guava version conflict between tools.build and clojurescript.
Expand Down
64 changes: 33 additions & 31 deletions src/app/client/shapes/circle.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@



(e/defn circle [[k {:keys [id x y r color dragging?]}]]
(e/defn circle [id]
(println "cirtle id" id)
(let [x-p [ id :x]
y-p [ id :y]
r-p [ id :type-specific-data :r]
Expand All @@ -26,35 +27,36 @@
(e/client
(svg/circle
(dom/props {:id id
:cx (subscribe. x-p)
:cy (subscribe. y-p)
:r (subscribe. r-p)
:fill (subscribe. color-p)})
(dom/on "mousemove" (e/fn [e]
(.preventDefault e)
(when dragging?
(println "dragging element"
(let [el (.getElementById js/document (name id))
[x y] (fc/element-new-coordinates1 e el)]
(e/server (swap! !nodes assoc-in [k :x] x))
(e/server (swap! !nodes assoc-in [k :y] y)))))))
(dom/on "mousedown" (e/fn [e]
(.preventDefault e)
(.stopPropagation e)
(println "pointerdown element")
(e/server (swap! !nodes assoc-in [k :dragging?] true))))
(dom/on "mouseup" (e/fn [e]
(.preventDefault e)
(.stopPropagation e)
(println "pointerup element")
(e/server (swap! !nodes assoc-in [k :dragging?] false))))
(dom/on "mouseleave" (e/fn [e]
:cx (subscribe. x-p) ;(+ 100 (rand-int 1000)) ;
:cy (subscribe. y-p) ;(+ 400 (rand-int 300));
:r (+ 2 (rand-int 30)) ;(subscribe. r-p)
:fill "brown"}) ;(subscribe. color-p)})
#_(dom/on "mousemove" (e/fn [e]
(.preventDefault e)
(when dragging?
(println "dragging element"
(let [el (.getElementById js/document (name id))
[x y] (fc/element-new-coordinates1 e el)]
(e/server (swap! !nodes assoc-in [k :x] x))
(e/server (swap! !nodes assoc-in [k :y] y)))))))
#_(dom/on "mousedown" (e/fn [e]
(.preventDefault e)
(.stopPropagation e)
(println "pointerdown element")
(e/server (swap! !nodes assoc-in [k :dragging?] true))))
#_(dom/on "mouseup" (e/fn [e]
(.preventDefault e)
(.stopPropagation e)
(println "pointerup element")
(e/server (swap! !nodes assoc-in [k :dragging?] false))))
#_(dom/on "mouseleave" (e/fn [e]
(.preventDefault e)
(.stopPropagation e)
(println "mouseleave element")
(e/server (swap! !nodes assoc-in [k :dragging?] false))))
#_(dom/on "mouseout" (e/fn [e]
(.preventDefault e)
(.stopPropagation e)
(println "mouseleave element")
(e/server (swap! !nodes assoc-in [k :dragging?] false))))
(dom/on "mouseout" (e/fn [e]
(.preventDefault e)
(.stopPropagation e)
(println "mouseout element")
(e/server (swap! !nodes assoc-in [k :dragging?] false))))))))
(println "mouseout element")
(e/server (swap! !nodes assoc-in [k :dragging?] false))))))))

66 changes: 45 additions & 21 deletions src/app/client/shapes/line.cljc
Original file line number Diff line number Diff line change
@@ -1,33 +1,57 @@
(ns app.client.shapes.line
(:require [hyperfiddle.electric-svg :as svg]
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]))
[app.client.flow-calc :as fc]
[hyperfiddle.electric-dom2 :as dom]
[app.client.utils :refer [ ui-mode edges nodes
is-dragging? zoom-level last-position subscribe
viewbox context-menu? reset-global-vals]]))
(defn attributes [x y height width a b]
(let [xmin x
ymin y
xmax (+ x width)
ymax (+ y height)
rx (atom nil)
ry (atom nil)]
(println "xmin" xmin "xmax" xmax "ymin" ymin "ymax" ymax "a " a "b" b)
(cond
(<= a xmin) (reset! rx xmin)
(>= a xmax) (reset! rx xmax)
:else (reset! rx a))
(cond
(<= b ymin) (reset! ry ymin)
(>= b ymax) (reset! ry ymax)
:else (reset! ry b))
[@rx @ry]))

(comment
(attributes 0 0 100 100 -51 51)
(attributes 0 0 100 100 51 51)
(attributes 0 0 100 100 -51 -51)
(attributes 0 0 100 100 51 -51)
(attributes 0 0 100 100 51 -21))

(e/defn line [[k {:keys [id color to from]}]]
(println "--->" k id color to from)
(println "--"[to :y])
(e/client
(let [tw (subscribe. [ to :width])
th (subscribe. [ to :height])
fw (subscribe. [ from :width])
fh (subscribe. [ from :height])
tx (subscribe. [ to :x])
ty (subscribe. [ to :y])
fx (subscribe. [ from :x])
fy (subscribe. [ from :y])]
(let [tw (int (subscribe. [ to :type-specific-data :width]))
th (int (subscribe. [ to :type-specific-data :height]))
tx (int (subscribe. [to :x]))
ty (int (subscribe. [to :y]))
fx (int (subscribe. [from :x]))
fy (int (subscribe. [from :y]))
[xx yy] (attributes tx ty th tw fx fy)]
(svg/line
(dom/props {:style {:z-index -1}
:id id
:x1 (if tw
(+ tx) (/ tw 2)
tx)
:y1 (if th
(+ ty (/ th 2))
ty)
:x2 (if fw
(+ fx (/ fw 2))
fx)
:y2 (if fh
(+ fy (/ fh 2))
fy)
:x1 xx #_(if tw
(+ tx) (/ tw 2)
tx)
:y1 yy #_(if th
(+ ty (/ th 2))
ty)
:x2 fx
:y2 fy
:stroke color
:stroke-width 4})))))
Loading

0 comments on commit c072521

Please sign in to comment.