Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit fa203e2

Browse files
committed
an attempt to reduce the density of edges for if-heavy compositions
Fixes #900
1 parent 0bf66b2 commit fa203e2

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

app/plugins/modules/wskflow/lib/fsm2graph.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function addDummy(sources, targets, obj, options, directionS, directionT){
2929

3030
let dummyId = "dummy_"+dummyCount, o, port;
3131
dummyCount++;
32-
obj.children.push(drawNodeNew(dummyId, '', 'Dummy', sources, options));
32+
obj.children.push(drawNodeNew(dummyId, dummyId, 'Dummy', sources, options));
3333
if(sources && sources.length > 0){
3434
o = drawEdgeNew(sources[0], dummyId, obj), port = o.targetPort;
3535
obj.edges.push(o);
@@ -134,12 +134,13 @@ function drawNodeNew(id, label, type, properties, options){
134134
}
135135
else if(o.type === 'function'){
136136
o.fullFunctionCode = label;
137-
const prettyCode = require('js-beautify')(o.fullFunctionCode)
138-
139-
if (options.renderFunctionsInView) {
137+
const prettyCode = require('js-beautify')(o.fullFunctionCode),
138+
{ nLines, maxLineLength } = textualPropertiesOfCode(prettyCode)
139+
140+
// uncomment the second clause if you want always to display 1-liner functions inline in the view
141+
if (options.renderFunctionsInView /*|| nLines === 1*/) {
140142
// ok cool, then render this function body directly in the view
141-
const { nLines, maxLineLength } = textualPropertiesOfCode(prettyCode),
142-
charWidthForCode = defaultCharWidth * 0.63
143+
const charWidthForCode = defaultCharWidth * 0.63
143144

144145
o.width = Math.min(maxWidth, maxLineLength * charWidthForCode);
145146
o.height = Math.max(2.25, nLines) * defaultCharHeight; // use at least two lines; makes one-line functions look better
@@ -202,12 +203,12 @@ function drawNodeNew(id, label, type, properties, options){
202203
properties.forEach(s => { // a source id
203204
if(visited[s]){ // if the source is visited
204205
visited[s].forEach(a => { // find out if any of its activation was success
205-
if(activations[a].response.success){ // if so, dummy is visited
206-
if(visited[dummyId] == undefined) {
207-
visited[dummyId] = [];
206+
if(activations[a].response.success){ // if so, dummy is visited
207+
if(visited[o.id] == undefined) {
208+
visited[o.id] = [];
208209
o.visited = [];
209210
}
210-
visited[dummyId].push(a);
211+
visited[o.id].push(a);
211212
o.visited.push(a);
212213
}
213214
})
@@ -331,11 +332,11 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
331332
}
332333
else if(ir.type === 'if'){
333334
let firstTestId = gm.children.length,
334-
lastTestId = ir2graph(ir.test, gm, `${id}-test`, undefined, options),
335+
lastTestId = ir2graph(ir.test, gm,`${id}-test`, undefined, options),
335336
firstConsId = gm.children.length,
336-
lastConsId = ir2graph(ir.consequent, gm, `${id}-consequent`, undefined, options),
337+
lastConsId = ir2graph(ir.consequent, gm,`${id}-consequent`, undefined, options),
337338
firstAltId = gm.children.length,
338-
lastAltId = ir2graph(ir.alternate, gm, `${id}-alternate`, undefined, options);
339+
lastAltId = ir2graph(ir.alternate, gm,`${id}-alternate`, undefined, options)
339340

340341
if(prevId) // connect prevId to the first node in test
341342
prevId.forEach(pid => gm.edges.push(drawEdgeNew(pid, gm.children[firstTestId].id, gm)));
@@ -354,8 +355,9 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
354355
gm.edges.push(drawEdgeNew(ltid, gm.children[firstAltId].id, gm, 'false'));
355356
else
356357
lastAltId = [ltid];
357-
358-
return lastAltId.concat(lastConsId);
358+
359+
const exitConcentrator = addDummy(lastAltId.concat(lastConsId), undefined, gm, options);
360+
return [exitConcentrator]
359361
}
360362
else if(ir.type === 'try'){
361363
// insert a compound node for try

tests/tests/passes/07/composer-viz-no-auth.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ describe('show the composer visualization with no wskauth', function() {
6767
.then(verifyEdgeExists('seq1', 'seq2'))
6868
.then(verifyEdgeExists('seq2', 'seq3'))
6969
.then(verifyEdgeExists('seq4', 'seq5'))
70-
.then(verifyEdgeExists('seq3', 'Exit'))
71-
.then(verifyEdgeExists('seq5', 'Exit'))
70+
.then(verifyEdgeExists('seq3', 'dummy_0'))
71+
.then(verifyEdgeExists('seq5', 'dummy_0'))
72+
.then(verifyEdgeExists('dummy_0', 'Exit'))
7273
.then(() => this.app.client.element('body.no-auth')) // make sure we have this indicator
7374
.catch(common.oops(this)))
7475

tests/tests/passes/07/composer-viz.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ describe('show the composer visualization without creating openwhisk assets', fu
145145
.then(verifyNodeExists('report-swapi', false)) // not yet deployed
146146
.then(verifyNodeExists('report-stapi', false)) // not yet deployed
147147
.then(verifyNodeExists('report-empty', false)) // not yet deployed
148-
.then(verifyEdgeExists('report-swapi', 'Exit'))
149-
.then(verifyEdgeExists('report-stapi', 'Exit'))
150-
.then(verifyEdgeExists('report-empty', 'Exit'))
148+
.then(verifyEdgeExists('report-swapi', 'dummy_1'))
149+
.then(verifyEdgeExists('report-stapi', 'dummy_0'))
150+
.then(verifyEdgeExists('report-empty', 'dummy_0'))
151+
.then(verifyEdgeExists('dummy_0', 'dummy_1'))
152+
.then(verifyEdgeExists('dummy_1', 'Exit'))
151153
.catch(common.oops(this)))
152154

153155
/** test: viz, then create with -r, testing for handling of implicit entity and auto-deploy */
@@ -174,8 +176,9 @@ describe('show the composer visualization without creating openwhisk assets', fu
174176
.then(verifyEdgeExists('seq1', 'seq2'))
175177
.then(verifyEdgeExists('seq2', 'seq3'))
176178
.then(verifyEdgeExists('seq4', 'seq5'))
177-
.then(verifyEdgeExists('seq3', 'Exit'))
178-
.then(verifyEdgeExists('seq5', 'Exit'))
179+
.then(verifyEdgeExists('seq3', 'dummy_0'))
180+
.then(verifyEdgeExists('seq5', 'dummy_0'))
181+
.then(verifyEdgeExists('dummy_0', 'Exit'))
179182
.catch(common.oops(this)))
180183

181184
/** test: while with nested sequence, from js file */

tests/tests/passes/08/docs-introductory-scenario.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ describe('Intro demo scenario', function() {
401401
.then(sidecar.expectOpen)
402402
.then(sidecar.expectShowing(`${appName2}.js`))
403403
.then(sidecar.expectBadge(badges.composerLib))
404-
.then(graph.hasNodes({tasks: 3, total: 5, deployed: 0}))
404+
.then(graph.hasNodes({tasks: 3, total: 6, deployed: 0}))
405405

406406
// visit fsm tab
407407
.then(() => this.app.client.click('#sidecar .sidecar-bottom-stripe-button[data-mode="fsm"]'))
@@ -438,7 +438,7 @@ describe('Intro demo scenario', function() {
438438
.then(sidecar.expectOpen)
439439
.then(sidecar.expectShowing(appName2))
440440
.then(sidecar.expectBadge(badges.composerLib))
441-
.then(graph.hasNodes({tasks: 3, total: 5, deployed: 3})) // <---- deployed had better be 3 now
441+
.then(graph.hasNodes({tasks: 3, total: 6, deployed: 3})) // <---- deployed had better be 3 now
442442
.then(() => this.app.client.click('#sidecar .sidecar-bottom-stripe-button[data-mode="fsm"]'))
443443
.then(() => this.app.client.getText('#sidecar .sidecar-content .action-content code'))
444444
.then(ui.expectStruct(fsm[appName2]))

0 commit comments

Comments
 (0)