Browse Source

시간 통계 bar 그래프 y축 단위 변경

pull/2/head
hhjk00 10 months ago
parent
commit
1e7490c1c2
  1. 25
      src/components/statistics/StatisticsSearch.js
  2. 4
      src/components/statistics/StatisticsTotal.js
  3. 22
      src/containers/statistics/FlightContainer.js

25
src/components/statistics/StatisticsSearch.js

@ -22,7 +22,7 @@ export default function StatisticsSearch({
handlerBarTicks, handlerBarTicks,
handlerTitleName, handlerTitleName,
handleChangeSearchType, handleChangeSearchType,
secondsToDateString formatSeconds
}) { }) {
const [total, setTotal] = useState([]); const [total, setTotal] = useState([]);
const [top, setTop] = useState([]); const [top, setTop] = useState([]);
@ -44,23 +44,20 @@ export default function StatisticsSearch({
const filteredData = data => const filteredData = data =>
data.filter(i => i && !['nodata', 'NoData'].includes(i)); data.filter(i => i && !['nodata', 'NoData'].includes(i));
const graph = filteredData(graphData.map(i => i.value));
const top = filteredData(topData.map(i => i.value));
if (searchType.category === 'TIME') { if (searchType.category === 'TIME') {
// ['00:00:00', '12:34:56'] -> [0,45296] 초 단위로 변경 // ['00:00:00', '12:34:56'] -> [0,45296] 초 단위로 변경
const timeGraph = filteredData(graphData.map(i => i.value)); const totalValue = parseTimeToSeconds(graph);
const timeTop = filteredData(topData.map(i => i.value)); const topValue = parseTimeToSeconds(top);
const totalValue = parseTimeToSeconds(timeGraph);
const topValue = parseTimeToSeconds(timeTop);
setTotal(totalValue); setTotal(totalValue);
setTop(topValue); setTop(topValue);
} else if (searchType.category === 'DISTANCE') { } else if (searchType.category === 'DISTANCE') {
// [0.1234, 0.5678] -> [0.1, 0.5] // [0.1234, 0.5678] -> [0.1, 0.5]
const distanceTotal = filteredData(graphData.map(i => i.value)); const totalValue = graph.map(i => i.toFixed(1));
const distanceTop = filteredData(topData.map(i => i.value)); const topValue = top.map(i => i.toFixed(1));
const totalValue = distanceTotal.map(i => i.toFixed(1));
const topValue = distanceTop.map(i => i.toFixed(1));
setTotal(totalValue); setTotal(totalValue);
setTop(topValue); setTop(topValue);
@ -92,7 +89,7 @@ export default function StatisticsSearch({
output = ` ${value}`; output = ` ${value}`;
if (searchType.category === 'TIME') { if (searchType.category === 'TIME') {
const dateValue = secondsToDateString(value); const dateValue = formatSeconds(value);
return (output = ` ${dateValue}`); return (output = ` ${dateValue}`);
} else if (searchType.category === 'DISTANCE') { } else if (searchType.category === 'DISTANCE') {
return (output = ` ${value} m`); return (output = ` ${value} m`);
@ -136,7 +133,7 @@ export default function StatisticsSearch({
ticks: { ticks: {
callback: function (value, index, values) { callback: function (value, index, values) {
if (searchType.category === 'TIME') { if (searchType.category === 'TIME') {
const dateValue = secondsToDateString(value, 'yAxes'); const dateValue = formatSeconds(value);
return dateValue; return dateValue;
} else if (searchType.category === 'DISTANCE') { } else if (searchType.category === 'DISTANCE') {
return value + 'm'; return value + 'm';
@ -188,7 +185,7 @@ export default function StatisticsSearch({
output = ` ${label} : ${value}`; output = ` ${label} : ${value}`;
if (searchType.category === 'TIME') { if (searchType.category === 'TIME') {
const dateValue = secondsToDateString(value); const dateValue = formatSeconds(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,
timeStringToDateString, formatTimeString,
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 timeStringToDateString(data); if (idx === 0) return formatTimeString(data);
if (idx === 1) return <>{formatDistance(data)}m</>; if (idx === 1) return <>{formatDistance(data)}m</>;
return <>{formatNumber(data)}</>; return <>{formatNumber(data)}</>;
} else { } else {

22
src/containers/statistics/FlightContainer.js

@ -120,7 +120,7 @@ export default function FlightContainer() {
}; };
// '24:35:12' -> '1일 35분 12초' // '24:35:12' -> '1일 35분 12초'
const timeStringToDateString = time => { const formatTimeString = 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);
@ -135,13 +135,10 @@ export default function FlightContainer() {
return parts.join(' '); return parts.join(' ');
}; };
const formatPart = (value, unit) => { const formatPart = (value, unit) => (value > 0 ? `${value}${unit}` : '');
if (unit === 's' && value === 0) return '0s';
return value > 0 ? `${value}${unit}` : '';
};
// 975 -> '16분 15초' // 975 -> '16분 15초'
const secondsToDateString = (time, yAxes) => { const formatSeconds = time => {
const { days, hours, minutes, seconds } = secondsToDHMS(time); const { days, hours, minutes, seconds } = secondsToDHMS(time);
let parts = [ let parts = [
@ -151,15 +148,6 @@ export default function FlightContainer() {
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(' ');
}; };
@ -179,16 +167,16 @@ export default function FlightContainer() {
titleName={titleName} titleName={titleName}
totalTitle={totalTitle} totalTitle={totalTitle}
totalData={flight} totalData={flight}
timeStringToDateString={timeStringToDateString} formatTimeString={formatTimeString}
formatDistance={formatDistance} formatDistance={formatDistance}
formatNumber={formatNumber} formatNumber={formatNumber}
/> />
<StatisticsSearch <StatisticsSearch
secondsToDateString={secondsToDateString}
searchData={flightSearch} searchData={flightSearch}
searchType={searchType} searchType={searchType}
categoryTypeOptions={categoryTypeOptions} categoryTypeOptions={categoryTypeOptions}
dateLists={dateLists} dateLists={dateLists}
formatSeconds={formatSeconds}
handlerBarTicks={handlerBarTicks} handlerBarTicks={handlerBarTicks}
handlerTitleName={handlerTitleName} handlerTitleName={handlerTitleName}
handleChangeSearchType={handleChangeSearchType} handleChangeSearchType={handleChangeSearchType}

Loading…
Cancel
Save