Skip to content

Commit 7635fe1

Browse files
committed
wip: highlight node based on url parameter
1 parent fdb8e06 commit 7635fe1

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

graph.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ function layoutNodes() {
4949
quality: "proof",
5050
});
5151
cy_layout.run();
52+
// only once, when the layout has finished, parse the URL to see what selection is provided
53+
cy_layout.one("layoutstop", function(event) {
54+
if ((url_highlighted_node !== null) && (url_highlighted_node.nonempty())) {
55+
var node = url_highlighted_node[0];
56+
highlightNode(node);
57+
}
58+
});
5259
}
5360

5461
const BUTTON_ICON_FNAMES = {

index.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const DATA_FOLDER = "simtools";
66
var SIMULATORS = [];
77
var TOOL_DESCRIPTIONS = {};
88
const selected = [];
9+
var url_highlighted_node;
910

1011
// If params are null, show a default message
1112
function showDetails(data, connected) {
@@ -183,6 +184,7 @@ function resetSearch() {
183184
updateHighlights();
184185
}
185186

187+
// INIT
186188
// Load style and data from JSON files
187189
Promise.all([
188190
fetch('assets/cy-style.json')
@@ -221,6 +223,45 @@ Promise.all([
221223
selected.push(simulator);
222224
create_cy_elements(data, style);
223225
create_filters();
224-
showDetails(null, null);
226+
227+
// showDetails of node selected in URL
228+
// Note: do not change layout here to select node, because we need to wait
229+
// for the initial layout to finish running
230+
const providedURL = new URL(window.location.href);
231+
const params = new URLSearchParams(providedURL.search);
232+
233+
if (params.size === 0)
234+
{
235+
console.log("No parameters passed, no op");
236+
showDetails(null, null);
237+
url_highlighted_node = null;
238+
}
239+
// We only process the first value of "selected" if there are multiples
240+
else
241+
{
242+
var simulator = params.get('selected');
243+
console.log("Simulator selected in url param list: " + simulator);
244+
245+
url_highlighted_node = cy.nodes("[id='" + simulator + "']")
246+
247+
if (url_highlighted_node.empty()) {
248+
console.log("Provided parameter not in simulator list. No op");
249+
showDetails(null, null);
250+
}
251+
else
252+
{
253+
var node = url_highlighted_node[0];
254+
console.log("Selecting provided parameter: " + simulator);
255+
showDetails(url_highlighted_node.data(), url_highlighted_node.outgoers("edge").map((edge) => {
256+
return { type: "outgoing", target: edge.target().id(), label: edge.data("label"), source: edge.source().id() };
257+
}).concat(
258+
url_highlighted_node.incomers("edge").map((edge) => {
259+
return { type: "incoming", target: edge.target().id(), label: edge.data("label"), source: edge.source().id() }
260+
})
261+
)
262+
);
263+
}
264+
}
265+
225266
}
226267
);

0 commit comments

Comments
 (0)