From 1317a035459586589db40654cbb9fe4733bdca19 Mon Sep 17 00:00:00 2001 From: Elora-V <elora95.vigo@gmail.com> Date: Mon, 16 Sep 2024 08:13:00 +0200 Subject: [PATCH] remove .value for all network --- src/composables/CalculateRelationCycle.ts | 20 +++---- src/composables/CalculateSize.ts | 16 +++--- src/composables/ConvertFromNetwork.ts | 6 +-- src/composables/ConvertToNetwork.ts | 2 +- src/composables/LayoutDrawCycle.ts | 54 +++++++++---------- src/composables/LayoutFindCycle.ts | 10 ++-- src/composables/LayoutMain.ts | 10 ++-- src/composables/LayoutMainChain.ts | 4 +- src/composables/LayoutManageSideCompounds.ts | 30 +++++------ src/composables/LayoutReversibleReactions.ts | 6 +-- src/composables/LayoutSugiyamaForce.ts | 2 +- src/composables/SubgraphForSubgraphNetwork.ts | 2 +- src/composables/SubgraphForViz.ts | 2 +- .../__tests__/CalculateRelationCycle.tests.ts | 5 +- .../__tests__/CalculateSize.tests.ts | 17 +++--- src/types/SubgraphNetwork.ts | 4 +- 16 files changed, 94 insertions(+), 96 deletions(-) diff --git a/src/composables/CalculateRelationCycle.ts b/src/composables/CalculateRelationCycle.ts index 2ce533a..60cef57 100644 --- a/src/composables/CalculateRelationCycle.ts +++ b/src/composables/CalculateRelationCycle.ts @@ -133,10 +133,10 @@ export function neighborsGroupCycle(subgraphNetwork:SubgraphNetwork,cycleGroupId */ export function parentNodeNotInCycle(subgraphNetwork: SubgraphNetwork, listNodes: string[]): string[][] { const parentNodes = listNodes.map((node: string) => { - const parentNodesI = subgraphNetwork.network.value.links + const parentNodesI = subgraphNetwork.network.links .filter(link => link.target.id === node) // get link with those node as child .map(link => link.source.id) // get the other node - .filter(id => !inCycle(subgraphNetwork.network.value, id)) // no node in a cycle + .filter(id => !inCycle(subgraphNetwork.network, id)) // no node in a cycle return parentNodesI; }); return parentNodes; @@ -152,10 +152,10 @@ export function parentNodeNotInCycle(subgraphNetwork: SubgraphNetwork, listNodes */ export function childNodeNotInCycle(subgraphNetwork: SubgraphNetwork, listNodes: string[]): string[][] { const childNodes = listNodes.map((node: string) => { - const childNodesI = subgraphNetwork.network.value.links + const childNodesI = subgraphNetwork.network.links .filter(link => link.source.id === node) // get link with those node as parent .map(link => link.target.id) // get the other node - .filter(id => !inCycle(subgraphNetwork.network.value, id)) // no node in a cycle + .filter(id => !inCycle(subgraphNetwork.network, id)) // no node in a cycle return childNodesI; }); @@ -321,7 +321,7 @@ export function sortLinksWithAllGroupCycle(subgraphNetwork:SubgraphNetwork,order links=links.concat(resultSorting.linksOrdered); }); // add other links - Object.values(subgraphNetwork.network.value.links).forEach((link) => { + Object.values(subgraphNetwork.network.links).forEach((link) => { if (!links.includes(link)){ links.push(link); } @@ -329,7 +329,7 @@ export function sortLinksWithAllGroupCycle(subgraphNetwork:SubgraphNetwork,order return { subgraphNetwork:subgraphNetwork,linksOrdered:links }; }else{ // no change - return { subgraphNetwork:subgraphNetwork,linksOrdered:subgraphNetwork.network.value.links }; + return { subgraphNetwork:subgraphNetwork,linksOrdered:subgraphNetwork.network.links }; } } @@ -395,12 +395,12 @@ function sortLinksWithGroupCycle(subgraphNetwork:SubgraphNetwork,groupCycle:stri function getLinksNodeGroupCycle(subgraphNetwork:SubgraphNetwork,nodeId:string,groupCycleId:string,source:"node"|"groupCycle"):LinkLayout[]{ if (source==="node"){ // node to group cycle - return Object.values(subgraphNetwork.network.value.links).filter((link) => { + return Object.values(subgraphNetwork.network.links).filter((link) => { return link.source.id === nodeId && link.target.metadataLayout && TypeSubgraph.CYCLEGROUP in link.target.metadataLayout && link.target.metadataLayout[TypeSubgraph.CYCLEGROUP] === groupCycleId; }); }else{ // group cycle to node - return Object.values(subgraphNetwork.network.value.links).filter((link) => { + return Object.values(subgraphNetwork.network.links).filter((link) => { return link.target.id === nodeId && link.source.metadataLayout && TypeSubgraph.CYCLEGROUP in link.source.metadataLayout && link.source.metadataLayout[TypeSubgraph.CYCLEGROUP] === groupCycleId; }); } @@ -441,7 +441,7 @@ export function getListNodeLinksForCycleGroup(subgraphNetwork:SubgraphNetwork,gr :{nodes:{ id: string,fx?:number, fy?:number,x?:number,y?:number }[],links:{source:string,target:string}[]}{ const nodesGroupCycle=getNodesPlacedInGroupCycle(subgraphNetwork,groupCycleName,positionAsFixed); const nodesGroupCycleName=Object.values(nodesGroupCycle).map(node=>node.id); - const linksGroupCycle=getLinksForListNodes(subgraphNetwork.network.value,nodesGroupCycleName); + const linksGroupCycle=getLinksForListNodes(subgraphNetwork.network,nodesGroupCycleName); return {nodes:nodesGroupCycle,links:linksGroupCycle}; } @@ -457,7 +457,7 @@ export function getListNodeLinksForCycleGroupAsObject(subgraphNetwork:SubgraphNe :{nodes:{[key:string]:{ x:number,y:number }},links:{source:string,target:string}[]}{ const nodesGroupCycle=getNodesPlacedInGroupCycleAsObject(subgraphNetwork,groupCycleName); const nodesGroupCycleName=Object.keys(nodesGroupCycle); - const linksGroupCycle=getLinksForListNodes(subgraphNetwork.network.value,nodesGroupCycleName); + const linksGroupCycle=getLinksForListNodes(subgraphNetwork.network,nodesGroupCycleName); return {nodes:nodesGroupCycle,links:linksGroupCycle}; } diff --git a/src/composables/CalculateSize.ts b/src/composables/CalculateSize.ts index b1366aa..c564f7c 100644 --- a/src/composables/CalculateSize.ts +++ b/src/composables/CalculateSize.ts @@ -290,8 +290,8 @@ export function rectangleSize(listCoordinates:Coordinate[],listID?:string[],subg minX = -defaultWidthNode/2; } else { const minXNode = listID[minXIndex]; - if (!(minXNode in subgraphNetwork.network.value.nodes)) throw new Error("Node not in network"); - const sizeMinXNode = getSizeNodePixel(subgraphNetwork.network.value.nodes[minXNode],subgraphNetwork.networkStyle.value); + if (!(minXNode in subgraphNetwork.network.nodes)) throw new Error("Node not in network"); + const sizeMinXNode = getSizeNodePixel(subgraphNetwork.network.nodes[minXNode],subgraphNetwork.networkStyle); minX = minX - sizeMinXNode.width/2; } @@ -300,8 +300,8 @@ export function rectangleSize(listCoordinates:Coordinate[],listID?:string[],subg maxX = defaultWidthNode/2; }else { const maxXNode = listID[maxXIndex]; - if (!(maxXNode in subgraphNetwork.network.value.nodes)) throw new Error("Node not in network"); - const sizeMaxXNode = getSizeNodePixel(subgraphNetwork.network.value.nodes[maxXNode],subgraphNetwork.networkStyle.value); + if (!(maxXNode in subgraphNetwork.network.nodes)) throw new Error("Node not in network"); + const sizeMaxXNode = getSizeNodePixel(subgraphNetwork.network.nodes[maxXNode],subgraphNetwork.networkStyle); maxX = maxX + sizeMaxXNode.width/2; } @@ -310,8 +310,8 @@ export function rectangleSize(listCoordinates:Coordinate[],listID?:string[],subg minY = -defaultHeightNode/2; } else { const minYNode = listID[minYIndex]; - if (!(minYNode in subgraphNetwork.network.value.nodes)) throw new Error("Node not in network"); - const sizeMinYNode = getSizeNodePixel(subgraphNetwork.network.value.nodes[minYNode],subgraphNetwork.networkStyle.value); + if (!(minYNode in subgraphNetwork.network.nodes)) throw new Error("Node not in network"); + const sizeMinYNode = getSizeNodePixel(subgraphNetwork.network.nodes[minYNode],subgraphNetwork.networkStyle); minY = minY - sizeMinYNode.height/2; } @@ -320,8 +320,8 @@ export function rectangleSize(listCoordinates:Coordinate[],listID?:string[],subg maxY = defaultHeightNode/2; } else { const maxYNode = listID[maxYIndex]; - if (!(maxYNode in subgraphNetwork.network.value.nodes)) throw new Error("Node not in network"); - const sizeMaxYNode = getSizeNodePixel(subgraphNetwork.network.value.nodes[maxYNode],subgraphNetwork.networkStyle.value); + if (!(maxYNode in subgraphNetwork.network.nodes)) throw new Error("Node not in network"); + const sizeMaxYNode = getSizeNodePixel(subgraphNetwork.network.nodes[maxYNode],subgraphNetwork.networkStyle); maxY = maxY + sizeMaxYNode.height/2; } } diff --git a/src/composables/ConvertFromNetwork.ts b/src/composables/ConvertFromNetwork.ts index af84107..6fd32ac 100644 --- a/src/composables/ConvertFromNetwork.ts +++ b/src/composables/ConvertFromNetwork.ts @@ -290,7 +290,7 @@ export function networkToViz(subgraphNetwork:SubgraphNetwork,cycle:boolean=true, // insert nodes if (addNodes){ - Object.entries(subgraphNetwork.network.value.nodes) + Object.entries(subgraphNetwork.network.nodes) .sort(([keyA], [keyB]) => keyA.localeCompare(keyB)) .forEach(([key, node])=> { const nodeViz=nodeForViz(subgraphNetwork,node,cycle,groupOrCluster); @@ -379,10 +379,10 @@ export function networkToViz(subgraphNetwork:SubgraphNetwork,cycle:boolean=true, */ function nodeForViz(subgraphNetwork:SubgraphNetwork,node:NodeLayout,cycle:boolean,groupOrCluster:"group"|"cluster"):{name:string,attributes:AttributesViz}|undefined{ // if cycle not taken into account or not in cycle - if (!cycle || !inCycle(subgraphNetwork.network.value,node.id)){ + if (!cycle || !inCycle(subgraphNetwork.network,node.id)){ const attributes:AttributesViz={}; // size of node in inches - const sizeNode= getSizeNodePixel(node,subgraphNetwork.networkStyle.value); + const sizeNode= getSizeNodePixel(node,subgraphNetwork.networkStyle); attributes.height=pixelsToInches(sizeNode.height); attributes.width=pixelsToInches(sizeNode.width); attributes.fixedsize=true; diff --git a/src/composables/ConvertToNetwork.ts b/src/composables/ConvertToNetwork.ts index 76bd682..4b0f600 100644 --- a/src/composables/ConvertToNetwork.ts +++ b/src/composables/ConvertToNetwork.ts @@ -88,7 +88,7 @@ export function networkLayoutToNetwork(networkLayout: NetworkLayout): Network { * @param assignRank boolean that indicates if rank and order need to be infered and assigned to nodes */ export async function changeNetworkFromViz(json: JsonViz, subgraphNetwork: SubgraphNetwork, assignRank:boolean=false): Promise<SubgraphNetwork> { - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; const unique_y:Array<number> =[]; json["objects"].forEach((node) => { diff --git a/src/composables/LayoutDrawCycle.ts b/src/composables/LayoutDrawCycle.ts index 7d55213..8ab2523 100644 --- a/src/composables/LayoutDrawCycle.ts +++ b/src/composables/LayoutDrawCycle.ts @@ -38,7 +38,7 @@ import { childNodeNotInCycle, getListNodeLinksForCycleGroup, getListNodeLinksFor */ export async function coordinateAllCycles(subgraphNetwork:SubgraphNetwork,allowInterncircle:boolean=false):Promise<SubgraphNetwork> { - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; const cycles = subgraphNetwork.cycles? Object.values(subgraphNetwork.cycles):undefined; let i=0 let newGroup=true; @@ -142,7 +142,7 @@ function addNewCycleGroup(subgraphNetwork:SubgraphNetwork, groupName:string):Sub * @returns A number indicating the sorting order. */ function sortingCycleForDrawing(subgraphNetwork:SubgraphNetwork,a:Subgraph,b:Subgraph,fullConstraint:boolean=false):number{ - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; // first sort by number of fixed nodes const fixedNodesA = a.nodes.filter(node => network.nodes[node].metadata && network.nodes[node].metadata.fixedCycle).length; @@ -188,7 +188,7 @@ function sortingCycleForDrawing(subgraphNetwork:SubgraphNetwork,a:Subgraph,b:Sub * @returns The updated subgraph network with the nodes placed in the cycle. */ async function coordinateCycle(subgraphNetwork:SubgraphNetwork, cycleToDrawID:string,groupCycleName:string,allowInterncircle:boolean=true):Promise<SubgraphNetwork>{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; // Get nodes to place let cycle:string[]=[]; @@ -241,11 +241,11 @@ async function coordinateCycle(subgraphNetwork:SubgraphNetwork, cycleToDrawID:st } async function independentCycleCoordinates(subgraphNetwork:SubgraphNetwork,cycleToDrawID:string,groupCycleName:string):Promise<SubgraphNetwork>{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; const cycle=subgraphNetwork.cycles[cycleToDrawID].nodes; // radius and centroid - const radius = await getRadiusSize(cycle,network,subgraphNetwork.networkStyle.value); + const radius = await getRadiusSize(cycle,network,subgraphNetwork.networkStyle); // first cycle centered at 0,0 const centroidX=0; const centroidY=0; @@ -263,7 +263,7 @@ async function independentCycleCoordinates(subgraphNetwork:SubgraphNetwork,cycle } async function tangentCycleCoordinates(subgraphNetwork:SubgraphNetwork,cycleToDrawID:string,groupCycleName:string,nodeFixed:Node,nodesPlaced:string[],allowInterncircle:boolean=false):Promise<SubgraphNetwork>{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; const cycle=subgraphNetwork.cycles[cycleToDrawID].nodes; // get fixed node coordinates (in the group cycle) @@ -276,7 +276,7 @@ async function tangentCycleCoordinates(subgraphNetwork:SubgraphNetwork,cycleToDr const shiftedCycle = cycleCopy.splice(firstIndex).concat(cycleCopy); // radius - const radius = await getRadiusSize(cycle,network,subgraphNetwork.networkStyle.value); + const radius = await getRadiusSize(cycle,network,subgraphNetwork.networkStyle); subgraphNetwork.cycles[cycleToDrawID].metadata.radius=radius; //centroid depending on fixed cycle @@ -365,7 +365,7 @@ async function getRadiusSize(cycle:string[],network:Network,styleNetwork:GraphSt function cycleNodesCoordinates(cycleName:string,cycle:string[],centroidX:number,centroidY:number,radius:number,subgraphNetwork:SubgraphNetwork, shiftAngle:number=-Math.PI/2,groupcycle?:string,):{subgraphNetwork:SubgraphNetwork,positionBefore:{[key:string]:{x:number,y:number}}}{ - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; let positionBefore:{[key:string]:{x:number,y:number}}={}; cycle.forEach((node, i) => { @@ -396,12 +396,12 @@ function cycleNodesCoordinates(cycleName:string,cycle:string[],centroidX:number, } } else if (node in subgraphNetwork.network.value.nodes) { // get position before drawing cycle - const xBefore=subgraphNetwork.network.value.nodes[node].x; - const yBefore=subgraphNetwork.network.value.nodes[node].x; + const xBefore=subgraphNetwork.network.nodes[node].x; + const yBefore=subgraphNetwork.network.nodes[node].x; positionBefore[node]={x:xBefore,y:yBefore}; // assign new position - subgraphNetwork.network.value.nodes[node].x=x; - subgraphNetwork.network.value.nodes[node].y=y; + subgraphNetwork.network.nodes[node].x=x; + subgraphNetwork.network.nodes[node].y=y; } else{ console.error("Node not in network or groupcycle not provided") } @@ -436,12 +436,12 @@ function undoIfOverlap(subgraphNetwork:SubgraphNetwork,groupCycleName:string,pos function isOverlapCycles(subgraphNetwork:SubgraphNetwork,groupCycleName:string):boolean{ const graph =getListNodeLinksForCycleGroupAsObject(subgraphNetwork,groupCycleName); // intersection of edges : - const intersectionEdges=isIntersectionGraph(graph.nodes ,graph.links,subgraphNetwork.network.value,subgraphNetwork.networkStyle.value); + const intersectionEdges=isIntersectionGraph(graph.nodes ,graph.links,subgraphNetwork.network,subgraphNetwork.networkStyle.value); if (intersectionEdges){ return true; }else{ // overlap of nodes - const nodesOverlap=isOverlapNodes(graph.nodes,subgraphNetwork.network.value,subgraphNetwork.networkStyle.value); + const nodesOverlap=isOverlapNodes(graph.nodes,subgraphNetwork.network,subgraphNetwork.networkStyle.value); if (nodesOverlap){ return true; }else{ @@ -467,7 +467,7 @@ function isOverlapCycles(subgraphNetwork:SubgraphNetwork,groupCycleName:string): function getUnfixedIntervals(nodes:string[],subgraphNetwork:SubgraphNetwork) { let intervals:number[][] = []; let start = null; - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; nodes.forEach((nodeID,i) => { const node=network.nodes[nodeID]; if (node.metadata && !node.metadata.fixedInCycle) { @@ -508,7 +508,7 @@ function getUnfixedIntervals(nodes:string[],subgraphNetwork:SubgraphNetwork) { */ function lineNodesCoordinates(start: {x: number, y: number}, end: {x: number, y: number}, nodes: string[], subgraphNetwork:SubgraphNetwork,groupCycleName?:string):{subgraphNetwork:SubgraphNetwork,positionBefore:{[key:string]:{x:number,y:number}}} { - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; let positionBefore:{[key:string]:{x:number,y:number}}={}; // Calculate direction vector @@ -550,14 +550,14 @@ function lineNodesCoordinates(start: {x: number, y: number}, end: {x: number, y: } else { console.error("CycleGroup not in subgraphNetwork"); } - } else if (node in subgraphNetwork.network.value.nodes) { + } else if (node in subgraphNetwork.network.nodes) { // get position before drawing cycle - const xBefore=subgraphNetwork.network.value.nodes[node].x; - const yBefore=subgraphNetwork.network.value.nodes[node].x; + const xBefore=subgraphNetwork.network.nodes[node].x; + const yBefore=subgraphNetwork.network.nodes[node].x; positionBefore[node]={x:xBefore,y:yBefore}; // assign new position - subgraphNetwork.network.value.nodes[node].x=x; - subgraphNetwork.network.value.nodes[node].y=y; + subgraphNetwork.network.nodes[node].x=x; + subgraphNetwork.network.nodes[node].y=y; } else{ console.error("Node not in network or groupcycle not provided") } @@ -585,7 +585,7 @@ function lineNodesCoordinates(start: {x: number, y: number}, end: {x: number, y: * @returns An object containing the updated subgraph network and group number. */ async function updateGroupCycles(remainingCycles: Subgraph[], subgraphNetwork: SubgraphNetwork, group: number, groupCycleName: string): Promise<{subgraphNetwork: SubgraphNetwork, group: number}> { - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; const groupCycleIsDraw = isRemainingCycleIndepOfDrawing(remainingCycles, subgraphNetwork); if (groupCycleIsDraw && subgraphNetwork.cyclesGroup[groupCycleName].metadata) { @@ -630,7 +630,7 @@ async function forceGroupCycle(subgraphNetwork:SubgraphNetwork, groupCycleName:s } // get attributes for force layout - const distanceLinks=medianEdgeLength(subgraphNetwork.network.value,false); + const distanceLinks=medianEdgeLength(subgraphNetwork.network,false); const strengthManyBody=-distanceLinks*10; // applying force layout @@ -668,7 +668,7 @@ async function forceGroupCycle(subgraphNetwork:SubgraphNetwork, groupCycleName:s */ function isRemainingCycleIndepOfDrawing(remainingCycles:Subgraph[], subgraphNetwork:SubgraphNetwork):boolean{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; if (remainingCycles.every(cycle => cycle.nodes.every(node => @@ -762,7 +762,7 @@ function findTopCycleNode(subgraphNetwork: SubgraphNetwork, cycleNodes:string[]) * @returns An array of indices representing lists containing minimum y-coordinate nodes. */ function getNodesAssociatedMinY(subgraphNetwork: SubgraphNetwork, associatedListNodes: string[][]): number[] { - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; let minY=Infinity; let minNodes: number[] = []; associatedListNodes.forEach((listNodes,i) => { @@ -788,7 +788,7 @@ function getNodesAssociatedMinY(subgraphNetwork: SubgraphNetwork, associatedList * @returns An array of indices representing lists containing maximum y-coordinate nodes. */ function getNodesAssociatedMaxY(subgraphNetwork: SubgraphNetwork, associatedListNodes: string[][]): number[] { - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; let maxY=-Infinity; let maxNodes:number[]=[]; associatedListNodes.forEach((listNodes,i) => { @@ -814,7 +814,7 @@ function getNodesAssociatedMaxY(subgraphNetwork: SubgraphNetwork, associatedList * @returns The name of the node with the median x-coordinate. */ function nodeMedianX(subgraphNetwork: SubgraphNetwork, listNodes: string[]): string { - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; let xValues = listNodes.map(node => [node,network.nodes[node].x]); xValues.sort((a, b) => Number(a[1]) - Number(b[1])); // sort by x diff --git a/src/composables/LayoutFindCycle.ts b/src/composables/LayoutFindCycle.ts index cde82c8..a0bba17 100644 --- a/src/composables/LayoutFindCycle.ts +++ b/src/composables/LayoutFindCycle.ts @@ -23,7 +23,7 @@ export function addDirectedCycleToSubgraphNetwork(subgraphNetwork:SubgraphNetwor let existingCycle=true; let i=0; while (existingCycle && i< cycle[1].length){ - if (!(cycle[1][i] in subgraphNetwork.network.value.nodes)){ + if (!(cycle[1][i] in subgraphNetwork.network.nodes)){ existingCycle=false; } i++; @@ -32,7 +32,7 @@ export function addDirectedCycleToSubgraphNetwork(subgraphNetwork:SubgraphNetwor if (existingCycle){ // update metada node : add cycle information cycle[1].forEach(node=>{ - updateNodeMetadataSubgraph(subgraphNetwork.network.value,node,cycle[0],TypeSubgraph.CYCLE); + updateNodeMetadataSubgraph(subgraphNetwork.network,node,cycle[0],TypeSubgraph.CYCLE); }); // remove reversible version of node in cycle, to only keep the one in the direction of cycle const toRename=keepFirstReversibleNode(subgraphNetwork,cycle[1],false) as {[key: string]: string}; @@ -85,10 +85,10 @@ export function addDirectedCycleToSubgraphNetwork(subgraphNetwork:SubgraphNetwor function getJohnsonCycles(subNetwork:SubgraphNetwork,onlyDirectedCycle:boolean=true,minsize:number=4):{[key:string]:string[]} { // get graph structure for johnson algorithm - const nodes=Object.keys(subNetwork.network.value.nodes).sort(); - const graph=graphForJohnson(subNetwork.network.value,nodes,onlyDirectedCycle); + const nodes=Object.keys(subNetwork.network.nodes).sort(); + const graph=graphForJohnson(subNetwork.network,nodes,onlyDirectedCycle); // apply johnson algorithm : get cycle - return JohnsonAlgorithm(graph,nodes,"All",onlyDirectedCycle,minsize,subNetwork.network.value); + return JohnsonAlgorithm(graph,nodes,"All",onlyDirectedCycle,minsize,subNetwork.network); } diff --git a/src/composables/LayoutMain.ts b/src/composables/LayoutMain.ts index 40f012f..05b65c4 100644 --- a/src/composables/LayoutMain.ts +++ b/src/composables/LayoutMain.ts @@ -63,8 +63,8 @@ export async function algorithmOnNetwork(network:Network,networkStyle:GraphStyle // initialize the subgraphNetwork object let subgraphNetwork:SubgraphNetwork={ - network:ref<NetworkLayout>(networkLayout), - networkStyle:ref<GraphStyleProperties>(networkStyle) + network:networkLayout, + networkStyle:networkStyle } @@ -72,7 +72,7 @@ export async function algorithmOnNetwork(network:Network,networkStyle:GraphStyle // change coordinates of the network with the algorithm await allSteps(subgraphNetwork,parameters,true,true); // convert networkLayout to network - return networkLayoutToNetwork(subgraphNetwork.network.value); + return networkLayoutToNetwork(subgraphNetwork.network); } catch(err){ console.log(" Error during execution of algorithm : " + err); @@ -92,8 +92,8 @@ export async function algorithmOnNetwork(network:Network,networkStyle:GraphStyle */ export async function allSteps(subgraphNetwork: SubgraphNetwork,parameters:Parameters,shiftCoord:boolean=true,printNameStep:boolean=false):Promise<SubgraphNetwork> { - let network=subgraphNetwork.network.value; - let networkStyle=subgraphNetwork.networkStyle.value; + let network=subgraphNetwork.network; + let networkStyle=subgraphNetwork.networkStyle; if (printNameStep){ console.log('_____________________________________________'); diff --git a/src/composables/LayoutMainChain.ts b/src/composables/LayoutMainChain.ts index 36950fa..bd130f8 100644 --- a/src/composables/LayoutMainChain.ts +++ b/src/composables/LayoutMainChain.ts @@ -39,7 +39,7 @@ export function addMainChainFromSources(subgraphNetwork:SubgraphNetwork, sources ):SubgraphNetwork{ //console.log('create main chain from longest path'); - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; subgraphNetwork[TypeSubgraph.MAIN_CHAIN]={}; // get sources @@ -76,7 +76,7 @@ export function addMainChainFromSources(subgraphNetwork:SubgraphNetwork, sources */ export function addMiniBranchToMainChain(subgraphNetwork:SubgraphNetwork):SubgraphNetwork{ //console.log('add mini branch to main chain'); - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; const graph=networkToGDSGraph(network); // for each main chain : Object.entries(subgraphNetwork.mainChains).forEach(([mainChainID,mainChain]:[string,Subgraph]) => { diff --git a/src/composables/LayoutManageSideCompounds.ts b/src/composables/LayoutManageSideCompounds.ts index 908c587..34416e9 100644 --- a/src/composables/LayoutManageSideCompounds.ts +++ b/src/composables/LayoutManageSideCompounds.ts @@ -150,7 +150,7 @@ import { error } from "console"; export async function addSideCompoundAttributeFromList(subgraphNetwork:SubgraphNetwork, pathListSideCompounds:string):Promise<void>{ const listIDSideCompounds = await getIDSideCompoundsInNetworkFromFile(subgraphNetwork,pathListSideCompounds); listIDSideCompounds.forEach((sideCompoundID) => { - setAsSideCompound(subgraphNetwork.network.value,sideCompoundID); + setAsSideCompound(subgraphNetwork.network,sideCompoundID); }); } @@ -162,7 +162,7 @@ export async function addSideCompoundAttributeFromList(subgraphNetwork:SubgraphN */ async function getIDSideCompoundsInNetworkFromFile(subgraphNetwork:SubgraphNetwork,pathListSideCompounds:string):Promise<string[]>{ let listIDSideCompounds:string[]; - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; try { listIDSideCompounds = await getIDSideCompoundsFromFile(pathListSideCompounds); const sideCompoundInNetwork = Object.keys(network.nodes).filter(id => listIDSideCompounds.includes(id)); @@ -256,8 +256,8 @@ export async function putDuplicatedSideCompoundAside(subgraphNetwork:SubgraphNet * @returns void */ export async function duplicateSideCompound(subgraphNetwork:SubgraphNetwork):Promise<void>{ - const network = subgraphNetwork.network.value; - const networkStyle = subgraphNetwork.networkStyle.value; + const network = subgraphNetwork.network; + const networkStyle = subgraphNetwork.networkStyle; // duplication of side compounds duplicateAllNodesByAttribut(network, networkStyle, sideCompoundAttribute); // add attributes to side compounds duplicates @@ -271,10 +271,10 @@ export async function duplicateSideCompound(subgraphNetwork:SubgraphNetwork):Pro * @returns void */ function sideCompoundAttributeOnDuplicate(subgraphNetwork:SubgraphNetwork):void{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; Object.keys(network.nodes).forEach((nodeID)=>{ if(isDuplicate(network,nodeID)){ - setAsSideCompound(subgraphNetwork.network.value,nodeID); + setAsSideCompound(subgraphNetwork.network,nodeID); } }); } @@ -289,7 +289,7 @@ function sideCompoundAttributeOnDuplicate(subgraphNetwork:SubgraphNetwork):void{ */ function removeSideCompoundsFromNetwork(subgraphNetwork:SubgraphNetwork): SubgraphNetwork{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; subgraphNetwork.sideCompounds={}; const sideCompounds = subgraphNetwork.sideCompounds; const listIDCoftactors:string[]=[]; @@ -336,7 +336,7 @@ export async function reinsertionSideCompounds(subgraphNetwork:SubgraphNetwork,f const sideCompounds = subgraphNetwork.sideCompounds // get information for length of edge for side compounds : // get the min length of edge in the network (if not, use default value) - let minLength=minEdgeLength(subgraphNetwork.network.value,false); + let minLength=minEdgeLength(subgraphNetwork.network,false); // get the default value : min lenght if there is no link in the network (when side compounds are removed) : if (isNaN(minLength)){ console.warn('Minimal edge length by default'); @@ -368,8 +368,8 @@ export async function reinsertionSideCompounds(subgraphNetwork:SubgraphNetwork,f * @returns The calculated minimum edge length. */ async function minEdgeLengthDefault(subgraphNetwork:SubgraphNetwork,factorMinEdgeLength:number):Promise<number>{ - const network = subgraphNetwork.network.value; - const networkStyle = subgraphNetwork.networkStyle.value; + const network = subgraphNetwork.network; + const networkStyle = subgraphNetwork.networkStyle; const meanSize=await getMeanNodesSizePixel(Object.values(network.nodes),networkStyle, false); const defaultSep=(meanSize.height+meanSize.width)/2; if(subgraphNetwork.attributs){ @@ -387,7 +387,7 @@ async function minEdgeLengthDefault(subgraphNetwork:SubgraphNetwork,factorMinEdg * @returns subgraphNetwork updated */ async function updateSideCompoundsReversibleReaction(subgraphNetwork:SubgraphNetwork):Promise<SubgraphNetwork>{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; if (subgraphNetwork.sideCompounds){ let sideCompounds=subgraphNetwork.sideCompounds; Object.keys(sideCompounds).forEach((reactionID)=>{ @@ -450,7 +450,7 @@ async function motifStampSideCompound(subgraphNetwork:SubgraphNetwork,reactionID * @throws Error if the reaction is not found in the network. */ async function initializeReactionSideCompounds(subgraphNetwork:SubgraphNetwork,idReaction:string):Promise<Reaction>{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; if (network.nodes[idReaction] && subgraphNetwork.sideCompounds && subgraphNetwork.sideCompounds[idReaction]){ try { // position of reaction @@ -493,7 +493,7 @@ async function initializeReactionSideCompounds(subgraphNetwork:SubgraphNetwork,i * @returns An array of objects representing the metabolites, each containing an ID and a type. */ async function getMetaboliteFromReaction(subgraphNetwork: SubgraphNetwork, idReaction: string): Promise<{ id: string; type: MetaboliteType }[]> { - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; return network.links .filter((link) => link.source.id === idReaction || link.target.id === idReaction) .map((link) => ({ @@ -731,7 +731,7 @@ async function giveCoordAllSideCompounds(subgraphNetwork:SubgraphNetwork,reactio if (subgraphNetwork.sideCompounds){ const distance=calculateDistance(subgraphNetwork, factorLength); const sideCompounds=subgraphNetwork.sideCompounds[reaction.id]; - const reactionCoord=subgraphNetwork.network.value.nodes[reaction.id]; + const reactionCoord=subgraphNetwork.network.nodes[reaction.id]; // Reactants Placement if (sideCompounds.reactants && sideCompounds.reactants.length>0){ await placeSideCompounds(sideCompounds.reactants, reaction, reactionCoord, distance, true); @@ -866,7 +866,7 @@ function insertAllSideCompoundsInNetwork(subgraphNetwork:SubgraphNetwork,reactio * @param typeSideCompound - The type of the side compound (reactant or product). */ function insertSideCompoundInNetwork(subgraphNetwork:SubgraphNetwork,reactionID:string,sideCompound:Node,typeSideCompound:MetaboliteType):void{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; // insert node network.nodes[sideCompound.id]=sideCompound; // insert link diff --git a/src/composables/LayoutReversibleReactions.ts b/src/composables/LayoutReversibleReactions.ts index 1bbe991..ba48db0 100644 --- a/src/composables/LayoutReversibleReactions.ts +++ b/src/composables/LayoutReversibleReactions.ts @@ -272,7 +272,7 @@ export async function chooseReversibleReaction( nodeOrderFunction: (network: Network, sources: Array<string> | StartNodesType) => Promise<string[]> = BFSWithSources ): Promise<SubgraphNetwork> { let nodeOrder: string[] = []; - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; // get node order nodeOrder = await nodeOrderFunction(network,sources); // keep the first node seen only, for duplicated nodes @@ -288,7 +288,7 @@ export async function chooseReversibleReaction( * @param nodeOrder The order of nodes to consider for keeping the first reversible node. */ export function keepFirstReversibleNode(subgraphNetwork:SubgraphNetwork,nodeOrder:string[],doRename:boolean=true):SubgraphNetwork |{[key: string]: string}{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; const reactionToRemove:Array<string>=[]; const nodeToRename:{[key: string]: string}={}; @@ -336,7 +336,7 @@ export function keepFirstReversibleNode(subgraphNetwork:SubgraphNetwork,nodeOrde * @returns The modified subgraph network. */ export function renameAllIDNode(subgraphNetwork:SubgraphNetwork,nodesToRename:{[key: string]: string}):SubgraphNetwork{ - const network = subgraphNetwork.network.value; + const network = subgraphNetwork.network; // Modify nodes Object.keys(network.nodes).forEach(ID => { diff --git a/src/composables/LayoutSugiyamaForce.ts b/src/composables/LayoutSugiyamaForce.ts index 4defdab..3d8725d 100644 --- a/src/composables/LayoutSugiyamaForce.ts +++ b/src/composables/LayoutSugiyamaForce.ts @@ -68,7 +68,7 @@ export async function vizLayout(subgraphNetwork:SubgraphNetwork,assignRank:boole await instance().then( async viz => { // attributes for viz - const sep =await getSepAttributesInches(subgraphNetwork.network.value,subgraphNetwork.networkStyle.value,factorLenghtEdge); + const sep =await getSepAttributesInches(subgraphNetwork.network,subgraphNetwork.networkStyle,factorLenghtEdge); subgraphNetwork.attributs={rankdir: "BT" , newrank:true, compound:true,splines:false,ranksep:sep.rankSep,nodesep:sep.nodeSep,dpi:dpi}; const dot=networkToDOT(subgraphNetwork,cycle,addNodes,groupOrCluster,orderChange); if(printDot) console.log(dot); diff --git a/src/composables/SubgraphForSubgraphNetwork.ts b/src/composables/SubgraphForSubgraphNetwork.ts index 1ad6b23..2f2c288 100644 --- a/src/composables/SubgraphForSubgraphNetwork.ts +++ b/src/composables/SubgraphForSubgraphNetwork.ts @@ -56,7 +56,7 @@ export function addSubgraphToNetwork(subgraphNetwork:SubgraphNetwork,subgraph:Su subgraphNetwork[type][subgraph.name]=subgraph; // node matadata update subgraph.nodes.forEach(node=>{ - updateNodeMetadataSubgraph(subgraphNetwork.network.value, node, subgraph.name, type); + updateNodeMetadataSubgraph(subgraphNetwork.network, node, subgraph.name, type); }); // if subgraph associated with another subgraph : add to associatedSubgraphs of the "parent" subgraph if (subgraph.parentSubgraph){ diff --git a/src/composables/SubgraphForViz.ts b/src/composables/SubgraphForViz.ts index 797ccd5..1732e11 100644 --- a/src/composables/SubgraphForViz.ts +++ b/src/composables/SubgraphForViz.ts @@ -84,7 +84,7 @@ export function addMainChainForViz(vizGraph: Graph, nameMainChain: string, subgr * @throws {Error} If a node is not found in the network. */ function changeCycleMetanodes(subgraphNetwork:SubgraphNetwork,listNodeBefore:string[]):string[]{ - const network=subgraphNetwork.network.value; + const network=subgraphNetwork.network; const listNodeAfter:string[]=[]; // for each nodes : listNodeBefore.forEach(node =>{ diff --git a/src/composables/__tests__/CalculateRelationCycle.tests.ts b/src/composables/__tests__/CalculateRelationCycle.tests.ts index 3a00b87..2d33809 100644 --- a/src/composables/__tests__/CalculateRelationCycle.tests.ts +++ b/src/composables/__tests__/CalculateRelationCycle.tests.ts @@ -11,7 +11,6 @@ import * as GetSetAttributsNodes from "../GetSetAttributsNodes"; // General imports -import { ref } from 'vue'; // Import the 'ref' function from the 'vue' module import { link } from 'fs'; @@ -49,8 +48,8 @@ describe('CalculateRelationCycle', () => { const networkStyle: GraphStyleProperties = {}; subgraphNetwork = { - network: ref<NetworkLayout>(network), - networkStyle: ref<GraphStyleProperties>(networkStyle), + network: network, + networkStyle: networkStyle, }; }); diff --git a/src/composables/__tests__/CalculateSize.tests.ts b/src/composables/__tests__/CalculateSize.tests.ts index f344418..c15ce78 100644 --- a/src/composables/__tests__/CalculateSize.tests.ts +++ b/src/composables/__tests__/CalculateSize.tests.ts @@ -13,7 +13,6 @@ import * as GetSetAttributsNodes from "../GetSetAttributsNodes"; import * as CalculateSize from "../CalculateSize"; // General imports -import { ref } from 'vue'; // Import the 'ref' function from the 'vue' module @@ -341,8 +340,8 @@ describe('CalculateSize', () => { // DATA const subgraphNetwork:SubgraphNetwork = { - network: ref<NetworkLayout>(network3Edges), - networkStyle: ref<GraphStyleProperties>(networkStyle) + network: network3Edges, + networkStyle: networkStyle }; const listID = ["node1","node2"] const coordinates: Coordinate[] = [ @@ -364,8 +363,8 @@ describe('CalculateSize', () => { // DATA const subgraphNetwork:SubgraphNetwork = { - network: ref<NetworkLayout>(network3Edges), - networkStyle: ref<GraphStyleProperties>(networkStyle) + network: network3Edges, + networkStyle: networkStyle }; const listID = ["node1","nodeNotNetwork"] const coordinates: Coordinate[] = [ @@ -399,8 +398,8 @@ describe('CalculateSize', () => { } }; let subgraphNetwork:SubgraphNetwork = { - network: ref<NetworkLayout>(network3Edges), - networkStyle: ref<GraphStyleProperties>(networkStyle), + network: network3Edges, + networkStyle: networkStyle, [TypeSubgraph.CYCLEGROUP]:{ "groupCycle_0": subgraph0, "groupCycle_1":subgraph1 @@ -408,8 +407,8 @@ describe('CalculateSize', () => { }; const subgraphNetworkExpected:SubgraphNetwork = { - network: ref<NetworkLayout>(network3Edges), - networkStyle: ref<GraphStyleProperties>(networkStyle), + network: network3Edges, + networkStyle: networkStyle, [TypeSubgraph.CYCLEGROUP]:{ "groupCycle_0": { ...subgraph0, diff --git a/src/types/SubgraphNetwork.ts b/src/types/SubgraphNetwork.ts index bd52a5d..59b8486 100644 --- a/src/types/SubgraphNetwork.ts +++ b/src/types/SubgraphNetwork.ts @@ -10,8 +10,8 @@ import { NetworkLayout } from "./NetworkLayout"; */ export interface SubgraphNetwork { - network: Ref<NetworkLayout>; - networkStyle: Ref<GraphStyleProperties>; + network: NetworkLayout; + networkStyle: GraphStyleProperties; stats?:{minEdgeLengthPixel?:number}; -- GitLab