Skip to content

Commit

Permalink
[#1269] Chart > Legend 영역 통계 > null 처리 (#1270)
Browse files Browse the repository at this point in the history
#####################################
- 합계, 최솟값, 최댓값, 평균 계산시 null과 undefined는 제외하도록 함
- 마지막값 계산 시 null과 undefined는 'Null'로 표시되도록함
- 계산된 값이 javascript기준 MAX_SAFE_INTEGER을 초과했거나 MIN_SAFE_INTEGER 미만일 경우 console warning이 출력되도록 함

Co-authored-by: jinhee park <jinhee@ex-em.com>
  • Loading branch information
jhee564 and jhee564 authored Aug 23, 2022
1 parent 4b8040c commit f17a2d3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
9 changes: 5 additions & 4 deletions docs/views/comboChart/example/TableTypeLegend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,16 @@ import { onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
avg: {
use: useAvg,
decimalPoint: 4,
formatter: value => `${value.toFixed(0)}`,
},
total: {
use: useTotal,
decimalPoint: 4,
formatter: value => `${value.toFixed(0)}`,
},
last: {
use: useLast,
title: 'CURRENT',
formatter: value => `${value.toFixed(0)}`,
style: {
color: '#219EBC',
},
Expand All @@ -223,7 +224,7 @@ import { onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
const liveInterval = ref();
let timeValue = dayjs().format('YYYY-MM-DD HH:mm:ss');
const addRandomChartData = () => {
const addRandomChartData = (ix) => {
if (isLive.value) {
chartData.labels.shift();
}
Expand All @@ -236,13 +237,13 @@ import { onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
seriesData.shift();
}
seriesData.push(Math.random() * (100 - 1) + 1);
seriesData.push(ix > 6 ? null : Math.random() * (100 - 1) + 1);
});
};
onMounted(() => {
for (let ix = 0; ix < 10; ix++) {
addRandomChartData();
addRandomChartData(ix);
}
});
Expand Down
8 changes: 8 additions & 0 deletions src/components/chart/helpers/helpers.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,12 @@ export default {
targetDOM.style[key] = styleObject[key];
});
},

checkSafeInteger(value) {
if (value === null || value === undefined) {
return false;
}

return value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER;
},
};
22 changes: 16 additions & 6 deletions src/components/chart/model/model.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,14 +949,24 @@ const modules = {
const seriesIds = Object.keys(series);

seriesIds?.forEach((sId) => {
const dataList = allData[sId].map(data => (data.value ? data.value : data));

const min = (Math.min(...dataList));
const max = (Math.max(...dataList));
const total = (dataList.reduce((a, b) => a + b, 0));
const avg = (total / dataList.length || 0);
const dataList = allData[sId].map(data => (data?.value ? data.value : data));
const last = (dataList[dataList.length - 1]);

const dataListExcludedNull = dataList.filter(value => value !== undefined && value !== null);
const min = (Math.min(...dataListExcludedNull));
const max = (Math.max(...dataListExcludedNull));
const total = (dataListExcludedNull.reduce((a, b) => a + b, 0));
const avg = (total / dataListExcludedNull.length || 0);

if (!Util.checkSafeInteger(min)
|| !Util.checkSafeInteger(max)
|| !Util.checkSafeInteger(avg)
|| !Util.checkSafeInteger(total)
|| !Util.checkSafeInteger(last)
) {
console.warn('[EVUI][Chart] The aggregated value exceeds 9007199254740991 or less then -9007199254740991.');
}

aggregationDataSet[sId] = { min, max, avg, total, last };
});

Expand Down
12 changes: 8 additions & 4 deletions src/components/chart/plugins/plugins.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ const modules = {
}

const seriesId = row.series.sId;
const value = +aggregations?.[seriesId]?.[key];
const value = aggregations?.[seriesId]?.[key];
dom.textContent = this.getFormattedValue(columns[key], value);
});
});
Expand Down Expand Up @@ -756,7 +756,7 @@ const modules = {
}

if (columns[key].use) {
const formattedTxt = this.getFormattedValue(columns[key], +aggregations[key]);
const formattedTxt = this.getFormattedValue(columns[key], aggregations[key]);
const valueDOM = document.createElement('td');
valueDOM.className = 'ev-chart-legend--table__value';
valueDOM.style.color = series.show ? opt.color : opt.inactive;
Expand Down Expand Up @@ -1134,13 +1134,17 @@ const modules = {
* @returns {string}
*/
getFormattedValue({ formatter, decimalPoint }, value) {
if (value === undefined || value === null) {
return 'Null';
}

let formattedTxt;
if (formatter) {
formattedTxt = formatter(value);
formattedTxt = formatter(+value);
}

if (!formatter || typeof formattedTxt !== 'string') {
formattedTxt = Util.labelSignFormat(value, decimalPoint);
formattedTxt = Util.labelSignFormat(+value, decimalPoint);
}

return formattedTxt;
Expand Down

0 comments on commit f17a2d3

Please sign in to comment.