WIP: matchGraphPathWithInsightsPath
This commit is contained in:
@@ -1,54 +1,79 @@
|
|||||||
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,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setCytoscape(cytoscape) {
|
setCytoscape(cytoscape) {
|
||||||
this.cytoscape = cytoscape;
|
this.cytoscape = cytoscape;
|
||||||
},
|
},
|
||||||
createAllPaths() {
|
createAllPaths() {
|
||||||
this.startNode = this.cytoscape.nodes().filter(function(elem) {
|
this.startNode = this.cytoscape.nodes().filter(function(elem) {
|
||||||
return elem.data('label').toLocaleLowerCase() === 'start';
|
return elem.data('label').toLocaleLowerCase() === 'start';
|
||||||
|
});
|
||||||
|
// Depth First Search from the starting node
|
||||||
|
this.depthFirstSearchCreatePath(this.startNode, [this.startNode.id()]);
|
||||||
|
const { insights } = this.allMapData;
|
||||||
|
this.insights = insights;
|
||||||
|
// this.matchGraphPathWithInsightsPath();
|
||||||
|
for(let i = 0; i < INSIGHTS_FIELDS_AND_LABELS.length; i++) {
|
||||||
|
const curButton = insights[INSIGHTS_FIELDS_AND_LABELS[i][0]];
|
||||||
|
for(let listIndex = 0; listIndex < curButton.length; listIndex++) {
|
||||||
|
for(let nodeIndex = 0; nodeIndex < curButton[listIndex].length; nodeIndex++){
|
||||||
|
//curButton[listIndex][nodeIndex]', curButton[listIndex][nodeIndex]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** 從start節點開始建立所有的path
|
||||||
|
*/
|
||||||
|
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)) {
|
||||||
|
// 避免loop,只有當目標節點不在當前路徑中之時才繼續
|
||||||
|
this.depthFirstSearchCreatePath(targetNode, [...currentPath, targetNode]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// Depth First Search from the starting node
|
}
|
||||||
this.depthFirstSearchCreatePath(this.startNode, [this.startNode.id()]);
|
},
|
||||||
this.allPaths.forEach(path => {
|
/**
|
||||||
console.log('path',path );
|
* 在每條path沿路據節點上的label之
|
||||||
});
|
* 字串來匹配這個path是屬於insights物件的哪一條path,
|
||||||
const { insights } = this.allMapData;
|
* 其中用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++) {
|
for(let i = 0; i < INSIGHTS_FIELDS_AND_LABELS.length; i++) {
|
||||||
const curButton = insights[INSIGHTS_FIELDS_AND_LABELS[i][0]];
|
const curButton = this.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) {
|
// 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;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
depthFirstSearchCreatePath(node, currentPath){
|
},
|
||||||
const outgoingEdges = node.outgoers('edge');
|
depthFirstSearchMatchTwoPaths(){
|
||||||
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()]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user