diff --git a/common/changes/@visactor/vchart/fix-bug-for-sampling_2026-04-28-11-20.json b/common/changes/@visactor/vchart/fix-bug-for-sampling_2026-04-28-11-20.json new file mode 100644 index 0000000000..6808a2d5b3 --- /dev/null +++ b/common/changes/@visactor/vchart/fix-bug-for-sampling_2026-04-28-11-20.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vchart", + "comment": "fix: bar smapling not work bug. fix#4571", + "type": "none" + } + ], + "packageName": "@visactor/vchart" +} \ No newline at end of file diff --git a/packages/vchart/__tests__/unit/chart/bar.test.ts b/packages/vchart/__tests__/unit/chart/bar.test.ts index 11a6533772..19f3c85265 100644 --- a/packages/vchart/__tests__/unit/chart/bar.test.ts +++ b/packages/vchart/__tests__/unit/chart/bar.test.ts @@ -149,6 +149,64 @@ describe('Bar chart test', () => { expect(series.fieldX2).toBeUndefined(); }); + test('Bar chart with lttb sampling should keep valid bar data', () => { + const samplingSpec = { + type: 'bar', + data: [ + { + id: 'barData', + values: [ + { month: 'Monday', sales: 22 }, + { month: 'Tuesday', sales: 13 }, + { month: 'Wednesday', sales: 25 }, + { month: 'Thursday', sales: 29 }, + { month: 'Friday', sales: 38 } + ] + } + ], + xField: 'month', + yField: 'sales', + sampling: 'lttb' + }; + const transformer = new BarChart.transformerConstructor({ + type: 'bar', + seriesType: 'bar', + getTheme: getTheme, + mode: 'desktop-browser' + }); + const info = transformer.initChartSpec(samplingSpec as any); + chart = new BarChart( + samplingSpec as any, + { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + eventDispatcher: new EventDispatcher({} as any, { addEventListener: () => {} } as any), + globalInstance: { + isAnimationEnable: () => true, + getContainer: () => ({}), + getTooltipHandlerByUser: (() => undefined) as () => undefined + }, + render: {} as any, + dataSet, + map: new Map(), + container: null, + mode: 'desktop-browser', + getCompiler: getTestCompiler, + globalScale: new GlobalScale([], { getAllSeries: () => [] as any[] } as any), + getTheme: getTheme, + getSpecInfo: () => info + } as any + ); + chart.created(transformer); + chart.init(); + + const series: BarSeries = chart.getAllSeries()[0] as BarSeries; + series.getRegion().setLayoutRect({ width: 500, height: 500 }); + series.compile(); + + expect((series as any)._data.getProduct()).toHaveLength(5); + }); + test('stackCornerRadius should build valid clip paths when barMinHeight is enabled', () => { const stackSpec = { type: 'bar', diff --git a/packages/vchart/src/series/bar/bar.ts b/packages/vchart/src/series/bar/bar.ts index 05c600305a..fb55f93c17 100644 --- a/packages/vchart/src/series/bar/bar.ts +++ b/packages/vchart/src/series/bar/bar.ts @@ -885,7 +885,7 @@ export class BarSeries extends Cartes this._data.setTransform([ { - type: 'sampling', + type: 'dataSampling', size: this._direction === Direction.horizontal ? height : width, factor: this._spec.samplingFactor, yfield: this._direction === Direction.horizontal ? fieldsX[0] : fieldsY[0],