         complete-edges (reduce conj {} (map #(rootpath %) (keys filtered-edges)))]
     {:v (into #{} (concat (keys complete-edges) (vals complete-edges)))
      :e complete-edges}))
+
+(defn layout-graph [mx model root]
+  (.beginUpdate model)
+  (let [layout (mxOrganicLayout. mx)]
+    (doto layout
+      (.setFineTuning false)
+      (.setBorderLineCostFactor 10)
+      (.setEdgeLengthCostFactor 0.001)
+      (.setEdgeDistanceCostFactor 6000)
+      (.setEdgeCrossingCostFactor 6000)
+      (.setMaxIterations 1000)
+      (.execute root)))
+    (.endUpdate model))
 
 (defn -main [& args]
   (if (> (count args) 1)

              actual-width (.getWidth bounds)
              scale-factor (* 0.9 (min (/ width actual-width) (/ height actual-height)))]
          (.setScale view scale-factor))
        (doto (JFrame. (str "defgraph" (if prefix (str " - " prefix) "")))
          (.add gc)
          (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
          (.setSize width height)

          (doseq [e (:e g)]
            (.insertEdge mx root nil "" (vmap (key e)) (vmap (val e)))))
        (.endUpdate model))
      (layout-graph mx model root)
      (let [gc (mxGraphComponent. mx)
            bounds (.getGraphBounds mx)
            view (.getView mx)]
