-
Notifications
You must be signed in to change notification settings - Fork 2
API
-
dictim.d2.compile
- Namespace for compiling dictim to d2. -
dictim.d2.parse
- Namespace for parsing d2 and returning dictim format.-
dictim
- Converts a d2 string to its dictim representation. label-regex
-
num-parses
- Implementation detail: exposed for testing purposes only. -
parses-d2
- Implementation detail: exposed for testing purposes only.
-
-
dictim.dot.compile
- Namespace for compiling dictim to graphviz' dot.-
dot
- Converts dictim elements to a (formatted) dot string.
-
-
dictim.flat
- Namespace for flattening and (re)building dictim. -
dictim.format
- Namespace for formatting d2 output of dictim. -
dictim.graphspec
-
graph-spec->dictim
- A higher level data api for producing dictim which models the data as a graph.
-
-
dictim.json
- Namespace for converting dictim to/ from json. -
dictim.template
- Namespace for handling dictim templates.-
apply-template
- Walks the supplied dictim edn and decorates with attrs and top level directives. -
apply-templates
- Merges multiple templates into the supplied dictim, with merge? true. deep-merge
-
postwalk-dictim
- Similar to clojure.walk/postwalk but for dictim. -
prewalk-dictim
- Similar to clojure.walk/prewalk but for dictim. -
remove-attrs
- removes all maps from the nested form. -
walk-dictim
- Similar to clojure.walk/walk but refined for dictim.
-
-
dictim.tests
-
attrs
- Returns the attrs of a dictim element. -
children
- Returns the children elements of a dictim element. -
element-type
- Returns the dictim element type as a string. -
key
- Returns the key of a dictim element. -
keys
- returns the keys of a dictim element. -
label
- Returns the label of a dictim element. -
set-attrs!
- Sets the attrs of a dictim element. -
set-label!
- Sets the attrs of a dictim element. -
test-elem
- Checks that that elem conforms to the tests. -
test-fn
- When passed a sequence of pairs, returns a 1-arity function that evaluates each test against the argument passed to the function and returns the value associated with the first true test. -
test-fn-merge
- When passed a sequence of pairs, returns a 1-arity function that evaluates each test against the argument passed to the function and returns the value associated by merging the values of all true test. -
valid-test?
- Returns true if a data-form test is valid.
-
Namespace for compiling dictim to d2
(d2 & elems)
Converts dictim elements to a formatted d2 string. Validates each element, throws an error if invalid.
Namespace for parsing d2 and returning dictim format.
(dictim
d2
&
{:keys [key-fn label-fn flatten-lists? retain-empty-lines?],
:or {key-fn identity, label-fn str/trim, flatten-lists? false, retain-empty-lines? false}})
Converts a d2 string to its dictim representation. Each dictim element returned's type is captured in the :tag key of the element's metadata. Three optional functions may be supplied: :key-fn a modifier applied to each key. :label-fn a modifier applied to each label. :flatten-lists? if true, flattens lists where every element is a shape with just a key, & no label or attrs. :retain-empty-lines? If true, empty lines are retained in the dictim output.
(num-parses d2 & kvs)
Implementation detail: exposed for testing purposes only
(parses-d2 d2 & kvs)
Implementation detail: exposed for testing purposes only
Namespace for compiling dictim to graphviz' dot
(dot & elems)
Converts dictim elements to a (formatted) dot string. Validates each element, throws an error if invalid.
Namespace for flattening and (re)building dictim.
(build flat-elems)
Builds a sequence of flat-dictim elements into dictim.
(flat elems)
Flattens dictim elements into flat-dictim format.
Namespace for formatting d2 output of dictim.
(fmt d2s & {:keys [tab], :or {tab 2}})
Formats a d2 string. :tab is the width of one indentation step.
(fmt-json jss & {:keys [tab], :or {tab 2}})
Formats a json string. :tab is the width of one indentation step.
(graph-spec->dictim spec & {:keys [validate?], :or {validate? true}})
A higher level data api for producing dictim which models the data as a graph. Takes a graph spec and produces dictim. A graph-spec is a map which must have keys: :nodes a sequence of nodes (each of which is an arbitrary (nested) map). :edges a sequence of edges ( ditto ). :node->key the key used to extract a unique value (the id) from each node. and optionally can have keys: :node-template see below. :edge-template ditto :container->attrs a map of the container (name) to a map of (e.g. d2) attributes or :container-template see below and :container->data a map of the container (name) to a map of data representing it. :node->container a key applied to each node to determine which container it is in :container->parent a map with containers mapped to their parent containers. :directives a map of dictim directives to be added to the dictim :template a default dictim template to be applied to the dictim (i.e. after node-template, edge-template & container-template have been applied during the formation of the dictim). attributes set by those templates are not overridden by the application of :template
This function makes no assumptions about whether the of the diagram spec are strings or keywords (both work). Similarly keywords and strings both work in specifying the nodes and edges data. The only assumption is that the spec is internally consistent. e.g. if a node is a map of keywords, then node-template, node->container, etc will also be specified using keywords.
node-template, edge-template are each sequences of test to a map of attrs e.g. style.fill blue in the below example...
:node-template [["=" "dept" "Equities"] {"label" ["This dept is %s" "dept"], "style.fill" "blue"}
"else" {"label" ["%s" "dept"]}]
The test and other instructions are the same as dictim.template.
For any values in the returned map that require dyanmic values to be interpolated into
the string from the element meeting the test, e..g. label
in the example above, use a
vector with the string to be interpolated into in the first position followed by keys
whose values should be looked up from the element and merged into the string. If the
element is represented by a nested map, instead of a single key, use a vector of keys.
Interpolation is done by java.util.Formatter.
Note that "label"
/ :label
is a special key name, used to set the element's
label in the final dictim. The value of label can be an interpolation instruction (e.g. a vector)
as described above.
All nodes, edges and containers (specified by :container->data) are arbitrary (nested) maps. The key names: 'key' 'label' 'attrs' 'children' 'keys' & 'element-type' must be avoided as they are reserved for dictim elements.
Namespace for converting dictim to/ from json.
(from-json js & args)
Desrializes the json to dictim
(to-json dictim & {:as opts})
Serializes the dictim to json.
Namespace for handling dictim templates
(apply-template
dict
{:keys [template directives merge? new-priority? all-matching-clauses?],
:or {merge? false, new-priority? true, all-matching-clauses? false}})
Walks the supplied dictim edn and decorates with attrs and top level directives.
A template is map with the key :template
and optionally :directives
, :merge?
,
:new-priority?
and :all-matching-clauses
The value under the :template
key can be either:
- a function that takes an elem and returns the attrs to be added
to the elem (or nil).
- a sequence of test and attribute maps pairs to be applied if the test succeeds.
A comparison test has the form [ ] where:
- is a string, one of 'matches' '=' '!=' 'contains' 'doesnt-contain'
'>' '<' '<=' or '>='
- is a string, one of 'key' 'label' 'attrs' 'keys' 'children'
or 'element-type'. Accessors allow you to access values of a dictim element,
for example its key
or label
.
- is the value to be tested against.
Example simple test: ["=" "key" "node123"]
A regex matching test has the form ["matches" ] where:
- .. same as for comparison test
- .. a string representation of a java.util.regex.Pattern
A nested test nests comparison/ matching tests with and
and or
statements.
Example nested test:
["and" ["=" "type" "ctr"] ["=" "key" "node123"]]
Attributes are supplied using standard dictim, e.g. {:style.fill "red"}
:merge?
If false, new attributes overwrite the original.
If true, then if :new-priority?
is true, new attributes have priority over
old when merged, otherwise old attributes have priority in the merge.
directives is a map of attrs to be added at the top level e.g. {"classes"...}
If there are directives in the original dict, the new directives will be merge over them
if merge? is true, otherwise they will be overwritten.
(apply-templates dict & templates)
Merges multiple templates into the supplied dictim, with merge? true.
(deep-merge v & vs)
(postwalk-dictim f element)
Similar to clojure.walk/postwalk but for dictim.
(prewalk-dictim f element)
Similar to clojure.walk/prewalk but for dictim.
(remove-attrs dict & {:keys [retain-vars?], :or {retain-vars? false}})
removes all maps from the nested form. i.e. attrs and directives. If retain-vars? is true, :vars/"vars" attributes will be retained in the dictim, since vars can be part of the 'data side' of a piece of dictim.
(walk-dictim inner outer element)
Similar to clojure.walk/walk but refined for dictim. Only walks into children of elements.
(attrs elem)
Returns the attrs of a dictim element
Returns the children elements of a dictim element
(element-type elem)
Returns the dictim element type as a string. Either: shape, conn, conn-ref, ctr, attrs, quikshape, cmt, empty-lines, list, elements or nil
Returns the key of a dictim element
returns the keys of a dictim element
Returns the label of a dictim element
Sets the attrs of a dictim element
Sets the attrs of a dictim element
(test-elem tests elem)
Checks that that elem conforms to the tests.
(test-fn tests)
When passed a sequence of pairs, returns a 1-arity function
that evaluates each test against the argument passed to the function and
returns the value associated with the first true test. Either :else
or "else"
can be used in the second last position to create a catch all clause in the
function returned.
(test-fn-merge tests)
When passed a sequence of pairs, returns a 1-arity function
that evaluates each test against the argument passed to the function and
returns the value associated by merging the values of all true test.
Either :else
or "else"
can be used in the second last position to
create a catch all clause in the function returned.
(valid-test? t)
Returns true if a data-form test is valid. A test may be simple, i.e. in the form [ ] e.g. ["=" "key" "Steve"] or use the "and" "or" keywords to arbitrarily nest simple tests. e.g. ["and" ["=" "element-type" "shape"] ["or" ["=" "key" "app14181"] ["=" "key" "app14027"]]]