Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
Signed-off-by: Anan Zhuang <[email protected]>
  • Loading branch information
ananzh committed Aug 7, 2024
1 parent 962c949 commit 9807a99
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/plugins/vis_builder/public/visualizations/vega/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,28 @@ const flattenSeries = (
});
};

const flattenHierarchy = (node, id = "0", parentId = null) => {
const flattenHierarchy = (data, parentId = null, parentValue = null, level = 0) => {
let result = [];

// Add current node
result.push({
id: id,
parentId: parentId,
name: node.name,
size: node.size
});

// Process children if they exist
if (node.children && node.children.length > 0) {
node.children.forEach((child, index) => {
result = result.concat(flattenHierarchy(child, `${id}-${index}`, id));

data.forEach((item, index) => {
const currentId = parentId ? `${parentId}-${index}` : `${index}`;

result.push({
id: currentId,
parentId,
name: item.category,
value: item.value,
parentValue,
level,
});
}


if (item.children && item.children.length > 0) {
result = result.concat(flattenHierarchy(item.children, currentId, item.value, level + 1));
}
});

return result;
}
};

export const flattenDataHandler = (context, dimensions, handlerType = 'series') => {
// Currently, our vislib only supports 'series' or 'slices' response types.
Expand All @@ -107,10 +109,10 @@ export const flattenDataHandler = (context, dimensions, handlerType = 'series')
handlerType === 'series' ? vislibSeriesResponseHandler : vislibSlicesResponseHandler;
const converted = handler(context, dimensions);
const group = dimensions.splitRow
? converted.rows
: dimensions.splitColumn
? converted.columns
: [];
? converted.rows
: dimensions.splitColumn
? converted.columns
: [];

if (handlerType === 'series') {
// Determine the group based on split dimensions
Expand All @@ -127,8 +129,7 @@ export const flattenDataHandler = (context, dimensions, handlerType = 'series')
// size: slice.size
// }));
// } else {
converted.series = flatternHierarchy(converted.series)

converted.slices = flattenHierarchy(converted.slices);
}

return converted;
Expand Down

0 comments on commit 9807a99

Please sign in to comment.