diff --git a/src/components/VisualizeChart/index.jsx b/src/components/VisualizeChart/index.jsx index bb8c7da4..1b3b1170 100644 --- a/src/components/VisualizeChart/index.jsx +++ b/src/components/VisualizeChart/index.jsx @@ -4,6 +4,7 @@ import Chart from 'chart.js/auto'; import { useSnackbar } from 'notistack'; import { Button } from '@mui/material'; import ViewPointModal from './ViewPointModal'; +import get from 'lodash/get'; const VisualizeChart = ({ scrollResult }) => { const { enqueueSnackbar, closeSnackbar } = useSnackbar(); @@ -44,7 +45,7 @@ const VisualizeChart = ({ scrollResult }) => { const dataset = []; const labelby = scrollResult.data.color_by; if (labelby) { - if (scrollResult.data.result?.points[0]?.payload[labelby] === undefined) { + if (get(scrollResult.data.result?.points[0]?.payload, labelby) === undefined) { enqueueSnackbar(`Visualization Unsuccessful, error: Color by field ${labelby} does not exist`, { variant: 'error', action, @@ -52,7 +53,7 @@ const VisualizeChart = ({ scrollResult }) => { return; } scrollResult.data.labelByArrayUnique = [ - ...new Set(scrollResult.data.result?.points?.map((point) => point.payload[labelby])), + ...new Set(scrollResult.data.result?.points?.map((point) => get(point.payload, labelby))), ]; scrollResult.data.labelByArrayUnique.forEach((label) => { dataset.push({ @@ -95,7 +96,7 @@ const VisualizeChart = ({ scrollResult }) => { }, }, legend: { - display: labelby ? true : false, + display: !!labelby, }, }, }, @@ -132,7 +133,7 @@ const VisualizeChart = ({ scrollResult }) => { variant: 'error', action, }); - return; + } else if (m.data.result && m.data.result.length > 0) { m.data.result.forEach((dataset, index) => { myChart.data.datasets[index].data = dataset.data; diff --git a/src/components/VisualizeChart/worker.js b/src/components/VisualizeChart/worker.js index 42ebed03..8f02db0e 100644 --- a/src/components/VisualizeChart/worker.js +++ b/src/components/VisualizeChart/worker.js @@ -1,5 +1,6 @@ /* eslint-disable no-restricted-globals */ import * as druid from '@saehrimnir/druidjs'; +import get from 'lodash/get'; const MESSAGE_INTERVAL = 200; @@ -67,7 +68,6 @@ self.onmessage = function (e) { } self.postMessage({ result: getDataset(data1, i), error: null }); } - return; }; function getDataset(data, reducedPoint) { @@ -82,7 +82,7 @@ function getDataset(data, reducedPoint) { }); data.result?.points?.forEach((point, index) => { - const label = point.payload[labelby]; + const label = get(point.payload, labelby); dataset[data.labelByArrayUnique.indexOf(label)].data.push({ x: reducedPoint[index][0], y: reducedPoint[index][1],