WIP: matchGraphPathWithInsightsPath

This commit is contained in:
Cindy Chang
2024-08-21 10:00:05 +08:00
parent 9b7b382962
commit fbed897d52

View File

@@ -1,12 +1,12 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import AllMapData from '@/stores/allMapData.js'; import AllMapData from '@/stores/allMapData.js';
import { INSIGHTS_FIELDS_AND_LABELS } from '@/constants/constants'; import { INSIGHTS_FIELDS_AND_LABELS } from '@/constants/constants';
import { elements } from 'chart.js';
export default defineStore('useMapPathStore', { export default defineStore('useMapPathStore', {
state: () => ({ state: () => ({
clickedPath: [], clickedPath: [],
allMapData: AllMapData(), allMapData: AllMapData(),
insights: [],
cytoscape: null, cytoscape: null,
allPaths: [], allPaths: [],
startNode: null, startNode: null,
@@ -21,34 +21,59 @@ export default defineStore('useMapPathStore', {
}); });
// Depth First Search from the starting node // Depth First Search from the starting node
this.depthFirstSearchCreatePath(this.startNode, [this.startNode.id()]); this.depthFirstSearchCreatePath(this.startNode, [this.startNode.id()]);
this.allPaths.forEach(path => {
console.log('path',path );
});
const { insights } = this.allMapData; const { insights } = this.allMapData;
this.insights = insights;
// this.matchGraphPathWithInsightsPath();
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) { //curButton[listIndex][nodeIndex]', curButton[listIndex][nodeIndex]
}
} }
} }
} }
}, },
/** 從start節點開始建立所有的path
*/
depthFirstSearchCreatePath(node, currentPath){ depthFirstSearchCreatePath(node, currentPath){
const outgoingEdges = node.outgoers('edge'); const outgoingEdges = node.outgoers('edge');
if (outgoingEdges.length === 0) { if (outgoingEdges.length === 0) {
this.allPaths.push([...currentPath]); this.allPaths.push([...currentPath]);
} else { } else {
outgoingEdges.targets().forEach((targetNode) => { outgoingEdges.targets().forEach((targetNode) => {
if (!currentPath.includes(targetNode.id())) { if (!currentPath.includes(targetNode)) {
// 避免loop只有當目標節點不在當前路徑中之時才繼續 // 避免loop只有當目標節點不在當前路徑中之時才繼續
this.depthFirstSearchCreatePath(targetNode, [...currentPath, targetNode.id()]); this.depthFirstSearchCreatePath(targetNode, [...currentPath, targetNode]);
} }
}); });
} }
}, },
/**
* 在每條path沿路據節點上的label之
* 字串來匹配這個path是屬於insights物件的哪一條path
* 其中用curButton去接住insights[INSIGHTS_FIELDS_AND_LABELS[i][0]]
* 而curButton[listIndex][nodeIndex]是用來確認是否跟depthFirstSearchCreatePath內的
* node.data('label')字串完全相等
*/
matchGraphPathWithInsightsPath(){
for(let pathIndex = 0; pathIndex < this.allPaths.length; pathIndex++) {
const curPath = this.allPaths[pathIndex];
for(let i = 0; i < INSIGHTS_FIELDS_AND_LABELS.length; i++) {
const curButton = this.insights[INSIGHTS_FIELDS_AND_LABELS[i][0]];
for(let listIndex = 0; listIndex < curButton.length; listIndex++) {
for(let nodeIndex = 0; nodeIndex < curButton[listIndex].length; nodeIndex++){
// console.log(curPath[0].data('label'));
// if(curPath[0].data('label') === curButton[listIndex][nodeIndex]){
// console.log('MATCH curPath[0].data(label)', curPath[0].data('label'));
// break;
// }
}
}
}
}
},
depthFirstSearchMatchTwoPaths(){
},
}, },
}); });