Skip to content

Commit 9bab060

Browse files
author
Mark Robinson
committed
Implement expanding selection to children or parents
1 parent f755131 commit 9bab060

File tree

1 file changed

+71
-5
lines changed

1 file changed

+71
-5
lines changed

src/main/resources/static/js/workflow.js

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ require(['jquery', 'bootstrap.modal', 'svg-pan-zoom', 'hammerjs', 'jquery.svg'],
106106
loadURL: $("#graph").attr("data-svgurl"),
107107
onLoad: enablePanZoom
108108
});
109-
$("#graphFullscreen").svg({
110-
loadURL: $("#graph").attr("data-svgurl"),
111-
onLoad: enablePanZoom
112-
});
109+
/*$("#graphFullscreen").svg({
110+
loadURL: $("#graph").attr("data-svgurl")
111+
});*/
113112

114113
/**
115114
* Enable svg-pan-zoom on the graph
@@ -288,7 +287,7 @@ require(['jquery', 'jquery.svg', 'jquery.svgdom'],
288287
// Find corresponding table row and return
289288
return $("tr").filter(function() {
290289
return $(this).find("td:first").html() == elementTitle;
291-
}).add();
290+
});
292291
}
293292

294293
/**
@@ -312,6 +311,73 @@ require(['jquery', 'jquery.svg', 'jquery.svgdom'],
312311
$(this).find("polygon").removeClass("hover");
313312
}
314313
}, ".node");
314+
315+
/**
316+
* Stores an in+outlist style graph structure
317+
* Generated at time of first use
318+
*/
319+
var graphModel = {};
320+
321+
/**
322+
* Generates the graph model
323+
*/
324+
function generateGraphModel() {
325+
var nodes = $(".node");
326+
327+
// Add all node titles to the model
328+
nodes.each(function() {
329+
graphModel[$(this).find("title").parent().attr("id")] = {
330+
inList: [],
331+
outList: []
332+
}
333+
});
334+
335+
// Add all links to the model
336+
$(".edge").each(function() {
337+
var edgeText = $(this).find("title").text();
338+
var toFrom = edgeText.split("->");
339+
var to = nodes.filter(function() {
340+
return $(this).find("title").text() === toFrom[0];
341+
}).attr("id");
342+
var from = nodes.filter(function() {
343+
return $(this).find("title").text() === toFrom[1];
344+
}).attr("id");
345+
graphModel[from].inList.push(to);
346+
graphModel[to].outList.push(from);
347+
});
348+
}
349+
350+
/**
351+
* Recursively select all the parents or children of a node
352+
*/
353+
function expandSelection(root, listName) {
354+
var rootID = root.attr("id");
355+
for (var i = 0; i < graphModel[rootID][listName].length; i++) {
356+
var next = $("#" + graphModel[rootID][listName][i]);
357+
next.find("polygon").addClass("selected");
358+
getTableRow(next).addClass("selected");
359+
expandSelection(next, listName);
360+
}
361+
}
362+
363+
$("#selectChildren").click(function() {
364+
if ($.isEmptyObject(graphModel)) {
365+
generateGraphModel();
366+
}
367+
$("polygon.selected").each(function() {
368+
expandSelection($(this).parent(), "outList");
369+
});
370+
});
371+
372+
$("#selectParents").click(function() {
373+
if ($.isEmptyObject(graphModel)) {
374+
generateGraphModel();
375+
}
376+
$("polygon.selected").each(function() {
377+
expandSelection($(this).parent(), "inList");
378+
});
379+
});
380+
315381
});
316382

317383
require(['jquery', 'bootstrap.tooltip'],

0 commit comments

Comments
 (0)