diff --git a/src/components/statistics/StatisticsSearch.js b/src/components/statistics/StatisticsSearch.js index ec70f281..b359a5a2 100644 --- a/src/components/statistics/StatisticsSearch.js +++ b/src/components/statistics/StatisticsSearch.js @@ -62,8 +62,8 @@ export default function StatisticsSearch({ setTotal(totalValue); setTop(topValue); } else { - setTotal(filteredData(graphData.map(i => i.value))); - setTop(filteredData(topData.map(i => i.value))); + setTotal(graph); + setTop(top); } }; diff --git a/src/containers/statistics/AbnormalSituationContainer.js b/src/containers/statistics/AbnormalSituationContainer.js index 454a97e7..f816150a 100644 --- a/src/containers/statistics/AbnormalSituationContainer.js +++ b/src/containers/statistics/AbnormalSituationContainer.js @@ -80,23 +80,28 @@ export default function AbnormalSituationContainer() { // Bar Graph handler const handlerBarTicks = data => { - const max = Math.ceil(Math.max(...data) / 10) * 10; - const stepSize = handlerStepSize(max); + const max = calculateMax(data); + const stepSize = hadnlerStepSize(max); return { max, stepSize }; }; - const handlerStepSize = max => { - const exponent = Math.floor(Math.log10(max)); - const base = Math.pow(10, exponent); + const calculateMax = data => { + const max = Math.max(...data); + return Math.ceil(max / 5) * 5; + }; + + const hadnlerStepSize = max => { + const step = Math.ceil(max / 5); + let stepSize; - if (max / base > 5) { - stepSize = base; - } else if (max / (base / 2) > 5) { - stepSize = base / 2; + if (max > 100) { + stepSize = Math.ceil(step / 50) * 50; + } else if (max <= 10) { + stepSize = 1; } else { - stepSize = base / 5; + stepSize = Math.ceil(step / 5) * 5; } return stepSize; diff --git a/src/containers/statistics/FlightContainer.js b/src/containers/statistics/FlightContainer.js index 66fd92f8..e22e0c36 100644 --- a/src/containers/statistics/FlightContainer.js +++ b/src/containers/statistics/FlightContainer.js @@ -79,32 +79,36 @@ export default function FlightContainer() { // Bar Graph handler const handlerBarTicks = data => { - const max = Math.ceil(Math.max(...data) / 10) * 10; - const stepSize = handlerStepSize(max); + const max = calculateMax(data); + const stepSize = hadnlerStepSize(max); return { max, stepSize }; }; - const handlerStepSize = max => { - const exponent = Math.floor(Math.log10(max)); - const base = Math.pow(10, exponent); + const calculateMax = data => { + const max = Math.max(...data); + return Math.ceil(max / 5) * 5; + }; + + const hadnlerStepSize = max => { + const step = Math.ceil(max / 5); + let stepSize; if (searchType.category === 'TIME') { stepSize = 3600; } else { - if (max / base > 5) { - stepSize = base; - } else if (max / (base / 2) > 5) { - stepSize = base / 2; + if (max > 100) { + stepSize = Math.ceil(step / 50) * 50; + } else if (max <= 10) { + stepSize = 1; } else { - stepSize = base / 5; + stepSize = Math.ceil(step / 5) * 5; } } return stepSize; }; - // 1234.2345 -> 1,234.2 const formatDistance = number => { if (number === 'noData' || number === 0.0) return '0'; diff --git a/src/containers/statistics/FlightResultContainer.js b/src/containers/statistics/FlightResultContainer.js index b0ba0190..09566916 100644 --- a/src/containers/statistics/FlightResultContainer.js +++ b/src/containers/statistics/FlightResultContainer.js @@ -79,27 +79,33 @@ export default function ResultContainer() { // Bar Graph handler const handlerBarTicks = data => { - const max = Math.ceil(Math.max(...data) / 10) * 10; - const stepSize = handlerStepSize(max); + const max = calculateMax(data); + const stepSize = hadnlerStepSize(max); return { max, stepSize }; }; - const handlerStepSize = max => { - const exponent = Math.floor(Math.log10(max)); - const base = Math.pow(10, exponent); + const calculateMax = data => { + const max = Math.max(...data); + return Math.ceil(max / 5) * 5; + }; + + const hadnlerStepSize = max => { + const step = Math.ceil(max / 5); + let stepSize; - if (max / base > 5) { - stepSize = base; - } else if (max / (base / 2) > 5) { - stepSize = base / 2; + if (max > 100) { + stepSize = Math.ceil(step / 50) * 50; + } else if (max <= 10) { + stepSize = 1; } else { - stepSize = base / 5; + stepSize = Math.ceil(step / 5) * 5; } return stepSize; }; + // 123456789 -> 123,456,789 const formatNumber = number => { if (number === 'NoData') return 0;