|
53 | 53 | [:div (for [[k v] outs] |
54 | 54 | [:div [:strong (name k)] ": " v])]]))})) |
55 | 55 |
|
56 | | -(defn elkg [flow {:keys [show-chans chans-as-ports with-content] |
| 56 | +(defn elkg [flow {:keys [show-chans chans-as-ports with-content proc-width proc-height chan-width chan-height] |
57 | 57 | :or {show-chans true |
58 | 58 | chans-as-ports true |
59 | | - with-content false}}] |
60 | | - (let [{:keys [conns procs]} (datafy/datafy flow) |
61 | | - all-proc-chans (into #{} cat conns)] |
| 59 | + with-content false |
| 60 | + proc-width 60 |
| 61 | + proc-height 30 |
| 62 | + chan-width 30 |
| 63 | + chan-height 12}}] |
| 64 | + (let [{:keys [conns procs chans]} (datafy/datafy flow) |
| 65 | + {:keys [ins outs error report]} chans |
| 66 | + all-proc-chans (into #{} cat conns) |
| 67 | + global-chans [{:id "report" |
| 68 | + :width chan-width |
| 69 | + :height chan-height |
| 70 | + :labels [{:text (str "report" "(" (-> report :buffer :count) ")")}]} |
| 71 | + {:id "error" |
| 72 | + :width chan-width |
| 73 | + :height chan-height |
| 74 | + :labels [{:text (str "error" "(" (-> error :buffer :count) ")")}]}] |
| 75 | + proc-nodes (for [[proc-key proc-chans] (group-by first all-proc-chans)] |
| 76 | + (let [{:keys [args proc]} (get procs proc-key) |
| 77 | + {:keys [desc]} proc |
| 78 | + {:keys [params]} desc |
| 79 | + content (when with-content |
| 80 | + [{:id (str (name proc-key) "_content") |
| 81 | + :width (- proc-width 5) |
| 82 | + :height (- proc-height 5) |
| 83 | + ;; nope, do it by id |
| 84 | + :layoutOptions {:content (str/join \newline |
| 85 | + (for [[k param] params] |
| 86 | + (str (name k) " (" (get args k) ") " param)))}}]) |
| 87 | + chans (for [[_ chan-k :as proc-chan] proc-chans |
| 88 | + :let [chan-name (name chan-k) |
| 89 | + {:keys [buffer]} (or (get outs chan-k) |
| 90 | + (get ins chan-k))]] |
| 91 | + {:id (id-for proc-chan) |
| 92 | + :width chan-width |
| 93 | + :height chan-height |
| 94 | + :labels [{:text (str chan-name " (" (:count buffer) ")")}]})] |
| 95 | + {:id (id-for proc-key) |
| 96 | + :width proc-width |
| 97 | + :height proc-height |
| 98 | + :layoutOptions {:org.eclipse.elk.nodeLabels.placement "OUTSIDE V_TOP H_LEFT"} |
| 99 | + :labels [{:text (name proc-key)}] |
| 100 | + :children (vec (concat content |
| 101 | + (when (and show-chans (not chans-as-ports)) |
| 102 | + chans))) |
| 103 | + |
| 104 | + :ports |
| 105 | + (vec (when (and show-chans chans-as-ports) |
| 106 | + chans))}))] |
62 | 107 | {:id "G" |
63 | 108 | :layoutOptions {:elk.algorithm "layered" |
64 | 109 | :elk.direction "RIGHT" |
65 | 110 | :elk.hierarchyHandling "INCLUDE_CHILDREN"} |
66 | | - :children |
67 | | - (for [[proc-key proc-chans] (group-by first all-proc-chans)] |
68 | | - (let [{:keys [args proc]} (get procs proc-key) |
69 | | - {:keys [desc]} proc |
70 | | - {:keys [params ins outs]} desc |
71 | | - width 60 |
72 | | - height 30 |
73 | | - port-width 20 |
74 | | - port-height 12 |
75 | | - content (when with-content |
76 | | - [{:id (str (name proc-key) "_content") |
77 | | - :width (- width 5) |
78 | | - :height (- height 5) |
79 | | - ;; nope, do it by id |
80 | | - :layoutOptions {:content (str/join \newline |
81 | | - (for [[k param] params] |
82 | | - (str (name k) " (" (get args k) ") " param)))}}]) |
83 | | - children (when show-chans |
84 | | - (for [[_ chan :as proc-chan] proc-chans] |
85 | | - {:id (id-for proc-chan) |
86 | | - :width port-width |
87 | | - :height port-height |
88 | | - :labels [{:text (name chan)}] |
89 | | - :children (if with-content |
90 | | - [{:id (str (id-for proc-chan) "_content") |
91 | | - :width port-width |
92 | | - :height port-height |
93 | | - ;; nope, do it by id |
94 | | - :layoutOptions {:content (str (name chan) |
95 | | - \newline \newline |
96 | | - (or (get outs chan) |
97 | | - (get ins chan)))}}] |
98 | | - [])}))] |
99 | | - {:id (id-for proc-key) |
100 | | - :width width |
101 | | - :height height |
102 | | - :layoutOptions {:org.eclipse.elk.nodeLabels.placement "OUTSIDE V_TOP H_LEFT"} |
103 | | - :labels [{:text (name proc-key)}] |
104 | | - :children (vec (concat content |
105 | | - (when (and show-chans (not chans-as-ports)) |
106 | | - children))) |
107 | | - |
108 | | - :ports |
109 | | - (vec (when (and show-chans chans-as-ports) |
110 | | - children))})) |
| 111 | + :children (into proc-nodes global-chans) |
111 | 112 | :edges |
112 | 113 | (vec (if show-chans |
113 | | - (for [[from to] conns] |
114 | | - {:id (id-for [from to]) |
115 | | - :sources [(id-for from)] |
116 | | - :targets [(id-for to)]}) |
| 114 | + (concat |
| 115 | + (for [[from to] conns] |
| 116 | + {:id (id-for [from to]) |
| 117 | + :sources [(id-for from)] |
| 118 | + :targets [(id-for to)]}) |
| 119 | + (for [[p] procs, c ["report" "error"]] |
| 120 | + {:id (id-for [p c]) |
| 121 | + :sources [(id-for p)] |
| 122 | + :targets [c]})) |
117 | 123 | (for [[[from] [to]] conns] |
118 | 124 | {:id (id-for [from to]) |
119 | 125 | :sources [(id-for from)] |
|
0 commit comments