Skip to content

Commit

Permalink
fix(issue-2216): 饼图默认强制关闭 tooltip shared
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Jan 19, 2021
1 parent bcd2143 commit e330581
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
19 changes: 19 additions & 0 deletions __tests__/unit/plots/pie/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,23 @@ describe('pie', () => {

pie.destroy();
});

it('tooltip, enforce shared to false', () => {
const pie = new Pie(createDiv(), {
width: 400,
height: 300,
data,
angleField: 'value',
colorField: 'type',
tooltip: { shared: true },
});
pie.render();
// @ts-ignore
expect(pie.options.tooltip.shared).toBe(true);

// @ts-ignore
expect(pie.chart.getController('tooltip').getTooltipCfg().shared).toBe(false);

pie.destroy();
});
});
2 changes: 1 addition & 1 deletion src/adaptor/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function theme<O extends Pick<Options, 'theme'>>(params: Params<O>): Para
* 状态 state 配置
* @param params
*/
export function state(params: Params<Options>): Params<Options> {
export function state<O extends Options>(params: Params<O>): Params<O> {
const { chart, options } = params;
const { state } = options;

Expand Down
2 changes: 1 addition & 1 deletion src/plots/multi-view/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type IView = {
readonly region?: Region;

/**
* view 的中数据
* view 中的数据
*/
readonly data: Data;

Expand Down
10 changes: 8 additions & 2 deletions src/plots/pie/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,26 @@ function statistic(params: Params<PieOptions>): Params<PieOptions> {
return params;
}

function adaptorTooltipOptions(params: Params<PieOptions>): Params<PieOptions> {
return get(params, ['options', 'tooltip']) !== false
? deepAssign({}, params, { options: { tooltip: { shared: false } } })
: params;
}

/**
* 饼图适配器
* @param chart
* @param options
*/
export function adaptor(params: Params<PieOptions>) {
// flow 的方式处理所有的配置到 G2 API
return flow(
return flow<Params<PieOptions>>(
geometry,
meta,
theme,
coordinate,
legend,
tooltip,
(args) => tooltip(adaptorTooltipOptions(args)),
label,
state,
annotation(),
Expand Down

0 comments on commit e330581

Please sign in to comment.