Skip to content

Commit 2ec178f

Browse files
kimorkimkim jeong yong
andauthored
fix: add optional chaining to prevent errors in chart calculations (#467)
Co-authored-by: kim jeong yong <usbsync@nts-corp.com>
1 parent 53ca2cb commit 2ec178f

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/components/widget/Chart/Bar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import _unzip from 'lodash/unzip';
1414
import _findIndex from 'lodash/findIndex';
1515

1616
const setChartXCount = (chartObj, categories, windowWidth) => () => {
17-
const categoryWordLength = categories?.[0].toString().length * 5;
17+
const categoryWordLength = categories?.[0]?.toString().length * 5;
1818
const padding = 100;
1919
if (windowWidth > categoryWordLength * categories.length + padding) {
2020
chartObj.tickCount = categories.length;

src/components/widget/Chart/Line.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import _unzip from 'lodash/unzip';
1414
import _findIndex from 'lodash/findIndex';
1515

1616
const setChartXCount = (chartObj, categories, windowWidth) => () => {
17-
const categoryWordLength = categories?.[0].toString().length * 5;
17+
const categoryWordLength = categories?.[0]?.toString().length * 5;
1818
const padding = 100;
1919
if (windowWidth > categoryWordLength * categories.length + padding) {
2020
chartObj.tickCount = categories.length;

src/utils/dataAnalytics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ export const getBinWidth = (table, categoryIndexes = [], boundary, bin) => {
190190
if (!categoryIndexes.length) {
191191
return '-';
192192
}
193-
let min = Number(table[1][categoryIndexes]) || Number.MAX_SAFE_INTEGER;
194-
let max = Number(table[1][categoryIndexes]) || Number.MIN_SAFE_INTEGER;
193+
let min = Number(table?.[1]?.[categoryIndexes]) || Number.MAX_SAFE_INTEGER;
194+
let max = Number(table?.[1]?.[categoryIndexes]) || Number.MIN_SAFE_INTEGER;
195195
_forEach(categoryIndexes, (index) => {
196196
_forEach(table.slice(1), (row) => {
197197
const value = Number(row[index]);

0 commit comments

Comments
 (0)