WIP: level capsule. However, one capsule is failed

This commit is contained in:
Cindy Chang
2024-08-15 14:26:08 +08:00
parent 9a7442b4ef
commit 305771ce5a

View File

@@ -72,6 +72,8 @@ import ImgCapsule2 from '@/assets/capsule2.svg';
import ImgCapsule3 from '@/assets/capsule3.svg';
import ImgCapsule4 from '@/assets/capsule4.svg';
const ImgCapsules = [ImgCapsule1, ImgCapsule2, ImgCapsule3, ImgCapsule4];
export default {
setup() {
const loadingStore = LoadingStore();
@@ -351,7 +353,6 @@ export default {
shape:"round-rectangle",
freq:node.freq,
duration:node.duration,
nodeImageUrl: ImgCapsule1,
backgroundOpacity: 0,
borderOpacity: 0,
}
@@ -402,9 +403,39 @@ export default {
if(this[type].vertices.length !== 0){
this.setNodesData(mapData);
this.setEdgesData(mapData);
this.setActivityBgImage(mapData);
this.cytoscapeGraph = cytoscapeMap(mapData, this.dataLayerType, this.dataLayerOption, this.curveStyle, this.rank, graphId);
};
},
setActivityBgImage(mapData) {
const nodes = mapData.nodes;
const groupSize = Math.floor(nodes.length / ImgCapsules.length);
let nodeOptionArr = [];
const leveledGroups = []; // 每一個level會使用不同的膠囊圖片
// 設定除了 start, end 的 node 顏色
// 找出 type activity's node
const activityNodeArray = nodes.filter(node => node.data.type === 'activity');
// 找出除了 start, end 以外所有的 node 的 option value
activityNodeArray.map(node => nodeOptionArr.push(node.data[this.dataLayerType][this.dataLayerOption]));
// 刪掉重複的元素將node的option值從小到大排序(映對色階淺到深)
nodeOptionArr = [...new Set(nodeOptionArr)].sort((a, b) => a - b);
for(let i = 0; i < ImgCapsules.length; i++) {
const startIdx = i * groupSize;
const endIdx = (i === ImgCapsules.length - 1) ? activityNodeArray.length : startIdx + groupSize;
leveledGroups.push(nodeOptionArr.slice(startIdx, endIdx));
}
for(let level = 0; level < leveledGroups.length; level++) {
leveledGroups[level].map(option => {
const curNode = activityNodeArray.find(activityNode => activityNode.data[this.dataLayerType][this.dataLayerOption] === option);
curNode.data = {
...curNode.data,
nodeImageUrl: ImgCapsules[level],
}
})
}
},
},
async created() {
const routeParams = this.$route.params;