From 02faa1259072c95d466f6d5b55b120854785df91 Mon Sep 17 00:00:00 2001 From: hhjk00 Date: Tue, 21 Nov 2023 13:38:29 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=84=ED=96=89=20=EC=8B=9C=EA=B0=84=20y?= =?UTF-8?q?=EC=B6=95=20value=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/statistics/StatisticsSearch.js | 13 ++++++------- src/containers/statistics/FlightContainer.js | 13 ++++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/components/statistics/StatisticsSearch.js b/src/components/statistics/StatisticsSearch.js index b359a5a..6d24c24 100644 --- a/src/components/statistics/StatisticsSearch.js +++ b/src/components/statistics/StatisticsSearch.js @@ -41,8 +41,7 @@ export default function StatisticsSearch({ const chartInit = () => { const { topData, graphData } = searchData; - const filteredData = data => - data.filter(i => i && !['nodata', 'NoData'].includes(i)); + const filteredData = data => data.filter(i => i && i !== 'NoData'); const graph = filteredData(graphData.map(i => i.value)); const top = filteredData(topData.map(i => i.value)); @@ -133,8 +132,8 @@ export default function StatisticsSearch({ ticks: { callback: function (value, index, values) { if (searchType.category === 'TIME') { - const dateValue = formatSeconds(value); - return dateValue; + const isLastIndex = index === values.length - 1; + return formatSeconds(value, isLastIndex); } else if (searchType.category === 'DISTANCE') { return value + 'm'; } @@ -231,7 +230,7 @@ export default function StatisticsSearch({ ] }; - const handlerPlugins = chartData => { + const plugins = chartData => { return [ { afterDraw: function (chart) { @@ -418,7 +417,7 @@ export default function StatisticsSearch({ data={totalData} options={barOptions} height={400} - plugins={handlerPlugins(totalData)} + plugins={plugins(totalData)} /> @@ -437,7 +436,7 @@ export default function StatisticsSearch({ data={topData} options={doughnutOptions} height={275} - plugins={handlerPlugins(topData)} + plugins={plugins(topData)} /> {/*
diff --git a/src/containers/statistics/FlightContainer.js b/src/containers/statistics/FlightContainer.js index e22e0c3..01d8094 100644 --- a/src/containers/statistics/FlightContainer.js +++ b/src/containers/statistics/FlightContainer.js @@ -109,6 +109,7 @@ export default function FlightContainer() { return stepSize; }; + // 1234.2345 -> 1,234.2 const formatDistance = number => { if (number === 'noData' || number === 0.0) return '0'; @@ -127,6 +128,10 @@ export default function FlightContainer() { return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); }; + const formatPart = (value, unit, isLastIndex) => { + return value > 0 || isLastIndex ? `${value}${unit}` : ''; + }; + // '24:35:12' -> '1일 35분 12초' const formatTimeString = time => { if (time === 'noData' || time === '00:00:00') return '0초'; @@ -143,17 +148,15 @@ export default function FlightContainer() { return parts.join(' '); }; - const formatPart = (value, unit) => (value > 0 ? `${value}${unit}` : ''); - // 975 -> '16분 15초' - const formatSeconds = time => { + const formatSeconds = (time, isLastIndex) => { const { days, hours, minutes, seconds } = secondsToDHMS(time); - let parts = [ + const parts = [ formatPart(days, '일'), formatPart(hours, '시간'), formatPart(minutes, '분'), - formatPart(seconds, '초') + formatPart(seconds, '초', isLastIndex) ]; return parts.join(' ');