From ee7113cc0ea13d17d39fc31b491fd54ecca1373e Mon Sep 17 00:00:00 2001 From: Tianxin Zu <2252922521@qq.com> Date: Fri, 1 Mar 2024 16:07:19 -0800 Subject: [PATCH] keep consistency --- js/app.js | 99 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/js/app.js b/js/app.js index f7a7a39..47be113 100644 --- a/js/app.js +++ b/js/app.js @@ -754,6 +754,16 @@ $(function () { $("#auto-complete").on("click", function (event) { event.preventDefault(); + + var shown = false; + + // check if applied capacity is shown + cy.edges().forEach(function (edge) { + if (edge.css("label").includes("/")) { + shown = true; + } + }); + // Call check graph function, update the graph var expectedGraph = oldFlowNetwork.addFlow(selectedPath, flow, false); @@ -771,31 +781,44 @@ $(function () { } } } - for (const edge of originalFlowNetwork) { - var backward = cy - .edges("[source='" + edge.target + "'][target='" + edge.source + "']") - .css("label"); - if (backward === undefined || backward === null || backward === "") - backward = "0"; - - addEdge( - cy, - edge.source + "/" + edge.target, - { - "line-color": "LightSkyBlue", - "target-arrow-color": "LightSkyBlue", - label: backward + "/" + edge.capacity, - }, - edge.source, - edge.target - ); + + if (shown) { + for (const edge of originalFlowNetwork) { + var backward = cy + .edges("[source='" + edge.target + "'][target='" + edge.source + "']") + .css("label"); + if (backward === undefined || backward === null || backward === "") + backward = "0"; + + addEdge( + cy, + edge.source + "/" + edge.target, + { + "line-color": "LightSkyBlue", + "target-arrow-color": "LightSkyBlue", + label: backward + "/" + edge.capacity, + }, + edge.source, + edge.target + ); + } } + highlightSourceAndSink(); }); $("#undo-updates").on("click", function (event) { event.preventDefault(); + var shown = false; + + // check if applied capacity is shown + cy.edges().forEach(function (edge) { + if (edge.css("label").includes("/")) { + shown = true; + } + }); + cy.edges().remove(); for (const [_, neighborsMap] of oldFlowNetwork.graph) { for (const [_, edge] of neighborsMap) { @@ -810,25 +833,29 @@ $(function () { } } } - for (const edge of originalFlowNetwork) { - var backward = cy - .edges("[source='" + edge.target + "'][target='" + edge.source + "']") - .css("label"); - if (backward === undefined || backward === null || backward === "") - backward = "0"; - - addEdge( - cy, - edge.source + "/" + edge.target, - { - "line-color": "LightSkyBlue", - "target-arrow-color": "LightSkyBlue", - label: backward + "/" + edge.capacity, - }, - edge.source, - edge.target - ); + + if (shown) { + for (const edge of originalFlowNetwork) { + var backward = cy + .edges("[source='" + edge.target + "'][target='" + edge.source + "']") + .css("label"); + if (backward === undefined || backward === null || backward === "") + backward = "0"; + + addEdge( + cy, + edge.source + "/" + edge.target, + { + "line-color": "LightSkyBlue", + "target-arrow-color": "LightSkyBlue", + label: backward + "/" + edge.capacity, + }, + edge.source, + edge.target + ); + } } + highlightSourceAndSink(); });