feature: cytoscape node positions are remembered

This commit is contained in:
Cindy Chang
2024-06-28 16:20:41 +08:00
parent b890df9de6
commit 2110388a2d
8 changed files with 134 additions and 19 deletions

View File

@@ -0,0 +1,469 @@
<template>
<!-- Sidebar: Switch data type -->
<div class="flex flex-col justify-between py-4 w-14 h-screen-main absolute bottom-0 left-0 z-10" :class="sidebarLeftValue? 'bg-neutral-50':''">
<ul class="space-y-4 flex flex-col justify-center items-center">
<li class="inline-flex items-center justify-center border border-neutral-500 rounded-full w-9 h-9 cursor-pointer bg-neutral-50 drop-shadow hover:border-primary" @click="sidebarView = !sidebarView" :class="{'border-primary': sidebarView}" v-tooltip="tooltip.sidebarView">
<span class="material-symbols-outlined !text-2xl hover:text-primary p-1.5" :class="[sidebarView ? 'text-primary' : 'text-neutral-500']">
track_changes
</span>
</li>
<li class="inline-flex items-center justify-center border border-neutral-500 rounded-full w-9 h-9 cursor-pointer bg-neutral-50 drop-shadow hover:border-primary" @click="sidebarFilter = !sidebarFilter" :class="{'border-primary': sidebarFilter}" v-tooltip="tooltip.sidebarFilter">
<span class="material-symbols-outlined !text-2xl hover:text-primary p-1.5" :class="[sidebarFilter ? 'text-primary' : 'text-neutral-500']" id="iconFilter">
tornado
</span>
</li>
<li class="inline-flex items-center justify-center border border-neutral-500 rounded-full w-9 h-9 cursor-pointer bg-neutral-50 drop-shadow hover:border-primary" @click="sidebarTraces = !sidebarTraces" :class="{'border-primary': sidebarTraces}" v-tooltip="tooltip.sidebarTraces">
<span class="material-symbols-outlined !text-2xl hover:text-primary p-1.5" :class="[sidebarTraces ? 'text-primary' : 'text-neutral-500']">
rebase
</span>
</li>
</ul>
<!-- <ul class="flex flex-col justify-center items-center">
<li class="inline-flex items-center justify-center border border-neutral-500 rounded-full w-9 h-9 cursor-pointer bg-neutral-50 drop-shadow hover:border-primary">
<span class="material-symbols-outlined !text-2xl text-neutral-500 hover:text-primary p-1.5">
highlight
</span>
</li>
</ul> -->
</div>
<!-- Cytoscape Map -->
<div class="min-w-full h-screen-main bg-neutral-50 -z-40">
<div id="cy" class="min-w-full h-screen-main"></div>
</div>
<!-- Sidebar: State -->
<div class="bg-transparent py-4 w-14 h-screen-main z-10 bottom-0 right-0 absolute">
<ul class="flex flex-col justify-center items-center">
<li class="inline-flex items-center justify-center border border-neutral-500 rounded-full w-9 h-9 cursor-pointer bg-neutral-50 drop-shadow hover:border-primary" @click="sidebarState = !sidebarState" :class="{'border-primary': sidebarState}" id="iconState" v-tooltip.left="tooltip.sidebarState">
<span class="material-symbols-outlined !text-2xl text-neutral-500 hover:text-primary p-1.5" :class="[sidebarState ? 'text-primary' : 'text-neutral-500']">
info
</span>
</li>
</ul>
</div>
<!-- Sidebar Model -->
<SidebarView v-model:visible="sidebarView" @switch-map-type="switchMapType" @switch-curve-styles="switchCurveStyles" @switch-rank="switchRank" @switch-data-layer-type="switchDataLayerType" ></SidebarView>
<SidebarState v-model:visible="sidebarState" :insights="insights" :stats="stats"></SidebarState>
<SidebarTraces v-model:visible="sidebarTraces" :cases="cases" @switch-Trace-Id="switchTraceId" ref="tracesView"></SidebarTraces>
<SidebarFilter v-model:visible="sidebarFilter" :filterTasks="filterTasks" :filterStartToEnd="filterStartToEnd" :filterEndToStart="filterEndToStart" :filterTimeframe="filterTimeframe" :filterTrace="filterTrace"
@submit-all="createCy(mapType)" @switch-Trace-Id="switchTraceId" ref="sidevarFilterRef"></SidebarFilter>
</template>
<script>
import { onBeforeMount, } from 'vue';
import { storeToRefs } from 'pinia';
import axios from 'axios';
import LoadingStore from '@/stores/loading.js';
import AllMapDataStore from '@/stores/allMapData.js';
import ConformanceStore from '@/stores/conformance.js';
import cytoscapeMap from '@/module/cytoscapeMap.js';
import CytoscapeStore from '@/stores/cytoscapeStore.js';
import SidebarView from '@/components/Discover/Map/SidebarView.vue';
import SidebarState from '@/components/Discover/Map/SidebarState.vue';
import SidebarTraces from '@/components/Discover/Map/SidebarTraces.vue';
import SidebarFilter from '@/components/Discover/Map/SidebarFilter.vue';
export default {
setup() {
const loadingStore = LoadingStore();
const allMapDataStore = AllMapDataStore();
const { isLoading } = storeToRefs(loadingStore);
const { processMap, bpmn, stats, insights, traceId, traces, baseTraces, baseTraceId,
filterTasks, filterStartToEnd, filterEndToStart, filterTimeframe, filterTrace,
temporaryData, isRuleData, ruleData, logId, baseLogId, createFilterId, cases,
postRuleData
} = storeToRefs(allMapDataStore);
const cytoscapeStore = CytoscapeStore();
const { setCurrentGraphId } = cytoscapeStore;
onBeforeMount(() => {
setCurrentGraphId(logId);
});
return { isLoading, processMap, bpmn, stats, insights, traceId, traces, baseTraces,
baseTraceId, filterTasks, filterStartToEnd, filterEndToStart, filterTimeframe,
filterTrace, logId, baseLogId, createFilterId, temporaryData, isRuleData,
ruleData, allMapDataStore, cases, postRuleData,
setCurrentGraphId,
};
},
props:['type', 'checkType', 'checkId', 'checkFileId'], // 來自 router 的 props
components: {
SidebarView,
SidebarState,
SidebarTraces,
SidebarFilter,
},
data() {
return {
processMapData: {
startId: 0,
endId: 1,
nodes: [],
edges: [],
},
bpmnData: {
startId: 0,
endId: 1,
nodes: [],
edges: [],
},
cytoscapeGraph: null,
curveStyle:'unbundled-bezier', // unbundled-bezier | taxi
mapType: 'processMap', // processMap | bpmn
dataLayerType: 'freq', // freq | duration
dataLayerOption: 'total',
rank: 'LR', // 直向 TB | 橫向 LR
traceId: 1,
sidebarView: false, // SideBar: Visualization Setting
sidebarState: false, // SideBar: Summary & Insight
sidebarTraces: false, // SideBar: Traces
sidebarFilter: false, // SideBar: Filter
infiniteFirstCases: null,
tooltip: {
sidebarView: {
value: 'Visualization Setting',
class: 'ml-1',
pt: {
text: 'text-[10px] p-1'
}
},
sidebarTraces: {
value: 'Trace',
class: 'ml-1',
pt: {
text: 'text-[10px] p-1'
}
},
sidebarFilter: {
value: 'Filter',
class: 'ml-1',
pt: {
text: 'text-[10px] p-1'
}
},
sidebarState: {
value: 'Summary',
class: 'ml-1',
pt: {
text: 'text-[10px] p-1'
}
},
}
}
},
computed:{
sidebarLeftValue: function() {
let result = this.sidebarView === true || this.sidebarTraces === true || this.sidebarFilter === true;
return result;
}
},
watch: {
sidebarView: function(newValue) {
if(newValue) {
this.sidebarFilter = false;
this.sidebarTraces = false;
}
},
sidebarFilter: function(newValue) {
if(newValue) {
this.sidebarView = false;
this.sidebarState = false;
this.sidebarTraces = false;
this.sidebarState = false;
}
},
sidebarTraces: function(newValue) {
if(newValue) {
this.sidebarView = false;
this.sidebarState = false;
this.sidebarFilter = false;
this.sidebarState = false;
}
},
sidebarState: function(newValue) {
if(newValue) {
this.sidebarFilter = false;
this.sidebarTraces = false;
}
},
},
methods: {
/**
* switch map type
* @param {string} type 'processMap' | 'bpmn',可傳入以上任一。
*/
switchMapType(type) {
this.mapType = type;
this.createCy(type);
},
/**
* switch curve style
* @param {string} style 直角 'unbundled-bezier' | 'taxi',可傳入以上任一。
*/
switchCurveStyles(style) {
this.curveStyle = style;
this.createCy(this.mapType);
},
/**
* switch rank
* @param {string} rank 直向 'TB' | 橫向 'LR',可傳入以上任一。
*/
switchRank(rank) {
this.rank = rank;
this.createCy(this.mapType);
},
/**
* switch Data Layoer Type or Option.
* @param {string} type freq | duration
* @param {string} option 下拉選單中的選項
*/
switchDataLayerType(type, option){
this.dataLayerType = type;
this.dataLayerOption = option;
this.createCy(this.mapType);
},
/**
* switch trace id and data
* @param {event} e input 傳入的事件
*/
async switchTraceId(e) {
if(e.id == this.traceId) return;
// if(e.count >= 1000) this.isLoading = true; // 超過 1000 筆要 loading 畫面
this.isLoading = true; // 都要 loading 畫面
this.traceId = e.id;
await this.allMapDataStore.getTraceDetail();
this.$refs.tracesView.createCy();
this.isLoading = false;
},
/**
* 將 element nodes 資料彙整
* @param {object} type 'processMapData' | 'bpmnData',可傳入以上任一。
*/
setNodesData(mapData) {
let mapType = this.mapType;
const logFreq = {
"total": "",
"rel_freq": "",
"average": "",
"median": "",
"max": "",
"min": "",
"cases": ""
};
const logDuration = {
"total": "",
"rel_duration": "",
"average": "",
"median": "",
"max": "",
"min": "",
};
// BPMN 才有 gateway 類別
const gateway = {
parallel: "+",
exclusive: "x",
inclusive: "o",
};
// 避免每次渲染都重複累加
mapData.nodes = [];
// 將 api call 回來的資料帶進 node
this[mapType].vertices.forEach(node => {
switch (node.type) {
// add type of 'bpmn gateway' node
case 'gateway':
mapData.nodes.push({
data:{
id:node.id,
type:node.type,
label:gateway[node.gateway_type],
height:60,
width:60,
backgroundColor:'#FFF',
bordercolor:'#003366',
shape:"diamond",
freq:logFreq,
duration:logDuration,
}
})
break;
// add type of 'event' node
case 'event':
if(node.event_type === 'start') mapData.startId = node.id;
else if(node.event_type === 'end') mapData.endId = node.id;
mapData.nodes.push({
data:{
id:node.id,
type:node.type,
label:node.event_type,
height:60,
width:60,
backgroundColor:'#FFCCCC',
bordercolor:'#003366',
shape:"ellipse",
freq:logFreq,
duration:logDuration,
}
});
break;
// add type of 'activity' node
default:
mapData.nodes.push({
data:{
id:node.id,
type:node.type,
label:node.label,
height:80,
width:100,
backgroundColor:'#FFCCCC',
bordercolor:'#003366',
shape:"round-rectangle",
freq:node.freq,
duration:node.duration,
}
})
break;
}
});
},
/**
* 將 element edges 資料彙整
* @param {object} type 'processMapData' | 'bpmnData',可傳入以上任一。
*/
setEdgesData(mapData) {
let mapType = this.mapType;
//add event duration is empty
const logDuration = {
"total": "",
"rel_duration": "",
"average": "",
"median": "",
"max": "",
"min": "",
"cases": ""
};
mapData.edges = [];
this[mapType].edges.map(edge => {
mapData.edges.push({
data: {
source:edge.tail,
target:edge.head,
freq:edge.freq,
duration:edge.duration === null ? logDuration : edge.duration,
style:'dotted',
lineWidth:1,
},
});
});
},
/**
* create cytoscape's map
* @param {string} type this.mapType 'processMap' | 'bpmn',可傳入以上任一。
*/
createCy(type) {
let graphId = document.getElementById('cy');
let mapData = type === 'processMap'? this.processMapData: this.bpmnData;
if(this[type].vertices.length !== 0){
this.setNodesData(mapData);
this.setEdgesData(mapData);
this.cytoscapeGraph = cytoscapeMap(mapData, this.dataLayerType, this.dataLayerOption, this.curveStyle, this.rank, graphId);
};
},
},
async created() {
const routeParams = this.$route.params;
const file = this.$route.meta.file;
const isCheckPage = this.$route.name.includes('Check');
// 先 loading 再執行以下程式
this.isLoading = true;
// Log 檔前往 Map Log 頁, Filter 檔前往 Map Filter 頁
switch (routeParams.type) {
case 'log':
if(!isCheckPage) {
this.logId = await routeParams.fileId;
this.baseLogId = await routeParams.fileId;
} else {
this.logId = await file.parent.id;
this.baseLogId = await file.parent.id;
}
break;
case 'filter':
if(!isCheckPage) {
this.createFilterId = await routeParams.fileId;
} else {
this.createFilterId = await file.parent.id;
}
// 取得 logID 和上次儲存的 Funnel
await this.allMapDataStore.fetchFunnel(this.createFilterId);
this.isRuleData = await Array.from(this.temporaryData);
this.ruleData = await this.isRuleData.map(e => this.$refs.sidevarFilterRef.setRule(e));
break;
}
// 取得 logId 後才 call api
await this.allMapDataStore.getAllMapData();
await this.allMapDataStore.getAllTrace();
// log、filter 檔切換過程中, trace id 不同,將初始 trace id 設定為該檔案的 trace 幣一筆資料的 id。
this.traceId = await this.traces[0]?.id;
this.baseTraceId = await this.baseTraces[0]?.id;
this.createCy(this.mapType);
await this.allMapDataStore.getFilterParams();
await this.allMapDataStore.getTraceDetail();
// 執行完後才取消 loading
this.isLoading = false;
// 存檔 Modal 打開時,側邊欄要關閉
this.$emitter.on('saveModal', boolean => {
this.sidebarView = boolean;
this.sidebarFilter = boolean;
this.sidebarTraces = boolean;
this.sidebarState = boolean;
});
this.$emitter.on('leaveFilter', boolean => {
this.sidebarView = boolean;
this.sidebarFilter = boolean;
this.sidebarTraces = boolean;
this.sidebarState = boolean;
});
},
beforeUnmount() {
this.logId = null;
this.createFilterId = null;
this.tempFilterId = null;
this.temporaryData = [];
this.postRuleData = [];
this.ruleData = [];
},
async beforeRouteEnter(to, from, next) {
const isCheckPage = to.name.includes('Check');
if (isCheckPage) {
const conformanceStore = ConformanceStore();
// Save token in Headers.
const token = document.cookie.replace(/(?:(?:^|.*;\s*)luciaToken\s*\=\s*([^;]*).*$)|^.*$/, "$1");
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
switch (to.params.type) {
case 'log':
conformanceStore.conformanceLogCreateCheckId = to.params.fileId;
break;
case 'filter':
conformanceStore.conformanceFilterCreateCheckId = to.params.fileId;
break;
}
await conformanceStore.getConformanceReport(true);
to.meta.file = conformanceStore.routeFile; // 將 file data 存到 route
}
next();
}
}
</script>