-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Update networks and GCC logic
- Loading branch information
Showing
10 changed files
with
198 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
getDatasetNetworks, | ||
getNetworkGCC, | ||
} from "@/api/rest"; | ||
import { Dataset, Network} from "./types"; | ||
import { availableNetworks } from './store'; | ||
import { showGCC } from "./layerStyles"; | ||
|
||
|
||
// ------------------ | ||
// Exported functions | ||
// ------------------ | ||
|
||
export async function toggleNodeActive( | ||
nodeId: number, | ||
dataset: Dataset, | ||
) { | ||
const network = await getNetwork(nodeId, dataset); | ||
if (network) { | ||
if (network.deactivated === undefined) network.deactivated = { | ||
nodes: [], | ||
edges: [], | ||
}; | ||
if (network.deactivated.nodes.includes(nodeId)) { | ||
network.deactivated.nodes = network.deactivated.nodes.filter((n) => n !== nodeId) | ||
} else { | ||
network.deactivated.nodes = [ | ||
...network.deactivated.nodes, | ||
nodeId, | ||
] | ||
} | ||
if (network.deactivated.nodes.length) { | ||
network.gcc = await getNetworkGCC(network.id, network.deactivated.nodes); | ||
} else { | ||
network.gcc = network.nodes.map((n) => n.id) | ||
} | ||
showGCC(network); | ||
} | ||
} | ||
|
||
// ------------------ | ||
// Internal functions | ||
// ------------------ | ||
|
||
async function getNetwork( | ||
nodeId: number, | ||
dataset: Dataset, | ||
): Promise<Network | undefined> { | ||
let network; | ||
availableNetworks.value.forEach((net) => { | ||
if (net.nodes.map((n) => n.id).includes(nodeId)) { | ||
network = net; | ||
} | ||
}) | ||
if (!network) { | ||
availableNetworks.value = [ | ||
...availableNetworks.value, | ||
...await getDatasetNetworks(dataset.id), | ||
] | ||
} | ||
availableNetworks.value.forEach((net) => { | ||
if (net.nodes.map((n) => n.id).includes(nodeId)) { | ||
network = net; | ||
} | ||
}) | ||
return network; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.