Skip to content

Commit da18c30

Browse files
committed
Support specifying root proc(s) for circular flows
1 parent e18edce commit da18c30

3 files changed

Lines changed: 28 additions & 24 deletions

File tree

src/clojure/core/async/flow_monitor.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
{:on-open (fn [ch]
8484
(swap! state update-in [:channels] conj ch)
8585
(send-message state {:action :datafy
86-
:data (d/datafy (:flow @state))})
86+
:data (assoc (d/datafy (:flow @state)) :root (:root @state))})
8787
(swap! state assoc-in [:loop-ping?] true)
8888
(loop-ping state))
8989
:on-receive (fn [ch data]
@@ -141,11 +141,11 @@
141141
142142
Returns:
143143
An atom containing the server's state, and prints a local url where the frontend can be reached"
144-
[{:keys [flow port handlers filters] :or {port 9998}}]
144+
[{:keys [flow port handlers filters root] :or {port 9998}}]
145145
(let [state (atom default-state)
146146
error-chan (:clojure.datafy/obj (meta (:error (:chans (d/datafy flow)))))
147147
report-chan (:clojure.datafy/obj (meta (:report (:chans (d/datafy flow)))))]
148-
(swap! state assoc :flow flow :handlers handlers :filters filters)
148+
(swap! state assoc :flow flow :handlers handlers :filters filters :root root)
149149
(report-monitoring state report-chan error-chan)
150150
(let [server (httpkit/run-server (app state) {:port port
151151
:max-body 100000000

src/clojure/core/async/flow_static.clj

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424
(update-in [from-proc :outs] (fnil conj []) out-port)))
2525
{} data))
2626

27-
(defn flow-levels [relationships]
28-
(loop [result []
29-
current-level (filter (fn [[_ v]] (empty? (:from v))) relationships)
27+
(defn flow-levels [relationships root]
28+
(let [orphans (filter (fn [[_ v]] (empty? (:from v))) relationships)
29+
user-roots (filter (fn [[k _]] (contains? (set root) k)) relationships)]
30+
(loop [result []
31+
current-level (if (empty? orphans) user-roots orphans)
3032
remaining (apply dissoc relationships (map first current-level))]
3133
(if (empty? current-level)
3234
result
3335
(let [next-level (select-keys remaining (mapcat (fn [[_ v]] (:to v)) current-level))]
3436
(recur (conj result (map (fn [[k v]] {k v}) current-level))
3537
next-level
36-
(apply dissoc remaining (keys next-level)))))))
38+
(apply dissoc remaining (keys next-level))))))))
3739

3840
(defn proc-card [proc]
3941
[:div.middle-section-one-container
@@ -60,10 +62,10 @@
6062
(for [proc row]
6163
(proc-el proc))])
6264

63-
(defn chart [conns]
65+
(defn chart [conns root]
6466
(let [relationships (flow-relationships conns)]
6567
[:div#chart
66-
(for [[idx row] (map-indexed vector (flow-levels relationships))]
68+
(for [[idx row] (map-indexed vector (flow-levels relationships root))]
6769
(proc-row idx row))]))
6870

6971
(defn json-friendly [conn]
@@ -79,7 +81,7 @@
7981
(defn connections-to-json [connections]
8082
(json/write-str (mapv json-friendly connections)))
8183

82-
(defn template [{:keys [conns]}]
84+
(defn template [{:keys [conns]} root]
8385
(str
8486
(h/html
8587
[:html
@@ -116,8 +118,8 @@ window.addEventListener('load', function() {
116118
drawConnections();});")]
117119
[:style "html,\nbody {\n margin: 0;\n padding: 0;\n}\n\nbody {\n height: 100vh;\n width: 100vw;\n margin-top: 50px;\n background-color: #CBD2D9;\n}\n\n.row-3 {\n display: flex;\n flex-direction: row;\n justify-content: center;\n gap: 10px;\n align-items: center;\n}\n\n.card-container {\n display: flex;\n flex-direction: column;\n align-items: center;\n margin-bottom: 40px;\n min-width: 220px;\n}\n.card-container .proc-card {\n background: #F5F7FA;\n border-radius: 3px;\n width: 100%;\n display: inline-block;\n position: relative;\n transition: all 0.4s ease-in-out;\n will-change: height;\n margin-bottom: 55px;\n}\n.card-container .proc-card.expanded .expanded-view {\n max-height: 500px;\n opacity: 1;\n visibility: visible;\n}\n.card-container .proc-card .expanded-view {\n transition: all 0.4s ease-in-out;\n max-height: 0;\n opacity: 0;\n overflow: hidden;\n visibility: hidden;\n}\n.card-container .proc-card .expanded-view .header-labels {\n display: flex;\n justify-content: center;\n padding: 0 15px;\n}\n.card-container .proc-card .expanded-view .header-labels .header-label {\n font-size: 1.75em;\n font-weight: 500;\n color: #4a4a4a;\n text-align: center;\n width: 150px;\n}\n.card-container .proc-card .expanded-view .middle-section-one-container {\n box-sizing: border-box;\n background: #52606D;\n color: #E4E7EB;\n border-radius: 2px;\n position: relative;\n padding: 10px 0;\n width: calc(100% - 20px);\n margin: auto;\n}\n.card-container .proc-card .expanded-view .title-container {\n text-align: center;\n}\n.card-container .proc-card .expanded-view .title-container .title {\n font-size: 2.3em;\n font-weight: 600;\n margin: 0;\n color: white;\n}\n.card-container .proc-card .output-section {\n width: 100%;\n display: flex;\n flex-direction: column;\n align-items: center;\n box-sizing: border-box;\n}\n.card-container .proc-card .output-section .output-container {\n display: flex;\n flex-direction: row;\n gap: 15px;\n justify-content: center;\n align-items: center;\n width: calc(100% - 14px);\n margin: 0 7px;\n padding: 0 0;\n box-sizing: border-box;\n}\n.card-container .proc-card .output-section .output-container .output {\n flex: 1;\n min-width: 110px;\n padding: 0 8px;\n font-size: 1.75em;\n color: #4a4a4a;\n text-align: center;\n height: 40px;\n display: flex;\n justify-content: center;\n align-items: center;\n white-space: nowrap;\n}\n"]]
118120
[:body
119-
(chart conns)]])))
121+
(chart conns root)]])))
120122

121-
(defn graph [flow-config]
122-
(tagged-literal 'flare/html {:html (template flow-config)
123+
(defn graph [flow-config & root]
124+
(tagged-literal 'flare/html {:html (template flow-config (first root))
123125
:title "Flow Chart"}))

src/clojurescript/flow_monitor_ui/routes/index/view.cljs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@
5959
(swap! global-state assoc :roots roots)
6060
r+p))
6161

62-
(defn flow-levels [relationships]
63-
(loop [result []
64-
current-level (filter (fn [[_ v]] (empty? (:from v))) relationships)
65-
remaining (apply dissoc relationships (map first current-level))]
66-
(if (empty? current-level)
67-
result
68-
(let [next-level (select-keys remaining (mapcat (fn [[_ v]] (:to v)) current-level))]
69-
(recur (conj result (map (fn [[k v]] {k v}) current-level))
70-
next-level
71-
(apply dissoc remaining (keys next-level)))))))
62+
(defn flow-levels [relationships root]
63+
(let [orphans (filter (fn [[_ v]] (empty? (:from v))) relationships)
64+
user-roots (filter (fn [[k _]] (contains? (set root) k)) relationships)]
65+
(loop [result []
66+
current-level (if (empty? orphans) user-roots orphans)
67+
remaining (apply dissoc relationships (map first current-level))]
68+
(if (empty? current-level)
69+
result
70+
(let [next-level (select-keys remaining (mapcat (fn [[_ v]] (:to v)) current-level))]
71+
(recur (conj result (map (fn [[k v]] {k v}) current-level))
72+
next-level
73+
(apply dissoc remaining (keys next-level))))))))
7274

7375
; = Components =================================================================
7476

@@ -372,7 +374,7 @@
372374
relationships (flow-relationships (:conns data))
373375
relationships* (assoc-ping-data relationships (-> @global-pings :flow-ping))]
374376
[:div#chart
375-
(when data (for [[idx row] (map-indexed vector (flow-levels relationships*))]
377+
(when data (for [[idx row] (map-indexed vector (flow-levels relationships* (:root data)))]
376378
^{:key (str "chart-" idx)} [proc-row idx row]))]))
377379

378380
; = Template ===================================================================

0 commit comments

Comments
 (0)