sonar 9 left; Resolved as much as possible

This commit is contained in:
Cindy Chang
2024-08-08 11:40:29 +08:00
parent 335b52cc70
commit b46a6ab995

View File

@@ -7,6 +7,14 @@ import { getTimeLabel } from '@/module/timeLabel.js'; // 時間格式轉換器
import CytoscapeStore from '@/stores/cytoscapeStore'; import CytoscapeStore from '@/stores/cytoscapeStore';
import { SAVE_KEY_NAME } from '@/constants/constants.js'; import { SAVE_KEY_NAME } from '@/constants/constants.js';
const composeFreqTypeText = (baseText, dataLayerOption, optionValue) => { //sonar-qube
let text = baseText;
const textInt = dataLayerOption === 'rel_freq' ? baseText + optionValue * 100 + "%" : baseText + optionValue;
const textFloat = dataLayerOption === 'rel_freq'? baseText + (optionValue * 100).toFixed(2) + "%" : baseText + optionValue.toFixed(2);
// 判斷是否為整數,若非整數要取小數點後面兩個值。
text = Math.trunc(optionValue) === optionValue ? textInt : textFloat;
return text;
};
cytoscape.use( dagre ); cytoscape.use( dagre );
@@ -113,22 +121,15 @@ export default function cytoscapeMap(mapData, dataLayerType, dataLayerOption, cu
// 可使用 parseInt(整數) parseFloat(浮點數) 將字串轉為數字 // 可使用 parseInt(整數) parseFloat(浮點數) 將字串轉為數字
// Relative 要轉為百分比 % // Relative 要轉為百分比 %
if(node.data('type') === 'activity') { if(node.data('type') === 'activity') {
let textInt;
let textFloat;
let textDurRel; let textDurRel;
let timeLabelInt; let timeLabelInt;
let timeLabelFloat; let timeLabelFloat;
let textTimeLabel; let textTimeLabel;
switch(dataLayerType) { switch(dataLayerType) {
case 'freq': // Frequency case 'freq': // Frequency
textInt = dataLayerOption === 'rel_freq' ? text + optionValue * 100 + "%" : text + optionValue; text = composeFreqTypeText(text, dataLayerOption, optionValue);
textFloat = dataLayerOption === 'rel_freq'? text + (optionValue * 100).toFixed(2) + "%" : text + optionValue.toFixed(2);
// 判斷是否為整數,若非整數要取小數點後面兩個值。
text = Math.trunc(optionValue) === optionValue ? textInt : textFloat;
break; break;
case 'duration': // Duration 除了 Relative 為百分比 % ,其他要轉變時間單位。 case 'duration': // Duration 除了 Relative 為百分比 % ,其他要轉變時間單位。
// Relative % // Relative %
textDurRel = text + (optionValue * 100).toFixed(2) + "%"; textDurRel = text + (optionValue * 100).toFixed(2) + "%";
@@ -144,7 +145,7 @@ export default function cytoscapeMap(mapData, dataLayerType, dataLayerOption, cu
} }
} }
return text return text;
}, },
'text-opacity':0.7, 'text-opacity':0.7,
'background-color': 'data(backgroundColor)', 'background-color': 'data(backgroundColor)',