Skip to content

Commit

Permalink
feat(pie): 饼图 geometry 默认对 elemenent 的 zIndex 进行反序 (#2266)
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky authored Jan 26, 2021
1 parent 510c1b5 commit a5971b6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions __tests__/unit/plots/pie/data-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ describe('饼图 异常数据', () => {

pie.render();

const elements = pie.chart.geometries[0].elements;
const geometry = pie.chart.geometries[0];
const elements = geometry.elements;
expect(elements.length).toBe(5);
expect(every(elements, (ele) => ele.getBBox().width > 0)).toBe(true);
const labels = pie.chart.geometries[0].labelsContainer.getChildren();
const labels = geometry.labelsContainer.getChildren();
expect(every(labels, (label) => (label as IGroup).getChildren()[0].attr('text') === 0)).toBe(true);

// @ts-ignore
expect(geometry.zIndexReversed).toBe(true);
pie.destroy();
});

Expand Down
2 changes: 2 additions & 0 deletions __tests__/unit/plots/pie/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe('pie', () => {
// 绘图数据
expect(elements[0].getModel().style?.fill || elements[0].getModel().color).toBe('blue');
expect(elements[1].getModel().style?.fill || elements[1].getModel().color).toBe('red');
// @ts-ignore
expect(geometry.zIndexReversed).toBe(true);

pie.destroy();
});
Expand Down
10 changes: 10 additions & 0 deletions src/plots/pie/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function geometry(params: Params<PieOptions>): Params<PieOptions> {
color,
style: pieStyle,
},
args: {
zIndexReversed: true,
},
},
});

Expand All @@ -54,6 +57,9 @@ function geometry(params: Params<PieOptions>): Params<PieOptions> {
color,
style: pieStyle,
},
args: {
zIndexReversed: true,
},
},
});

Expand Down Expand Up @@ -201,6 +207,10 @@ export function pieAnnotation(params: Params<PieOptions>): Params<PieOptions> {
return params;
}

/**
* 饼图 tooltip 配置适配,强制 tooltip.shared 为 false
* @param params
*/
function adaptorTooltipOptions(params: Params<PieOptions>): Params<PieOptions> {
return get(params, ['options', 'tooltip']) !== false
? deepAssign({}, params, { options: { tooltip: { shared: false } } })
Expand Down
3 changes: 3 additions & 0 deletions src/plots/pie/contants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Plot } from '../../core/plot';
import { deepAssign } from '../../utils';

/**
* 饼图默认配置项
*/
export const DEFAULT_OPTIONS = deepAssign({}, Plot.getDefaultOptions(), {
legend: {
position: 'right',
Expand Down

0 comments on commit a5971b6

Please sign in to comment.