Skip to content

Commit

Permalink
fix[visualize-tab]: add support nested object path in color_by para…
Browse files Browse the repository at this point in the history
…meter for visualiztion tab

fixes : #251
  • Loading branch information
kartik-gupta-ij committed Oct 26, 2024
1 parent 681c506 commit 8cbf6a3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/VisualizeChart/renderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ export function generateColorBy(points, colorBy = null) {
colorBy = { payload: colorBy };
}

function getNestedValue(obj, path) {
return path.split('.').reduce((acc, part) => acc && acc[part], obj);
}

if (colorBy.payload) {
const valuesToColor = {};

return points.map((point) => {
const payloadValue = point.payload[colorBy.payload];
if (!payloadValue) {
const payloadValue = getNestedValue(point.payload, colorBy.payload);
if (payloadValue === undefined || payloadValue === null) {
return BACKGROUND_COLOR;
}
return colorByPayload(payloadValue, valuesToColor);
Expand Down

0 comments on commit 8cbf6a3

Please sign in to comment.