Skip to content

Commit b1b3139

Browse files
committed
refactor graph viz, add settings context
1 parent a6a5f47 commit b1b3139

File tree

2 files changed

+47
-35
lines changed

2 files changed

+47
-35
lines changed
Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
package reqt
22

33
object GraphVizGen:
4+
case class GraphVizSettings(
5+
fontName: String = "Sans",
6+
fontSize: Int = 10,
7+
rankDir: String = "LR",
8+
ordering: String = "out",
9+
noJustify: Boolean = true,
10+
edgeArrowhead: String = "empty",
11+
nodeShape: String = "record",
12+
compound: Boolean = true,
13+
)
14+
object GraphVizSettings:
15+
given default: GraphVizSettings = GraphVizSettings()
16+
17+
extension (m: Model)
18+
def toGraphViz(using settings: GraphVizSettings): String =
19+
val s = settings.copy(rankDir = "LR")
20+
???
421

522
def recordNode(
623
nodeName: String,
@@ -14,37 +31,32 @@ object GraphVizGen:
1431

1532
def edge(fromNode: String, toNode: String): String = s" $fromNode -> $toNode"
1633

17-
def directedGraph(
18-
name: String,
19-
fontName: String = "Sans",
20-
fontSize: Int = 10,
21-
rankDir: String = "BT",
22-
ordering: String = "out",
23-
noJustify: Boolean = true,
24-
edgeArrowhead: String = "empty",
25-
nodeShape: String = "record",
26-
)(rankSame: Seq[Seq[String]])(edges: Seq[(String, String)])(nodeFormats: Seq[String]) =
27-
s"""|digraph $name {
28-
| fontname = "$fontName"
29-
| fontsize = $fontSize
30-
| rankdir = "$rankDir"
31-
| ordering = "$ordering"
32-
| nojustify = $noJustify
33-
|
34-
| node [
35-
| fontname = "$fontName"
36-
| fontsize = $fontSize
37-
| shape = "$nodeShape"
38-
| ]
39-
|
40-
| edge [
41-
| arrowhead = "$edgeArrowhead"
42-
| ]
43-
|
44-
|${rankSame.map(_.mkString(" { rank = same; ", "; ", "; }")).mkString(" ", "\n ", "\n")}
45-
|
46-
|${nodeFormats.mkString(" ", "\n ", "\n")}
47-
|
48-
|${edges.map((f,t) => edge(f,t)).mkString(" ", "\n ", "\n")}
49-
|}
50-
|""".stripMargin
34+
def classDiagram(title: String)
35+
(rankSame: Seq[Seq[String]])(edges: Seq[(String, String)])(nodeFormats: Seq[String])
36+
(using settings: GraphVizSettings) =
37+
val s = settings.copy(rankDir = "BT")
38+
import s.*
39+
s"""|digraph $title {
40+
| fontname = "$fontName"
41+
| fontsize = $fontSize
42+
| rankdir = "$rankDir"
43+
| ordering = "$ordering"
44+
| nojustify = $noJustify
45+
|
46+
| node [
47+
| fontname = "$fontName"
48+
| fontsize = $fontSize
49+
| shape = "$nodeShape"
50+
| ]
51+
|
52+
| edge [
53+
| arrowhead = "$edgeArrowhead"
54+
| ]
55+
|
56+
|${rankSame.map(_.mkString(" { rank = same; ", "; ", "; }")).mkString(" ", "\n ", "\n")}
57+
|
58+
|${nodeFormats.mkString(" ", "\n ", "\n")}
59+
|
60+
|${edges.map((f,t) => edge(f,t)).mkString(" ", "\n ", "\n")}
61+
|}
62+
|""".stripMargin

src/test/scala/generateLang.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def graphFile(mod: String) = docsDir + s"/metamodel$mod-GENERATED.dot"
2323
println(s"Generating $conceptFile")
2424
meta.csv("\t").saveTo(conceptFile)
2525

26-
println(s"Generating $graphFile")
26+
println(s"Generating graph files: metamodel-*-GENERATED.dot")
2727
meta.graph(showElem=false, showElemType=false).saveTo(graphFile("-Model"))
2828
meta.graph(showElem=true, showElemType=false).saveTo(graphFile("-Elem"))
2929
meta.graph(showElem=false, showElemType=true).saveTo(graphFile("-ElemType"))

0 commit comments

Comments
 (0)