shouldn't use mod(%) operator.
shouldn't divide hour and then divide day again. should use substring. should split into 8 instead of 6.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import moment from 'moment';
|
||||
const NUM_OF_PARTS_TO_SPLIT = 6;
|
||||
const NUM_OF_PARTS_TO_SPLIT = 8;
|
||||
const TOFIXED_DEICMAL = 1;
|
||||
|
||||
/**
|
||||
* 若想要有等差的Y軸刻度,則必須確保index是乘以一個共通的被乘數
|
||||
@@ -10,8 +11,10 @@ const NUM_OF_PARTS_TO_SPLIT = 6;
|
||||
export const getStepSizeOfYTicks = (maxTimeInSecond) => {
|
||||
const numOfParts = NUM_OF_PARTS_TO_SPLIT;
|
||||
const {unitToUse, timeValue} = getTimeUnitAndValueToUse(maxTimeInSecond);
|
||||
console.log('{unitToUse, timeValue}', unitToUse, timeValue); // TODO:
|
||||
let resultStepSize;
|
||||
resultStepSize = Math.floor(timeValue / numOfParts);
|
||||
resultStepSize = (timeValue / numOfParts);
|
||||
console.log('resultStepSize', resultStepSize); //TODO:
|
||||
|
||||
return {resultStepSize, unitToUse};
|
||||
}
|
||||
@@ -26,25 +29,29 @@ const getTimeUnitAndValueToUse = (secondToDecide) => {
|
||||
const hour = 60 * 60;
|
||||
const minutes = 60;
|
||||
const dd = secondToDecide / day;
|
||||
const hh = (secondToDecide % day) / hour;
|
||||
const mm = (secondToDecide % hour) / minutes;
|
||||
const hh = secondToDecide / hour;
|
||||
const mm = secondToDecide / minutes;
|
||||
|
||||
if (dd > 0 && dd > 1) {
|
||||
if (dd > 0) {
|
||||
console.log('dd > 0 && dd > 1 secondToDecide / day', secondToDecide / day); //TODO:
|
||||
return {
|
||||
unitToUse: "d",
|
||||
timeValue: secondToDecide / day,
|
||||
};
|
||||
} else if (hh > 0 && hh > 1) {
|
||||
} else if (hh > 0) {
|
||||
console.log('hh > 0 && hh > 1 secondToDecide / hour', secondToDecide / hour);
|
||||
return {
|
||||
unitToUse: "h",
|
||||
timeValue: (secondToDecide % day) / hour,
|
||||
timeValue: secondToDecide / hour,
|
||||
};
|
||||
} else if (mm > 0 && mm > 1) {
|
||||
} else if (mm > 0) {
|
||||
console.log('mm > 0 && mm > 1', secondToDecide / minutes);
|
||||
return {
|
||||
unitToUse: "m",
|
||||
timeValue: (secondToDecide % hour) / minutes,
|
||||
timeValue: secondToDecide / minutes,
|
||||
};
|
||||
} else {
|
||||
console.log('less than one minutes final case timeValue:', secondToDecide, dd, hh, mm); //TODO:
|
||||
return {
|
||||
unitToUse: "s",
|
||||
timeValue: secondToDecide,
|
||||
@@ -61,7 +68,10 @@ const getTimeUnitAndValueToUse = (secondToDecide) => {
|
||||
* @param {string} unitToUse time unit to display; "dhms" usually
|
||||
*/
|
||||
export function getYTicksByIndex(stepSize, index, unitToUse){
|
||||
return `${stepSize * index}${unitToUse}`;
|
||||
const rawStepsizeMultIndex = (stepSize * index).toString();
|
||||
const shortenStepsizeMultIndex = rawStepsizeMultIndex.substring(
|
||||
0, rawStepsizeMultIndex.indexOf('.') + 1 + TOFIXED_DEICMAL);
|
||||
return `${shortenStepsizeMultIndex}${unitToUse}`;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -263,9 +273,7 @@ export function dateLabel(date, maxDate, minDate) {
|
||||
* @returns {string} - The suitable time format string.
|
||||
*/
|
||||
export const setTimeStringFormatBaseOnTimeDifference = (minTimeStamp, maxTimeStamp) => {
|
||||
const laterDate = new Date(maxTimeStamp);
|
||||
const earlyDate = new Date(minTimeStamp);
|
||||
const timeDifferenceInSeconds = (laterDate - earlyDate);
|
||||
const timeDifferenceInSeconds = maxTimeStamp - minTimeStamp;
|
||||
|
||||
let dateFormat;
|
||||
if (timeDifferenceInSeconds < 60) {
|
||||
|
||||
Reference in New Issue
Block a user