|
16 | 16 | * limitations under the License. |
17 | 17 | */ |
18 | 18 |
|
| 19 | +function tooltipElement(lines) { |
| 20 | + var container = document.createElement("div"); |
| 21 | + lines.forEach(function(line, i) { |
| 22 | + if (line.bold) { |
| 23 | + var b = document.createElement("b"); |
| 24 | + b.textContent = line.text; |
| 25 | + container.appendChild(b); |
| 26 | + } else { |
| 27 | + container.appendChild(document.createTextNode(line.text)); |
| 28 | + } |
| 29 | + if (i < lines.length - 1) { |
| 30 | + container.appendChild(document.createElement("br")); |
| 31 | + } |
| 32 | + }); |
| 33 | + return container; |
| 34 | +} |
| 35 | + |
19 | 36 | var visNS = { |
20 | 37 | // Update / refresh setting |
21 | 38 | shouldUpdate: true, |
@@ -257,10 +274,12 @@ function parseNode(nodeJson, nodeId) { |
257 | 274 | selectedCol = "#ffc180"; |
258 | 275 | } |
259 | 276 |
|
260 | | - // Generate title |
261 | | - var title = "<b>" + nodeId + "</b><br/>"; |
262 | | - title += "Capacity: " + nodeJson[":capacity"] + "<br/>"; |
263 | | - title += "Latency: " + nodeJson[":latency"] |
| 277 | + // Generate title as DOM element (vis-network 10 does not render HTML strings) |
| 278 | + var title = tooltipElement([ |
| 279 | + { text: nodeId, bold: true }, |
| 280 | + { text: "Capacity: " + nodeJson[":capacity"] }, |
| 281 | + { text: "Latency: " + nodeJson[":latency"] } |
| 282 | + ]) |
264 | 283 |
|
265 | 284 | // Construct the node |
266 | 285 | var node = { |
@@ -317,7 +336,11 @@ function parseEdge(edgeJson, sourceId) { |
317 | 336 | "from": edgeJson[":component"], |
318 | 337 | "to": sourceId, |
319 | 338 | "label": edgeJson[":stream"], |
320 | | - "title": "From: " + edgeJson[":component"] + "<br>To: " + sourceId + "<br>Grouping: " + edgeJson[":grouping"] |
| 339 | + "title": tooltipElement([ |
| 340 | + { text: "From: " + edgeJson[":component"] }, |
| 341 | + { text: "To: " + sourceId }, |
| 342 | + { text: "Grouping: " + edgeJson[":grouping"] } |
| 343 | + ]) |
321 | 344 | }); |
322 | 345 | } |
323 | 346 | } |
@@ -410,12 +433,22 @@ function asc_sort(a, b){ |
410 | 433 | return ($(b).text()) < ($(a).text()) ? 1 : -1; |
411 | 434 | } |
412 | 435 |
|
413 | | -// Expose for Cypress testing and inline script access |
414 | | -window.visNS = visNS; |
415 | | -window.checkStream = checkStream; |
| 436 | +// Expose for Cypress testing only |
| 437 | +if (window.Cypress) { |
| 438 | + window.visNS = visNS; |
| 439 | + window.checkStream = checkStream; |
| 440 | +} |
416 | 441 |
|
417 | 442 | $(document).ready(function() { |
418 | 443 | visNS.networkContainer = document.getElementById("mynetwork"); |
419 | 444 | update(); |
| 445 | + |
| 446 | + // Delegated handler replaces inline onclick on component links |
| 447 | + $(document).on('click', '.component-link', function(e) { |
| 448 | + e.preventDefault(); |
| 449 | + var comp = $(this).attr('data-component'); |
| 450 | + visNS.network.selectNodes([comp]); |
| 451 | + handleNodeClickEvent(comp); |
| 452 | + }); |
420 | 453 | }); |
421 | 454 |
|
0 commit comments