This commit is contained in:
Cindy Chang
2024-08-19 17:07:56 +08:00
parent 2de9a2b3e6
commit 9b7b382962

View File

@@ -8,27 +8,47 @@ export default defineStore('useMapPathStore', {
clickedPath: [], clickedPath: [],
allMapData: AllMapData(), allMapData: AllMapData(),
cytoscape: null, cytoscape: null,
allPaths: [],
startNode: null,
}), }),
actions: { actions: {
setCytoscape(cytoscape) { setCytoscape(cytoscape) {
this.cytoscape = cytoscape; this.cytoscape = cytoscape;
}, },
createAllPaths() { createAllPaths() {
this.startNode = this.cytoscape.nodes().filter(function(elem) {
return elem.data('label').toLocaleLowerCase() === 'start';
});
// Depth First Search from the starting node
this.depthFirstSearchCreatePath(this.startNode, [this.startNode.id()]);
this.allPaths.forEach(path => {
console.log('path',path );
});
const { insights } = this.allMapData; const { insights } = this.allMapData;
for(let i = 0; i < INSIGHTS_FIELDS_AND_LABELS.length; i++) { for(let i = 0; i < INSIGHTS_FIELDS_AND_LABELS.length; i++) {
const curButton = insights[INSIGHTS_FIELDS_AND_LABELS[i][0]]; const curButton = insights[INSIGHTS_FIELDS_AND_LABELS[i][0]];
for(let listIndex = 0; listIndex < curButton.length; listIndex++) { for(let listIndex = 0; listIndex < curButton.length; listIndex++) {
for(let nodeIndex = 0; nodeIndex < curButton[listIndex].length; nodeIndex++){ for(let nodeIndex = 0; nodeIndex < curButton[listIndex].length; nodeIndex++){
if(nodeIndex === 0) { if(nodeIndex === 0) {
const startNodes = this.cytoscape.nodes().filter(function(elem) {
return elem.data('label').toLocaleLowerCase() === 'start';
// highlight between start node and first node
});
} }
} }
} }
} }
}, },
depthFirstSearchCreatePath(node, currentPath){
const outgoingEdges = node.outgoers('edge');
if (outgoingEdges.length === 0) {
this.allPaths.push([...currentPath]);
} else {
outgoingEdges.targets().forEach((targetNode) => {
if (!currentPath.includes(targetNode.id())) {
// 避免loop只有當目標節點不在當前路徑中之時才繼續
this.depthFirstSearchCreatePath(targetNode, [...currentPath, targetNode.id()]);
}
});
}
},
}, },
}); });