Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(heatmap): 修复色力图 coordinate部分配置不起效 和 配置了 refect coordinate 失效的问题 #3294

Merged
merged 6 commits into from
Jul 28, 2022
36 changes: 36 additions & 0 deletions __tests__/unit/plots/heatmap/coordinate-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,40 @@ describe('heatmap', () => {

heatmap.destroy();
});

it('coordinate reflect', () => {
const coordinate = {
type: 'polar',
cfg: {
radius: 0.85,
innerRadius: 0.2,
},
actions: [['scale', 0.5, -1]],
} as any;

const heatmap = new Heatmap(createDiv('custom axis'), {
width: 400,
height: 300,
data: semanticBasicHeatmapData,
xField: 'name',
yField: 'day',
colorField: 'sales',
shape: 'circle',
coordinate,
reflect: 'x',
});

heatmap.render();

// @ts-ignore
expect(heatmap.chart.options.coordinate).toMatchObject({
...coordinate,
actions: [
['scale', 0.5, -1],
['reflect', 'x'],
],
});

heatmap.destroy();
});
});
11 changes: 4 additions & 7 deletions src/plots/heatmap/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,14 @@ function coordinate(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
const { chart, options } = params;
const { coordinate, reflect } = options;

if (coordinate) {
chart.coordinate({
type: coordinate.type || 'rect',
cfg: coordinate.cfg,
});
}
const coordinateOption = deepAssign({ actions: [] }, coordinate ?? { type: 'rect' });

if (reflect) {
chart.coordinate().reflect(reflect);
coordinateOption.actions?.push?.(['reflect', reflect]);
}

chart.coordinate(coordinateOption);

return params;
}

Expand Down