SYNC: charts fix

This commit is contained in:
SPRINX0\prochazka
2025-06-19 17:57:01 +02:00
committed by Diflow
parent 28439c010f
commit cd505abb22
3 changed files with 39 additions and 1 deletions

View File

@@ -48,6 +48,7 @@ export interface ChartDefinition {
title?: string;
pieRatioLimit?: number; // limit for pie chart, if the value is below this, it will be grouped into "Other"
pieCountLimit?: number; // limit for number of pie chart slices, if the number of slices is above this, it will be grouped into "Other"
trimXCountLimit?: number; // limit for number of x values, if the number of x values is above this, it will be trimmed
xdef: ChartXFieldDefinition;
ydefs: ChartYFieldDefinition[];

View File

@@ -231,7 +231,7 @@ export class ChartProcessor {
continue;
}
let addedChart: ProcessedChart = chart;
if (chart.rowsAdded == 0) {
if (chart.rowsAdded == 0 && !chart.isGivenDefinition) {
continue; // skip empty charts
}
const sortOrder = chart.definition.xdef.sortOrder ?? 'ascKeys';
@@ -277,6 +277,13 @@ export class ChartProcessor {
};
}
if (
addedChart.definition.trimXCountLimit != null &&
addedChart.bucketKeysOrdered.length > addedChart.definition.trimXCountLimit
) {
addedChart.bucketKeysOrdered = addedChart.bucketKeysOrdered.slice(0, addedChart.definition.trimXCountLimit);
}
if (addedChart) {
addedChart.availableColumns = this.availableColumns;
this.charts.push(addedChart);

View File

@@ -373,4 +373,34 @@ describe('Chart processor', () => {
expect(chart.buckets).toEqual(expectedBuckets);
}
);
test.only('Incorrect chart definition', () => {
const processor = new ChartProcessor([
{
chartType: 'bar',
xdef: {
field: 'category',
transformFunction: 'date:day',
},
ydefs: [],
},
]);
processor.addRows(...DS1.slice(0, 3));
processor.finalize();
expect(processor.charts.length).toEqual(1);
const chart = processor.charts[0];
expect(chart.definition.xdef.transformFunction).toEqual('date:day');
// console.log(getChartDebugPrint(processor.charts[0]));
// expect(chart.definition.xdef.transformFunction).toEqual('date:day');
// expect(chart.definition.ydefs).toEqual([
// expect.objectContaining({
// field: 'value',
// }),
// ]);
// expect(chart.bucketKeysOrdered).toEqual(['2023-10-01', '2023-10-02', '2023-10-03']);
});
});