mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-06-03 07:29:37 +00:00
112 lines
3.4 KiB
Java
112 lines
3.4 KiB
Java
package dk.camelot64.kickc.passes.reports;
|
|
|
|
import dk.camelot64.kickc.model.Program;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
|
|
/**
|
|
* Create sub graphics for mermaid report generation.
|
|
* Sub graphs contain nodes, and can either be located as a single entity in root, or embedded in other sub graphs.
|
|
* A sub graph models dependencies to other sub graphs.
|
|
*/
|
|
public class MermaidSubGraph extends Mermaid {
|
|
|
|
protected HashMap<String, MermaidNode> nodes;
|
|
protected HashSet<MermaidFlow> flows;
|
|
protected HashMap<String, MermaidSubGraph> procedureSubGraphs;
|
|
|
|
public MermaidSubGraph(String title) {
|
|
super(toID(title), title);
|
|
this.nodes = new HashMap<String, MermaidNode>();
|
|
this.flows = new HashSet<MermaidFlow>();
|
|
this.procedureSubGraphs = new HashMap<String, MermaidSubGraph>();
|
|
}
|
|
|
|
public MermaidSubGraph(String id, String title) {
|
|
super(id, title);
|
|
this.nodes = new HashMap<String, MermaidNode>();
|
|
this.flows = new HashSet<MermaidFlow>();
|
|
this.procedureSubGraphs = new HashMap<String, MermaidSubGraph>();
|
|
}
|
|
|
|
public String getText(Program program) {
|
|
StringBuilder text = new StringBuilder();
|
|
|
|
// subgraph and nodes
|
|
text.append("subgraph ").append("sg_" + id).append("[\"").append(title).append("\"]\n");
|
|
for(MermaidNode node : nodes.values()) {
|
|
text.append(node.getText(program));
|
|
}
|
|
text.append("end\n\n");
|
|
|
|
// procedure subgraphs
|
|
for(MermaidSubGraph procedureSubGraph : getProcedureSubGraphs().values()) {
|
|
text.append(procedureSubGraph.getText(program));
|
|
}
|
|
|
|
// flows to and from nodes (outside the subgraph)
|
|
for(MermaidFlow flow : flows) {
|
|
text.append(flow.getText(program));
|
|
}
|
|
|
|
return text.toString();
|
|
}
|
|
|
|
public HashMap<String, MermaidNode> getNodes() {
|
|
return nodes;
|
|
}
|
|
|
|
public void setNodes(HashMap<String, MermaidNode> nodes) {
|
|
this.nodes = nodes;
|
|
}
|
|
|
|
public MermaidNode addNode(MermaidNode node) {
|
|
this.nodes.putIfAbsent(node.id, node);
|
|
return node;
|
|
}
|
|
|
|
public MermaidNode addNode(String nodeName) {
|
|
MermaidNode node = new MermaidNode(nodeName);
|
|
this.nodes.putIfAbsent(node.id, node);
|
|
return node;
|
|
}
|
|
|
|
public HashSet<MermaidFlow> getFlows() {
|
|
return flows;
|
|
}
|
|
|
|
public void setFlows(HashSet<MermaidFlow> flows) {
|
|
this.flows = flows;
|
|
}
|
|
|
|
public void addFlow(MermaidFlow flow) {
|
|
this.flows.add(flow);
|
|
}
|
|
|
|
public void addFlow(MermaidNode from, MermaidNode to, String title, MermaidFlow.Type type, MermaidFlow.Direction direction) {
|
|
MermaidFlow flow = new MermaidFlow(from, to, title, type, direction);
|
|
this.flows.add(flow);
|
|
}
|
|
|
|
public HashMap<String, MermaidSubGraph> getProcedureSubGraphs() {
|
|
return procedureSubGraphs;
|
|
}
|
|
|
|
public void setProcedureSubGraphs(HashMap<String, MermaidSubGraph> procedureSubGraphs) {
|
|
this.procedureSubGraphs = procedureSubGraphs;
|
|
}
|
|
|
|
public MermaidSubGraph addProcedureSubGraph(MermaidSubGraph subGraph) {
|
|
this.procedureSubGraphs.putIfAbsent(subGraph.id, subGraph);
|
|
return subGraph;
|
|
}
|
|
|
|
public MermaidSubGraph addProcedureSubGraph(String subGraphName) {
|
|
MermaidSubGraph subGraph = new MermaidSubGraph(subGraphName);
|
|
this.procedureSubGraphs.putIfAbsent(subGraph.id, subGraph);
|
|
return subGraph;
|
|
}
|
|
|
|
}
|