Skip to content

Commit

Permalink
feat(VisualizeChart): add support object path for color_by fixed #101
Browse files Browse the repository at this point in the history
… (#102)

Co-authored-by: Ivan Zhuravlev <[email protected]>
  • Loading branch information
intech and Ivan Zhuravlev authored Aug 21, 2023
1 parent f63d93d commit fdb3c44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/components/VisualizeChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -44,15 +45,15 @@ 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,
});
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({
Expand Down Expand Up @@ -95,7 +96,7 @@ const VisualizeChart = ({ scrollResult }) => {
},
},
legend: {
display: labelby ? true : false,
display: !!labelby,
},
},
},
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/components/VisualizeChart/worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-restricted-globals */
import * as druid from '@saehrimnir/druidjs';
import get from 'lodash/get';

const MESSAGE_INTERVAL = 200;

Expand Down Expand Up @@ -67,7 +68,6 @@ self.onmessage = function (e) {
}
self.postMessage({ result: getDataset(data1, i), error: null });
}
return;
};

function getDataset(data, reducedPoint) {
Expand All @@ -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],
Expand Down

0 comments on commit fdb3c44

Please sign in to comment.