Skip to content

Commit 9de0051

Browse files
committed
feat: support for EventInvokeConfig and externally referenced resources
1 parent 758de54 commit 9de0051

File tree

6 files changed

+106
-76
lines changed

6 files changed

+106
-76
lines changed

graph/MxGenerator.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ function addEdges(from, to, dependencyNode) {
9898
const existingEdge = graph.model.cells[existingEdges[0]];
9999
if (filterConfig.edgeMode === "Off") {
100100
existingEdge.value = "";
101-
} else if (!existingEdge.value.includes(pathToDescriptor(dependencyNode.path))) {
102-
existingEdge.value += `\n${pathToDescriptor(dependencyNode.path)}`;
101+
} else if (!existingEdge.value.includes(jsonUtil.pathToDescriptor(dependencyNode.path, filterConfig))) {
102+
existingEdge.value += `\n${jsonUtil.pathToDescriptor(dependencyNode.path, filterConfig)}`;
103103
}
104104
return;
105105
}
@@ -116,7 +116,7 @@ function addEdges(from, to, dependencyNode) {
116116
graph.insertEdge(
117117
parent,
118118
edgeId(to, from),
119-
pathToDescriptor(dependencyNode.path),
119+
jsonUtil.pathToDescriptor(dependencyNode.path, filterConfig),
120120
from,
121121
to,
122122
"edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;fontColor=#EA6B66;"
@@ -148,6 +148,7 @@ function addVertices(resource, dependencies, type) {
148148
function getDependencies(template, resource) {
149149
const dependencies = [];
150150
jsonUtil.findAllValues(template.Resources[resource], dependencies, "Ref");
151+
jsonUtil.findAllValues(template.Resources[resource], dependencies, "Fn::Sub");
151152
jsonUtil.findAllValues(
152153
template.Resources[resource],
153154
dependencies,
@@ -185,21 +186,6 @@ function edgeId(to, from) {
185186
return `${to.value}|${from.value}`; //|${pathToDescriptor(dependencyNode.path)}`;
186187
}
187188

188-
function pathToDescriptor(path) {
189-
if (filterConfig.edgeMode === "Off") {
190-
return "";
191-
}
192-
if (path.startsWith("$.Properties.Environment")) {
193-
return "Variable";
194-
}
195-
196-
if (path.startsWith("$.Properties.Policies")) {
197-
const split = path.split(".");
198-
return split[3];
199-
}
200-
return path.split(".").slice(-1)[0];
201-
}
202-
203189
function graphToXML(graph) {
204190
var encoder = new mxCodec();
205191
var result = encoder.encode(graph.getModel());

graph/Vis.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function reset() {
2424
}
2525

2626
function makeGraph(template, prefix) {
27+
jsonUtil.createPseudoResources(template);
28+
2729
const resources = Object.keys(template.Resources);
2830
try {
2931
for (const resource of resources) {
@@ -35,7 +37,7 @@ function makeGraph(template, prefix) {
3537
makeGraph(resObj.Template, resource);
3638
}
3739
const dependencies = getDependencies(template, resource);
38-
40+
3941
addnodes(
4042
resource,
4143
dependencies,
@@ -76,8 +78,8 @@ function addEdges(from, to, dependencyNode, fromNode, prefix) {
7678
from: to,
7779
label: "Invoke",
7880
});
79-
} else {
80-
const descriptor = pathToDescriptor(dependencyNode.path);
81+
} else {
82+
const descriptor = jsonUtil.pathToDescriptor(dependencyNode.path, filterConfig);
8183
if (
8284
edges.filter(
8385
(p) => p.from === from && p.to === to && p.label === descriptor
@@ -122,7 +124,7 @@ function addnodes(resource, dependencies, type, resourceObject, prefix) {
122124
function createImage(resourceType) {
123125
const type = resourceType.split("::")[1].toLowerCase();
124126
var svg =
125-
icons.iconMap.get(resourceType) ||
127+
icons.iconMap.get(resourceType.toLowerCase()) ||
126128
'<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve"><g> <rect x="15" y="15" fill="#FF9900" width="70" height="70"/> <g> <path fill="#FFFFFF" d="M39.4,47c0,0.6,0.1,1.1,0.2,1.4c0.1,0.4,0.3,0.7,0.5,1.2c0.1,0.1,0.1,0.3,0.1,0.4c0,0.2-0.1,0.3-0.3,0.5 l-1,0.7c-0.2,0.1-0.3,0.1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.6 c-0.9,0-1.6,0.2-2.2,0.5c-0.5,0.3-0.8,0.8-0.8,1.4c0,0.5,0.2,0.8,0.5,1.1c0.3,0.3,0.9,0.6,1.8,0.9l2.3,0.7c1.2,0.4,2,0.9,2.5,1.6 c0.5,0.7,0.8,1.4,0.8,2.3c0,0.7-0.1,1.3-0.4,1.9c-0.3,0.6-0.7,1-1.2,1.4c-0.5,0.4-1.1,0.7-1.8,0.9C68.2,51.6,67.5,51.7,66.6,51.7z "/> <g> <path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M69.7,59.5c-5.3,3.9-13.1,6-19.7,6c-9.3,0-17.8-3.5-24.1-9.2 c-0.5-0.5-0.1-1.1,0.5-0.7c6.9,4,15.4,6.4,24.1,6.4c5.9,0,12.4-1.2,18.4-3.8C69.8,57.9,70.6,58.9,69.7,59.5z"/> <path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M71.9,57c-0.7-0.9-4.5-0.4-6.2-0.2c-0.5,0.1-0.6-0.4-0.1-0.7 c3.1-2.1,8.1-1.5,8.6-0.8c0.6,0.7-0.2,5.7-3,8.1c-0.4,0.4-0.9,0.2-0.7-0.3C71.2,61.5,72.6,57.9,71.9,57z"/> </g> </g></g></svg>';
127129
return "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
128130
}
@@ -142,21 +144,6 @@ function getDependencies(template, resource) {
142144
return dependencies;
143145
}
144146

145-
function pathToDescriptor(path) {
146-
if (filterConfig.edgeMode === "Off") {
147-
return "";
148-
}
149-
if (path.startsWith("$.Properties.Environment")) {
150-
return "Variable";
151-
}
152-
153-
if (path.startsWith("$.Properties.Policies")) {
154-
const split = path.split(".");
155-
return split[3];
156-
}
157-
return path.split(".").slice(-1)[0];
158-
}
159-
160147
async function renderTemplate(template, isJson, filePath, ciMode) {
161148
useJson = isJson;
162149
const { nodes, edges } = makeGraph(template, "root");

0 commit comments

Comments
 (0)