Skip to content

Commit

Permalink
fix support for several categoris with same name
Browse files Browse the repository at this point in the history
  • Loading branch information
zbigg committed Sep 27, 2023
1 parent 6c0d814 commit 3cc633e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,16 @@ function TimeSeriesWidgetUIContent({
}))
: [{ data: [], color: theme.palette.secondary.main }];

for (const { name, value, category } of data) {
const categoryIndex = categories && category ? categories.indexOf(category) : 0;
if (categoryIndex === -1) continue;
for (const { name, value, category, categoryIndex: _categoryIndex } of data) {
const categoryIndex =
_categoryIndex ?? (categories && category ? categories.indexOf(category) : 0);
if (
categoryIndex === -1 ||
categoryIndex >= categories.length ||
!Number.isFinite(categoryIndex)
) {
continue;
}

series[categoryIndex].data.push([name, value]);
}
Expand All @@ -197,7 +204,7 @@ function TimeSeriesWidgetUIContent({

// If timeWindow is activated
if (timeWindow.length) {
const [start, end] = timeWindow.map(time => new Date(time));
const [start, end] = timeWindow.map((time) => new Date(time));
return formatTimeRange({ start, end, stepSize });
}

Expand Down
8 changes: 4 additions & 4 deletions packages/react-widgets/src/models/TimeSeriesModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ async function getMultipleSeries(props) {
getCategoryForAggregationOperation({ operation, operationColumn, series })
);
const rowsByCategory = await Promise.all(
series.map(async (serie, index) => ({
series.map(async (serie, categoryIndex) => ({
data: (await getTimeSeries({ ...propsNoSeries, ...serie })).rows,
category: categories[index]
categoryIndex
}))
);
const rows = [];
for (const { data, category } of rowsByCategory) {
for (const { data, categoryIndex } of rowsByCategory) {
for (const { name, value } of data) {
rows.push({ name, value, category });
rows.push({ name, value, categoryIndex });
}
}
return {
Expand Down

0 comments on commit 3cc633e

Please sign in to comment.