From 8cbf6a3fad1c3b49b0af2dbf2599254c6f0c07ee Mon Sep 17 00:00:00 2001 From: kartik-gupta-ij Date: Sun, 27 Oct 2024 04:26:48 +0530 Subject: [PATCH] fix[visualize-tab]: add support nested object path in `color_by` parameter for visualiztion tab fixes : #251 --- src/components/VisualizeChart/renderBy.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/VisualizeChart/renderBy.js b/src/components/VisualizeChart/renderBy.js index f979a01a..ec7fe316 100644 --- a/src/components/VisualizeChart/renderBy.js +++ b/src/components/VisualizeChart/renderBy.js @@ -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);