<commit_before>(ns cfg.layout.klay
  (:require [cfg.common :as cmn]))


(def klay (js* "$klay"))


(defn make
  []
  #js{"id" "root"
      "properties" #js{"direction" "DOWN"
                       "spacing" 40}
      "children" #js[]
      "edges" #js[]})


(defn- cfg-bb->klay
  [bb]
  (clj->js {"id" (str (:addr bb))
            "width" (:width bb)
            "height" (:height bb)
            "properties" {"de.cau.cs.kieler.portConstraints" "FIXED_SIDE"}
            "ports" [{"id" (str (:addr bb) "IN")
                      "properties" {"de.cau.cs.kieler.portSide" "NORTH"}}
                     {"id" (str (:addr bb) "OUT")
                      "properties" {"de.cau.cs.kieler.portSide" "SOUTH"}}]}))



(defn add-node!
  [g bb]
  (let [nodes (aget g "children")]
    (.push nodes (cfg-bb->klay bb))))


(defn- cfg-edge->klay
  [edge]
  (clj->js {"source" (str (:src edge))
            "sourcePort" (str (:src edge) "OUT")
            "target" (str (:dst edge))
            "targetPort" (str (:dst edge) "IN")
            "type" (:type edge)
            "id" (str (:src edge) (:type edge) (:dst edge))}))


(defn add-edge!
  [g edge]
  (let [edges (aget g "edges")]
    (.push edges (cfg-edge->klay edge))))


(defn- klay-bb->cfg
  [bb]
  (let [x (get bb "x")
        y (get bb "y")
        w (get bb "width")
        h (get bb "height")]
    {
     :x x
     :y y
     :height h
     :width w
     :id (js/parseInt (get bb "id"))}))


(defn get-nodes
  [g]
  (mapv klay-bb->cfg (js->clj (aget g "children"))))


(defn- klay-point->cfg
  [point]
  {:x (get point "x")
   :y (get point "y")})


(defn- klay-edge->cfg
  [edge]
  (let [src-point (get edge "sourcePoint")
        target-point (get edge "targetPoint")
        bend-points (get edge "bendPoints")
        points (concat [src-point] bend-points [target-point])]
    {:points (mapv klay-point->cfg points)
     :type (get edge "type")
     :src (js/parseInt (get edge "source"))
     :dst (js/parseInt (get edge "target"))}))


(defn get-edges
  [g]
  (mapv klay-edge->cfg (js->clj (aget g "edges"))))


(defn layout
  [g s e]
  (let [layout-fn (aget klay "layout")]
    (layout-fn #js{"graph" g
                   "options" #js{}
                   "success" s
                   "error" e})))<commit_msg>klay: use clj->js where appropriate<commit_after>(ns cfg.layout.klay
  (:require [cfg.common :as cmn]))


(def klay (js* "$klay"))


(defn make
  []
  (clj->js {"id" "root"
            "properties" {"direction" "DOWN"
                          "spacing" 10
                          "edgeSpacingFactor" 1}
            "children" []
            "edges" []}))


(defn- cfg-bb->klay
  [bb]
  (clj->js {"id" (str (:addr bb))
            "width" (:width bb)
            "height" (:height bb)
            "properties" {"de.cau.cs.kieler.portConstraints" "FIXED_SIDE"}
            "ports" [{"id" (str (:addr bb) "IN")
                      "properties" {"de.cau.cs.kieler.portSide" "NORTH"}}
                     {"id" (str (:addr bb) "OUT")
                      "properties" {"de.cau.cs.kieler.portSide" "SOUTH"}}]}))



(defn add-node!
  [g bb]
  (let [nodes (aget g "children")]
    (.push nodes (cfg-bb->klay bb))))


(defn- cfg-edge->klay
  [edge]
  (clj->js {"source" (str (:src edge))
            "sourcePort" (str (:src edge) "OUT")
            "target" (str (:dst edge))
            "targetPort" (str (:dst edge) "IN")
            "type" (:type edge)
            "id" (str (:src edge) (:type edge) (:dst edge))}))


(defn add-edge!
  [g edge]
  (let [edges (aget g "edges")]
    (.push edges (cfg-edge->klay edge))))


(defn- klay-bb->cfg
  [bb]
  (let [x (get bb "x")
        y (get bb "y")
        w (get bb "width")
        h (get bb "height")]
    {
     :x x
     :y y
     :height h
     :width w
     :id (js/parseInt (get bb "id"))}))


(defn get-nodes
  [g]
  (mapv klay-bb->cfg (js->clj (aget g "children"))))


(defn- klay-point->cfg
  [point]
  {:x (get point "x")
   :y (get point "y")})


(defn- klay-edge->cfg
  [edge]
  (let [src-point (get edge "sourcePoint")
        target-point (get edge "targetPoint")
        bend-points (get edge "bendPoints")
        points (concat [src-point] bend-points [target-point])]
    {:points (mapv klay-point->cfg points)
     :type (get edge "type")
     :src (js/parseInt (get edge "source"))
     :dst (js/parseInt (get edge "target"))}))


(defn get-edges
  [g]
  (mapv klay-edge->cfg (js->clj (aget g "edges"))))


(defn layout
  [g s e]
  (let [layout-fn (aget klay "layout")]
    (layout-fn (clj->js {"graph" g
                         "options" {}
                         "success" s
                         "error" e}))))
{'fraction_non_alphanumeric': 0.19365215526485097, 'fraction_numerical': 0.001072271070126528, 'mean_word_length': 1.9537682077264091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4299442', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1722, 'n_words': 476}