Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added colors for arrows in graph #314

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/liberator/graph.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns liberator.graph)
(ns liberator.graph
(:require [liberator.core :as liberator]))

(defn extract
([_ name then else] [name then else])
Expand All @@ -7,16 +8,21 @@
(defn clean-id [str]
(clojure.string/replace str #"[^a-zA-Z0-9_]+" ""))

(def default-style "color=\"#b2df8a\"")

(defn to-graph [[& args]]
(condp = (first args)
'defdecision
(let [[name then else] (apply extract args)]
(let [[name then else] (apply extract args)
default (get liberator/default-functions (keyword name))
then-default (if (true? default) default-style "")
else-default (if (false? default) default-style "")]
(format (str "\"%s\" [id = \"%s\"] \n "
"\"%s\" -> \"%s\" [label = \"true\", id = \"%s\"] \n"
"\"%s\" -> \"%s\" [label = \"false\", id = \"%s\"]\n")
"\"%s\" -> \"%s\" [label = \"true\", id = \"%s\" %s] \n"
"\"%s\" -> \"%s\" [label = \"false\", id = \"%s\" %s]\n")
name (clean-id name)
name then (clean-id (str name "_" then))
name else (clean-id (str name "_" else))))
name then (clean-id (str name "_" then)) then-default
name else (clean-id (str name "_" else)) else-default))
'defaction
(let [[_ name then] args]
(format (str "\"%s\"[shape=\"ellipse\" id = \"%s\"];\n"
Expand Down
Loading