Skip to content

Commit

Permalink
Fix performance part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Jul 8, 2022
1 parent 795ef97 commit ea7c941
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,21 @@ export const getLegendAction = (

const { table } = layer;

const data = [...series.splitAccessors].reduce<FilterEvent['data']['data']>(
(acc, [accessor, value]) => {
const rowIndex = table.rows.findIndex((row) => {
return row[accessor] === value;
});
if (rowIndex !== -1) {
return [
...acc,
{
row: rowIndex,
column: table.columns.findIndex((column) => column.id === accessor),
value: table.rows[rowIndex][accessor],
table,
},
];
}
const data: FilterEvent['data']['data'] = [];

return acc;
},
[]
);
series.splitAccessors.forEach((value, accessor) => {
const rowIndex = table.rows.findIndex((row) => {
return row[accessor] === value;
});
if (rowIndex !== -1) {
data.push({
row: rowIndex,
column: table.columns.findIndex((column) => column.id === accessor),
value: table.rows[rowIndex][accessor],
table,
});
}
});

if (data.length === 0) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,30 +509,22 @@ export function XYChart({
},
];

let splitPoints: FilterEvent['data']['data'] = [];
const splitPoints: FilterEvent['data']['data'] = [];

if (xySeries.seriesKeys.length > 1) {
splitPoints = [...xySeries.splitAccessors].reduce<FilterEvent['data']['data']>(
(acc, [accessor, value]) => {
const splitPointRowIndex = table.rows.findIndex((row) => {
return row[accessor] === value;
xySeries.splitAccessors.forEach((value, accessor) => {
const splitPointRowIndex = table.rows.findIndex((row) => {
return row[accessor] === value;
});
if (splitPointRowIndex !== -1) {
splitPoints.push({
row: splitPointRowIndex,
column: table.columns.findIndex((column) => column.id === accessor),
value: table.rows[splitPointRowIndex][accessor],
table,
});
if (splitPointRowIndex !== -1) {
return [
...acc,
{
row: splitPointRowIndex,
column: table.columns.findIndex((column) => column.id === accessor),
value: table.rows[splitPointRowIndex][accessor],
table,
},
];
}

return acc;
},
[]
);
}
});
}
const context: FilterEvent['data'] = {
data: [...points, ...splitPoints],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,26 @@ export const getAllSeries = (

const columnToLabelMap = columnToLabel ? JSON.parse(columnToLabel) : {};

return formattedDatatable.table.rows.reduce<string[]>((acc, row) => {
const allSeries: string[] = [];

formattedDatatable.table.rows.forEach((row) => {
const splitName = getSplitName(splitAccessors, formattedDatatable, row, fieldFormats);

const allRowSeries = accessors.reduce<string[]>((names, accessor) => {
accessors.forEach((accessor) => {
const yAccessor = getAccessorByDimension(accessor, formattedDatatable.table.columns);
const yTitle = columnToLabelMap[yAccessor] ?? titles?.yTitles?.[yAccessor] ?? null;
let name = yTitle;
if (splitName) {
name = accessors.length > 1 ? `${splitName} - ${yTitle}` : splitName;
}

return names.includes(name) ? names : [...names, name];
}, []);
if (!allSeries.includes(name)) {
allSeries.push(name);
}
});
});

// need only uniq values
return [...new Set([...acc, ...allRowSeries])];
}, []);
return allSeries;
};

export function getColorAssignments(
Expand Down

0 comments on commit ea7c941

Please sign in to comment.