                    :blue 2})
 
 (defn svg-vertex [edges id [weight [x y]]]
-  (let [entering (filter #(= id (second (second %))) edges)
-        summed (apply + (map #(color->value ((second %) 2)) entering))]
+  (let [vert-inflow (inflow edges id)]
     (list
       [:svg:circle
        {:cx x :cy y

       {:x x :y (+ 5 y)
        :fill "black"
        :text-anchor "middle"}
       (str id " (" summed "/" weight ")") ]))
  )

(defn event->targetid [e]

                  (crate/html [:div#forsvg
                                (make-svg [1000 1000] world-state)])))

(defn inflow [edges vertex]
  (let [in-going (for [[_ [_ to color]] edges
                       :when (= to vertex)]
                   (color->value color))]
    (apply + in-going)))

(defn ok-to-flip? [{:keys [vertices edges]} [_ to color]]
  (let [edge-value (color->value color)
        to-inflow (inflow edges to)
        to-vertex-value (first (vertices to))]
    (>= (- to-inflow edge-value) to-vertex-value)))

(defn flip-edge [world-state [from to color :as edge]]
  (if (ok-to-flip? world-state edge)
    [to from color]
    edge))


