         (.beginUpdate model)
         (let [layout (mxOrganicLayout. mx)]
           (doto layout
+            (.setBorderLineCostFactor 10)
+            (.setEdgeLengthCostFactor 0.001)
+            (.setEdgeDistanceCostFactor 1500)
+            (.setEdgeCrossingCostFactor 24000)
+            (.setMaxIterations 5000)
             (.execute root)))
         (.endUpdate model))
-      (doto (JFrame. "defgraph")
-        (.setSize width height)
-        (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
-        (.add (mxGraphComponent. mx))
-        (.setVisible true)))))
+      (let [gc (mxGraphComponent. mx)
+            bounds (.getGraphBounds mx)
+            view (.getView mx)]
+        (let [offset-x (+ 20 (- (.getX bounds)))
+              offset-y (+ 20 (- (.getY bounds)))]
+          (.setTranslate view (mxPoint. offset-x offset-y)))
+        (let [actual-height (.getHeight bounds)
+              actual-width (.getWidth bounds)
+              scale-factor (* 0.9 (min (/ width actual-width) (/ height actual-height)))]
+          (.setScale view scale-factor))
+        (doto (JFrame. "defgraph")
+          (.add gc)
+          (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
+          (.setSize width height)
+          (.setVisible true))))))

(ns defgraph.core
  (:gen-class)
  (:import com.mxgraph.swing.mxGraphComponent
           com.mxgraph.view.mxGraph
           javax.swing.JFrame
           com.mxgraph.layout.mxOrganicLayout))

(def defs     (filter #(.isFile %) (.listFiles (java.io.File. "defs/runs"))))
(def vertices (map #(.getName %) defs))

          mx (mxGraph.)
          model (.getModel mx)
          root (.getDefaultParent mx)
          height 700
          width 700]
      (doto mx
        (.setCellsDisconnectable false)
        (.setCellsEditable false)
