Browse Source

비행 시간 통계 그래프 라벨 수정

pull/2/head
hhjk00 10 months ago
parent
commit
b478143e49
  1. 30
      src/components/statistics/StatisticsSearch.js
  2. 4
      src/components/statistics/StatisticsTotal.js
  3. 15
      src/containers/statistics/AbnormalSituationContainer.js
  4. 39
      src/containers/statistics/FlightContainer.js
  5. 16
      src/containers/statistics/FlightResultContainer.js

30
src/components/statistics/StatisticsSearch.js

@ -22,12 +22,11 @@ export default function StatisticsSearch({
handlerBarTicks, handlerBarTicks,
handlerTitleName, handlerTitleName,
handleChangeSearchType, handleChangeSearchType,
parseTimeToDate secondsToDateString
}) { }) {
const [total, setTotal] = useState([]); const [total, setTotal] = useState([]);
const [top, setTop] = useState([]); const [top, setTop] = useState([]);
// searchType과 searchData가 바뀔때마다 state 업데이트
useEffect(() => { useEffect(() => {
chartInit(); chartInit();
}, [searchData]); }, [searchData]);
@ -86,6 +85,22 @@ export default function StatisticsSearch({
}, },
tooltips: { tooltips: {
// Updated default tooltip UI // Updated default tooltip UI
callbacks: {
label(tooltipItem, data) {
// let label = data.labels[tooltipItem.index] || '',
let value = data.datasets[0].data[tooltipItem.index],
output = ` ${value}`;
if (searchType.category === 'TIME') {
const dateValue = secondsToDateString(value);
return (output = ` ${dateValue}`);
} else if (searchType.category === 'DISTANCE') {
return (output = ` ${value} m`);
}
return output;
}
},
shadowOffsetX: 1, shadowOffsetX: 1,
shadowOffsetY: 1, shadowOffsetY: 1,
shadowBlur: 8, shadowBlur: 8,
@ -119,6 +134,15 @@ export default function StatisticsSearch({
zeroLineColor: gridLineColor zeroLineColor: gridLineColor
}, },
ticks: { ticks: {
callback: function (value, index, values) {
if (searchType.category === 'TIME') {
const dateValue = secondsToDateString(value, 'yAxes');
return dateValue;
} else if (searchType.category === 'DISTANCE') {
return value + 'm';
}
return value;
},
...handlerBarTicks(total), ...handlerBarTicks(total),
min: 0, min: 0,
fontColor: labelColor fontColor: labelColor
@ -164,7 +188,7 @@ export default function StatisticsSearch({
output = ` ${label} : ${value}`; output = ` ${label} : ${value}`;
if (searchType.category === 'TIME') { if (searchType.category === 'TIME') {
const dateValue = parseTimeToDate(value); const dateValue = secondsToDateString(value);
return (output = ` ${label} : ${dateValue}`); return (output = ` ${label} : ${dateValue}`);
} else if (searchType.category === 'DISTANCE') { } else if (searchType.category === 'DISTANCE') {
return (output = ` ${label} : ${value} m`); return (output = ` ${label} : ${value} m`);

4
src/components/statistics/StatisticsTotal.js

@ -5,7 +5,7 @@ export default function StatisticsTotal({
totalData, totalData,
titleName, titleName,
totalTitle, totalTitle,
parseTimeToSeconds, timeStringToDateString,
formatNumber, formatNumber,
formatDistance formatDistance
}) { }) {
@ -17,7 +17,7 @@ export default function StatisticsTotal({
const renderData = (data, titleName, idx) => { const renderData = (data, titleName, idx) => {
if (titleName) { if (titleName) {
if (idx === 0) return parseTimeToSeconds(data); if (idx === 0) return timeStringToDateString(data);
if (idx === 1) return <>{formatDistance(data)}m</>; if (idx === 1) return <>{formatDistance(data)}m</>;
return <>{formatNumber(data)}</>; return <>{formatNumber(data)}</>;
} else { } else {

15
src/containers/statistics/AbnormalSituationContainer.js

@ -87,8 +87,19 @@ export default function AbnormalSituationContainer() {
}; };
const handlerStepSize = max => { const handlerStepSize = max => {
const exponent = Math.ceil(Math.log10(max)); const exponent = Math.floor(Math.log10(max));
return 10 ** (exponent - 1); const base = Math.pow(10, exponent);
let stepSize;
if (max / base > 5) {
stepSize = base;
} else if (max / (base / 2) > 5) {
stepSize = base / 2;
} else {
stepSize = base / 5;
}
return stepSize;
}; };
// 123456789 -> 123,456,789 // 123456789 -> 123,456,789

39
src/containers/statistics/FlightContainer.js

@ -86,8 +86,19 @@ export default function FlightContainer() {
}; };
const handlerStepSize = max => { const handlerStepSize = max => {
const exponent = Math.ceil(Math.log10(max)); const exponent = Math.floor(Math.log10(max));
return 10 ** (exponent - 1); const base = Math.pow(10, exponent);
let stepSize;
if (max / base > 5) {
stepSize = base;
} else if (max / (base / 2) > 5) {
stepSize = base / 2;
} else {
stepSize = base / 5;
}
return stepSize;
}; };
// 1234.2345 -> 1,234.2 // 1234.2345 -> 1,234.2
@ -109,7 +120,7 @@ export default function FlightContainer() {
}; };
// '24:35:12' -> '1일 35분 12초' // '24:35:12' -> '1일 35분 12초'
const parseTimeToSeconds = time => { const timeStringToDateString = time => {
if (time === 'noData' || time === '00:00:00') return '0초'; if (time === 'noData' || time === '00:00:00') return '0초';
const [hour, minute, second] = String(time).split(':').map(Number); const [hour, minute, second] = String(time).split(':').map(Number);
@ -124,19 +135,31 @@ export default function FlightContainer() {
return parts.join(' '); return parts.join(' ');
}; };
const formatPart = (value, unit) => (value > 0 ? `${value}${unit}` : ''); const formatPart = (value, unit) => {
if (unit === 's' && value === 0) return '0s';
return value > 0 ? `${value}${unit}` : '';
};
// 975 -> '16분 15초' // 975 -> '16분 15초'
const parseTimeToDate = time => { const secondsToDateString = (time, yAxes) => {
const { days, hours, minutes, seconds } = secondsToDHMS(time); const { days, hours, minutes, seconds } = secondsToDHMS(time);
const parts = [ let parts = [
formatPart(days, '일'), formatPart(days, '일'),
formatPart(hours, '시간'), formatPart(hours, '시간'),
formatPart(minutes, '분'), formatPart(minutes, '분'),
formatPart(seconds, '초') formatPart(seconds, '초')
]; ];
if (yAxes) {
parts = [
formatPart(days, 'd'),
formatPart(hours, 'h'),
formatPart(minutes, 'm'),
formatPart(seconds, 's')
];
}
return parts.join(' '); return parts.join(' ');
}; };
@ -156,12 +179,12 @@ export default function FlightContainer() {
titleName={titleName} titleName={titleName}
totalTitle={totalTitle} totalTitle={totalTitle}
totalData={flight} totalData={flight}
parseTimeToSeconds={parseTimeToSeconds} timeStringToDateString={timeStringToDateString}
formatDistance={formatDistance} formatDistance={formatDistance}
formatNumber={formatNumber} formatNumber={formatNumber}
/> />
<StatisticsSearch <StatisticsSearch
parseTimeToDate={parseTimeToDate} secondsToDateString={secondsToDateString}
searchData={flightSearch} searchData={flightSearch}
searchType={searchType} searchType={searchType}
categoryTypeOptions={categoryTypeOptions} categoryTypeOptions={categoryTypeOptions}

16
src/containers/statistics/FlightResultContainer.js

@ -86,10 +86,20 @@ export default function ResultContainer() {
}; };
const handlerStepSize = max => { const handlerStepSize = max => {
const exponent = Math.ceil(Math.log10(max)); const exponent = Math.floor(Math.log10(max));
return 10 ** (exponent - 1); const base = Math.pow(10, exponent);
}; let stepSize;
if (max / base > 5) {
stepSize = base;
} else if (max / (base / 2) > 5) {
stepSize = base / 2;
} else {
stepSize = base / 5;
}
return stepSize;
};
// 123456789 -> 123,456,789 // 123456789 -> 123,456,789
const formatNumber = number => { const formatNumber = number => {
if (number === 'NoData') return 0; if (number === 'NoData') return 0;

Loading…
Cancel
Save