1717
1818package guru.nidi.graphviz
1919
20- import guru.nidi.graphviz.attribute.*
21- import guru.nidi.graphviz.attribute.Attributes.attr
2220import guru.nidi.graphviz.engine.Graphviz
2321import guru.nidi.graphviz.model.*
2422import guru.nidi.graphviz.model.Factory.*
2523
26- fun graph (name : String = "", strict : Boolean = false, directed : Boolean = false, cluster : Boolean = false, config : () -> Unit = { }) =
24+ fun graph (name : String = "", strict : Boolean = false, directed : Boolean = false, cluster : Boolean = false,
25+ config : KraphvizContext .() -> Unit = { }): MutableGraph =
2726 mutGraph(name).apply {
2827 isStrict = strict
2928 isDirected = directed
3029 isCluster = cluster
31- use { _, _ ->
32- config()
30+ use { _, ctx ->
31+ config(KraphvizContext (ctx) )
3332 }
3433 }
3534
36- infix fun String.eq (value : Any ): Attributes <ForAll > = attr(this , value)
37-
38- interface AttributeContainer <F : For > {
39- operator fun get (vararg attrs : Attributes <out F >)
40- }
41-
42- val edge = object : AttributeContainer <ForLink > {
43- override fun get (vararg attrs : Attributes <out ForLink >) {
44- val linkAttrs = CreationContext .get().linkAttrs()
45- attrs.forEach { linkAttrs.add(it) }
46- }
47- }
48-
49- val node = object : AttributeContainer <ForNode > {
50- override fun get (vararg attrs : Attributes <out ForNode >) {
51- val nodeAttrs = CreationContext .get().nodeAttrs()
52- attrs.forEach { nodeAttrs.add(it) }
53- }
54- }
55-
56- val graph = object : AttributeContainer <ForGraph > {
57- override fun get (vararg attrs : Attributes <out ForGraph >) {
58- val graphAttrs = CreationContext .get().graphAttrs()
59- attrs.forEach { graphAttrs.add(it) }
60- }
61- }
62-
63- operator fun MutableNode.minus (target : LinkTarget ) = addLink(target).links().last()!!
64- operator fun MutableNode.minus (node : String ) = this - mutNode(node)
65- operator fun MutableNode.div (record : String ) = port(record)
66- operator fun MutableNode.div (compass : Compass ) = port(compass)
67- operator fun MutableNode.get (vararg attrs : Attributes <out ForNode >) = add(* attrs)
68-
69- operator fun PortNode.minus (target : LinkTarget ) = links().run {
70- add(between(port(), target))
71- last()!!
72- }
73-
74- operator fun PortNode.minus (node : String ) = this - mutNode(node)
75- operator fun PortNode.div (record : String ) = port(record)
76- operator fun PortNode.div (compass : Compass ) = port(compass)
77- operator fun PortNode.get (vararg attrs : Attributes <out ForNode >): PortNode {
78- (node() as MutableNode ).add(* attrs)
79- return this
80- }
81-
82- operator fun Link.minus (target : LinkTarget ): Link {
83- val source = to().asLinkSource()
84- return source.links().run {
85- add(source.linkTo(target))
86- last()!!
87- }
88- }
89-
90- operator fun Link.minus (node : String ) = this - mutNode(node)
91- operator fun Link.get (vararg attrs : Attributes <out ForLink >) = add(Attributes .attrs(* attrs))
92-
93- operator fun String.unaryMinus () = mutNode(this , true )
94- operator fun String.minus (target : LinkTarget ) = - this - target
95- operator fun String.minus (node : String ) = - this - node
96- operator fun String.div (record : String ) = - this / record
97- operator fun String.div (compass : Compass ) = - this / compass
98- operator fun String.get (vararg attrs : Attributes <out ForNode >) = (- this ).add(* attrs)
35+ operator fun MutableGraph.invoke (config : KraphvizContext .() -> Unit ): MutableGraph =
36+ reuse { _, ctx ->
37+ config(KraphvizContext (ctx))
38+ }
9939
100- fun MutableGraph.toGraphviz () = Graphviz .fromGraph(this )
40+ fun MutableGraph.toGraphviz (): Graphviz = Graphviz .fromGraph(this )
0 commit comments