fix: #302. Shouldn't use mod and shouldn't double divide.
This commit is contained in:
@@ -39,13 +39,12 @@ const getTimeUnitAndValueToUse = (secondToDecide) => {
|
||||
timeValue: secondToDecide / hour,
|
||||
};
|
||||
} else if (mm > 0 && mm > 1) {
|
||||
console.log('mm > 0 && mm > 1', secondToDecide / minutes);
|
||||
return {
|
||||
unitToUse: "m",
|
||||
timeValue: secondToDecide / minutes,
|
||||
};
|
||||
} 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 {
|
||||
unitToUse: "s",
|
||||
timeValue: secondToDecide,
|
||||
@@ -161,16 +160,16 @@ export function followTimeLabel(second, max, fixedNumber = 0) {
|
||||
const minutes = 60;
|
||||
|
||||
const dd = max / day;
|
||||
const hh = (max % day) / hour;
|
||||
const mm = (max % hour) / minutes;
|
||||
const hh = max / hour;
|
||||
const mm = max/ minutes;
|
||||
let maxUnit = '';
|
||||
let result = "";
|
||||
|
||||
if (dd > 0) {
|
||||
if (dd > 1) {
|
||||
maxUnit = 'd';
|
||||
} else if (hh > 0) {
|
||||
} else if (hh > 1) {
|
||||
maxUnit = 'h';
|
||||
} else if (mm > 0) {
|
||||
} else if (mm > 1) {
|
||||
maxUnit = 'm';
|
||||
} else {
|
||||
maxUnit = 's';
|
||||
@@ -186,13 +185,13 @@ export function followTimeLabel(second, max, fixedNumber = 0) {
|
||||
if(((second % day) / hour) === 0) {
|
||||
fixedNumber = 0;
|
||||
}
|
||||
result = ((second % day) / hour).toFixed(fixedNumber) + 'h';
|
||||
result = (second / hour).toFixed(fixedNumber) + 'h';
|
||||
break;
|
||||
case 'm':
|
||||
if(((second % hour) / minutes) === 0) {
|
||||
if((second / minutes) === 0) {
|
||||
fixedNumber = 0;
|
||||
}
|
||||
result = ((second % hour) / minutes).toFixed(fixedNumber) + 'm';
|
||||
result = (second / minutes).toFixed(fixedNumber) + 'm';
|
||||
break;
|
||||
case 's':
|
||||
if(second === 0) {
|
||||
@@ -211,7 +210,7 @@ export function followTimeLabel(second, max, fixedNumber = 0) {
|
||||
* @param { string } maxX 該 data 最大的日期,格式是 timestamp
|
||||
* @param { string } minX 該 data 最小的日期,格式是 timestamp
|
||||
*/
|
||||
export function dateLabel(date, maxDate, minDate) {
|
||||
export function getDateLabelByMinMaxDate(date, maxDate, minDate) {
|
||||
// 將時間字串轉換為時間物件
|
||||
// new Date(time) 之後不用 getTime(),因為在JavaScript中,
|
||||
// 日期物件是以時間戳記(timestamp)的形式存儲的。當創建一個新的日期物件時,
|
||||
@@ -238,16 +237,16 @@ export function dateLabel(date, maxDate, minDate) {
|
||||
const diffSeconds = Math.floor(timeDiff);
|
||||
|
||||
// 顯示結果
|
||||
if (diffMonths > 0) {
|
||||
if (diffMonths > 1) {
|
||||
return moment(date).format('YYYY/MM/DD');
|
||||
}
|
||||
else if (diffDays > 0) {
|
||||
else if (diffDays > 1) {
|
||||
return moment(date).format('MM/DD');
|
||||
}
|
||||
else if (diffHours > 0) {
|
||||
else if (diffHours > 1) {
|
||||
return moment(date).format('MM/DD hh:00');
|
||||
}
|
||||
else if (diffMinutes > 0) {
|
||||
else if (diffMinutes > 1) {
|
||||
return moment(date).format('MM/DD hh:mm');
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -158,7 +158,7 @@ import LoadingStore from '@/stores/loading.js';
|
||||
import CompareStore from '@/stores/compare.js';
|
||||
import SidebarStates from '@/components/Compare/SidebarStates.vue';
|
||||
import { setLineChartData } from '@/module/setChartData.js';
|
||||
import { simpleTimeLabel, followTimeLabel, dateLabel,
|
||||
import { simpleTimeLabel, followTimeLabel, getDateLabelByMinMaxDate,
|
||||
setTimeStringFormatBaseOnTimeDifference,
|
||||
mapTimestampToAxisTicksByFormat,
|
||||
getStepSizeOfYTicks,
|
||||
@@ -438,7 +438,7 @@ export default {
|
||||
const maxX = chartData.x_axis.max;
|
||||
const minX = chartData.x_axis.min;
|
||||
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 xDataPrimary;
|
||||
let yDataPrimary;
|
||||
|
||||
@@ -146,7 +146,7 @@ import PerformanceStore from '@/stores/performance.js';
|
||||
import ConformanceStore from '@/stores/conformance.js';
|
||||
import StatusBar from '@/components/Discover/StatusBar.vue';
|
||||
import { setLineChartData } from '@/module/setChartData.js';
|
||||
import { simpleTimeLabel, followTimeLabel, dateLabel,
|
||||
import { simpleTimeLabel, followTimeLabel, getDateLabelByMinMaxDate,
|
||||
setTimeStringFormatBaseOnTimeDifference,
|
||||
mapTimestampToAxisTicksByFormat,
|
||||
getStepSizeOfYTicks,
|
||||
@@ -438,7 +438,7 @@ export default {
|
||||
const maxX = chartData.x_axis.max;
|
||||
const minX = chartData.x_axis.min;
|
||||
const getMoment = (time)=> this.$moment(time).format('YYYY/M/D hh:mm:ss');
|
||||
const getDateLabel = dateLabel;
|
||||
const getDateLabel = getDateLabelByMinMaxDate;
|
||||
let datasets = chartData.data;
|
||||
let xData;
|
||||
let yData;
|
||||
|
||||
Reference in New Issue
Block a user