fix: Issues #222 done.
This commit is contained in:
@@ -184,7 +184,7 @@ import ConformanceStore from '@/stores/conformance.js';
|
||||
import iconNA from '@/components/icons/IconNA.vue';
|
||||
import MoreModal from './MoreModal.vue';
|
||||
import getNumberLabel from '@/module/numberLabel.js';
|
||||
import { setLineChartData, setBarChartData, timeRange, yTimeRange, getXIndex, formatTime } from '@/module/setChartData.js';
|
||||
import { setLineChartData, setBarChartData, timeRange, yTimeRange, getXIndex, formatTime, formatMaxTwo } from '@/module/setChartData.js';
|
||||
import shortScaleNumber from '@/module/shortScaleNumber.js';
|
||||
import getMoment from 'moment';
|
||||
|
||||
@@ -617,6 +617,7 @@ export default {
|
||||
let yVal = yTimeRange(data, 100, yMin, yMax);
|
||||
data = xVal.map((x, index) => ({ x, y: yVal[index] }));
|
||||
let formattedXVal = xVal.map(value => formatTime(value));
|
||||
formattedXVal = formatMaxTwo(formattedXVal);
|
||||
let selectTimeMinIndex = getXIndex(xVal, this.selectDurationTime.min);
|
||||
let selectTimeMaxIndex = getXIndex(xVal, this.selectDurationTime.max);
|
||||
const start = selectTimeMinIndex;
|
||||
@@ -624,6 +625,8 @@ export default {
|
||||
const inside = (ctx, value) => ctx.p0DataIndex >= start && ctx.p1DataIndex <= end ? value : undefined;
|
||||
const outside = (ctx, value) => ctx.p0DataIndex < start || ctx.p1DataIndex > end ? value : undefined;
|
||||
|
||||
// console.log(formattedXVal);
|
||||
|
||||
this.timeChartData = {
|
||||
labels: formattedXVal,
|
||||
datasets: [
|
||||
|
||||
@@ -179,3 +179,27 @@ export function formatTime(seconds) {
|
||||
return result.trim(); // 去除最后一个空格
|
||||
} else return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {array} times
|
||||
* @returns {array}
|
||||
*/
|
||||
export function formatMaxTwo(times) {
|
||||
const formattedTimes = [];
|
||||
for (let time of times) {
|
||||
let units = time.match(/\d+[dhms]/g); // 匹配數字和單位(天、小時、分鐘、秒)
|
||||
let formattedTime = '';
|
||||
let count = 0;
|
||||
|
||||
// 只保留最大的兩個單位
|
||||
for (let unit of units) {
|
||||
if (count >= 2) {
|
||||
break;
|
||||
}
|
||||
formattedTime += unit + ' ';
|
||||
count++;
|
||||
}
|
||||
formattedTimes.push(formattedTime.trim()); // 去除末尾的空格
|
||||
}
|
||||
return formattedTimes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user