Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: bar smapling not work bug. fix#4571",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
58 changes: 58 additions & 0 deletions packages/vchart/__tests__/unit/chart/bar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/vchart/src/series/bar/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ export class BarSeries<T extends IBarSeriesSpec = IBarSeriesSpec> 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],
Expand Down
Loading