fix: #302. Shouldn't use mod and shouldn't double divide.

This commit is contained in:
Cindy Chang
2024-06-17 23:03:46 +08:00
parent cee61dbd93
commit 9b88de4c3f
3 changed files with 18 additions and 19 deletions

View File

@@ -39,13 +39,12 @@ const getTimeUnitAndValueToUse = (secondToDecide) => {
timeValue: secondToDecide / hour, timeValue: secondToDecide / hour,
}; };
} else if (mm > 0 && mm > 1) { } else if (mm > 0 && mm > 1) {
console.log('mm > 0 && mm > 1', secondToDecide / minutes);
return { return {
unitToUse: "m", unitToUse: "m",
timeValue: secondToDecide / minutes, timeValue: secondToDecide / minutes,
}; };
} else { } else {
console.log('less than one minutes final case timeValue:', secondToDecide, dd, hh, mm); //TODO: console.log('less than one minutes final case timeValue:', secondToDecide, dd, hh, mm);
return { return {
unitToUse: "s", unitToUse: "s",
timeValue: secondToDecide, timeValue: secondToDecide,
@@ -161,16 +160,16 @@ export function followTimeLabel(second, max, fixedNumber = 0) {
const minutes = 60; const minutes = 60;
const dd = max / day; const dd = max / day;
const hh = (max % day) / hour; const hh = max / hour;
const mm = (max % hour) / minutes; const mm = max/ minutes;
let maxUnit = ''; let maxUnit = '';
let result = ""; let result = "";
if (dd > 0) { if (dd > 1) {
maxUnit = 'd'; maxUnit = 'd';
} else if (hh > 0) { } else if (hh > 1) {
maxUnit = 'h'; maxUnit = 'h';
} else if (mm > 0) { } else if (mm > 1) {
maxUnit = 'm'; maxUnit = 'm';
} else { } else {
maxUnit = 's'; maxUnit = 's';
@@ -186,13 +185,13 @@ export function followTimeLabel(second, max, fixedNumber = 0) {
if(((second % day) / hour) === 0) { if(((second % day) / hour) === 0) {
fixedNumber = 0; fixedNumber = 0;
} }
result = ((second % day) / hour).toFixed(fixedNumber) + 'h'; result = (second / hour).toFixed(fixedNumber) + 'h';
break; break;
case 'm': case 'm':
if(((second % hour) / minutes) === 0) { if((second / minutes) === 0) {
fixedNumber = 0; fixedNumber = 0;
} }
result = ((second % hour) / minutes).toFixed(fixedNumber) + 'm'; result = (second / minutes).toFixed(fixedNumber) + 'm';
break; break;
case 's': case 's':
if(second === 0) { if(second === 0) {
@@ -211,7 +210,7 @@ export function followTimeLabel(second, max, fixedNumber = 0) {
* @param { string } maxX 該 data 最大的日期,格式是 timestamp * @param { string } maxX 該 data 最大的日期,格式是 timestamp
* @param { string } minX 該 data 最小的日期,格式是 timestamp * @param { string } minX 該 data 最小的日期,格式是 timestamp
*/ */
export function dateLabel(date, maxDate, minDate) { export function getDateLabelByMinMaxDate(date, maxDate, minDate) {
// 將時間字串轉換為時間物件 // 將時間字串轉換為時間物件
// new Date(time) 之後不用 getTime()因為在JavaScript中 // new Date(time) 之後不用 getTime()因為在JavaScript中
// 日期物件是以時間戳記timestamp的形式存儲的。當創建一個新的日期物件時 // 日期物件是以時間戳記timestamp的形式存儲的。當創建一個新的日期物件時
@@ -238,16 +237,16 @@ export function dateLabel(date, maxDate, minDate) {
const diffSeconds = Math.floor(timeDiff); const diffSeconds = Math.floor(timeDiff);
// 顯示結果 // 顯示結果
if (diffMonths > 0) { if (diffMonths > 1) {
return moment(date).format('YYYY/MM/DD'); return moment(date).format('YYYY/MM/DD');
} }
else if (diffDays > 0) { else if (diffDays > 1) {
return moment(date).format('MM/DD'); return moment(date).format('MM/DD');
} }
else if (diffHours > 0) { else if (diffHours > 1) {
return moment(date).format('MM/DD hh:00'); return moment(date).format('MM/DD hh:00');
} }
else if (diffMinutes > 0) { else if (diffMinutes > 1) {
return moment(date).format('MM/DD hh:mm'); return moment(date).format('MM/DD hh:mm');
} }
else { else {

View File

@@ -158,7 +158,7 @@ import LoadingStore from '@/stores/loading.js';
import CompareStore from '@/stores/compare.js'; import CompareStore from '@/stores/compare.js';
import SidebarStates from '@/components/Compare/SidebarStates.vue'; import SidebarStates from '@/components/Compare/SidebarStates.vue';
import { setLineChartData } from '@/module/setChartData.js'; import { setLineChartData } from '@/module/setChartData.js';
import { simpleTimeLabel, followTimeLabel, dateLabel, import { simpleTimeLabel, followTimeLabel, getDateLabelByMinMaxDate,
setTimeStringFormatBaseOnTimeDifference, setTimeStringFormatBaseOnTimeDifference,
mapTimestampToAxisTicksByFormat, mapTimestampToAxisTicksByFormat,
getStepSizeOfYTicks, getStepSizeOfYTicks,
@@ -438,7 +438,7 @@ export default {
const maxX = chartData.x_axis.max; const maxX = chartData.x_axis.max;
const minX = chartData.x_axis.min; const minX = chartData.x_axis.min;
const getMoment = (time)=> this.$moment(time).format('YYYY/M/D hh:mm:ss'); const getMoment = (time)=> this.$moment(time).format('YYYY/M/D hh:mm:ss');
const getDateLabel = dateLabel; const getDateLabel = getDateLabelByMinMaxDate;
let datasetsPrimary = chartData.data[0].data; let datasetsPrimary = chartData.data[0].data;
let xDataPrimary; let xDataPrimary;
let yDataPrimary; let yDataPrimary;

View File

@@ -146,7 +146,7 @@ import PerformanceStore from '@/stores/performance.js';
import ConformanceStore from '@/stores/conformance.js'; import ConformanceStore from '@/stores/conformance.js';
import StatusBar from '@/components/Discover/StatusBar.vue'; import StatusBar from '@/components/Discover/StatusBar.vue';
import { setLineChartData } from '@/module/setChartData.js'; import { setLineChartData } from '@/module/setChartData.js';
import { simpleTimeLabel, followTimeLabel, dateLabel, import { simpleTimeLabel, followTimeLabel, getDateLabelByMinMaxDate,
setTimeStringFormatBaseOnTimeDifference, setTimeStringFormatBaseOnTimeDifference,
mapTimestampToAxisTicksByFormat, mapTimestampToAxisTicksByFormat,
getStepSizeOfYTicks, getStepSizeOfYTicks,
@@ -438,7 +438,7 @@ export default {
const maxX = chartData.x_axis.max; const maxX = chartData.x_axis.max;
const minX = chartData.x_axis.min; const minX = chartData.x_axis.min;
const getMoment = (time)=> this.$moment(time).format('YYYY/M/D hh:mm:ss'); const getMoment = (time)=> this.$moment(time).format('YYYY/M/D hh:mm:ss');
const getDateLabel = dateLabel; const getDateLabel = getDateLabelByMinMaxDate;
let datasets = chartData.data; let datasets = chartData.data;
let xData; let xData;
let yData; let yData;