sometimes highlightMostFrequentPath works

This commit is contained in:
Cindy Chang
2024-08-27 16:03:01 +08:00
parent 3f993741c8
commit 554411ace1
2 changed files with 14 additions and 11 deletions

View File

@@ -31,16 +31,15 @@ export default defineStore('useMapPathStore', {
setCytoscape(cytoscape) { setCytoscape(cytoscape) {
this.cytoscape = cytoscape; this.cytoscape = cytoscape;
}, },
createAllPaths() { async createPaths() {
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 // Depth First Search from the starting node
this.depthFirstSearchCreatePath(this.startNode, [this.startNode], []); await this.depthFirstSearchCreatePath(this.startNode, [this.startNode], []);
const { insights } = AllMapData(); const { insights } = AllMapData();
this.insights = {...insights}; this.insights = {...insights};
this.matchGraphPathWithInsightsPath(); await this.matchGraphPathWithInsightsPath();
this.highlightMostFrequentPath();
}, },
/** 從start節點開始建立所有的path /** 從start節點開始建立所有的path
* 於第二個參數逐漸推入節點,於第三個參數逐漸推入線段 * 於第二個參數逐漸推入節點,於第三個參數逐漸推入線段
@@ -102,10 +101,10 @@ export default defineStore('useMapPathStore', {
}, },
depthFirstSearchMatchTwoPaths(curPath, curPathIndex, curButton, listIndex, nodeIndex){ depthFirstSearchMatchTwoPaths(curPath, curPathIndex, curButton, listIndex, nodeIndex){
if(listIndex >= curButton.length) { // 邊界條件檢查,防止超出範圍 if(listIndex >= curButton.length) { // 邊界條件檢查,防止超出範圍
return; return; // nodeIndex表示是當選訂了五顆按鈕之一之後清單上的第幾個path
} }
if(nodeIndex >= curButton[listIndex]) { // 邊界條件檢查,防止超出範圍 if(nodeIndex >= curButton[listIndex]) { // 邊界條件檢查,防止超出範圍
return; return; // 表示清單上這個path上的第幾個節點
} }
// 如果 `curPath` 和 `curButton[listIndex]` 完全匹配 // 如果 `curPath` 和 `curButton[listIndex]` 完全匹配
if (curPathIndex === curPath.length || nodeIndex === curButton[listIndex].length) { if (curPathIndex === curPath.length || nodeIndex === curButton[listIndex].length) {
@@ -152,7 +151,7 @@ export default defineStore('useMapPathStore', {
this.cytoscape?.nodes().removeClass('highlight-node'); this.cytoscape?.nodes().removeClass('highlight-node');
this.cytoscape?.nodes().forEach(nodeToReset => { this.cytoscape?.nodes().forEach(nodeToReset => {
nodeToReset.data('nodeImageUrl', ImgCapsules[nodeToReset.data('level')]) nodeToReset.data('nodeImageUrl', ImgCapsules[nodeToReset.data('level')])
}) });
}, },
onNodeClickHighlightEdges(clickedNode) { onNodeClickHighlightEdges(clickedNode) {
this.clearAllHighlight(); this.clearAllHighlight();
@@ -183,11 +182,14 @@ export default defineStore('useMapPathStore', {
const keyLength = Object.keys(this.mapGraphPathToInsight[whichPath]).length; const keyLength = Object.keys(this.mapGraphPathToInsight[whichPath]).length;
for(let i = 0; i < keyLength; i++) { for(let i = 0; i < keyLength; i++) {
if(this.mapGraphPathToInsight[whichPath][i]?.pathType === 'most_freq_traces'){ if(this.mapGraphPathToInsight[whichPath][i]?.pathType === 'most_freq_traces'){
this.mapGraphPathToInsight[whichPath][i].pathByNode.forEach(nodeToHighlight => { console.log('found', );
this.mapGraphPathToInsight[whichPath][i].pathByNode.map(nodeToHighlight => {
nodeToHighlight.data('nodeImageUrl', ImgCapsulesGlow[nodeToHighlight.data('level')]); nodeToHighlight.data('nodeImageUrl', ImgCapsulesGlow[nodeToHighlight.data('level')]);
}); });
this.mapGraphPathToInsight[whichPath][i].pathByEdge.forEach( this.mapGraphPathToInsight[whichPath][i].pathByEdge.map(
edgeToHighlight => edgeToHighlight.addClass('highlight-edge')); edgeToHighlight => {
edgeToHighlight.addClass('highlight-edge');
});
return; // 之所以要此時就立刻return是因為要避免第二個以上的most freq path也被點亮 return; // 之所以要此時就立刻return是因為要避免第二個以上的most freq path也被點亮
} }
break; break;

View File

@@ -486,7 +486,8 @@ export default {
this.baseTraceId = await this.baseTraces[0]?.id; this.baseTraceId = await this.baseTraces[0]?.id;
this.createCy(this.mapType); this.createCy(this.mapType);
await mapPathStore.setCytoscape(this.cytoscapeGraph); await mapPathStore.setCytoscape(this.cytoscapeGraph);
await mapPathStore.createAllPaths(); await mapPathStore.createPaths();
await mapPathStore.highlightMostFrequentPath();
await this.allMapDataStore.getFilterParams(); await this.allMapDataStore.getFilterParams();
await this.allMapDataStore.getTraceDetail(); await this.allMapDataStore.getTraceDetail();