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(pie): 修复饼图 title statistic 没有使用 meta formatter #3235

Merged
merged 3 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#### 2.4.18 (2022-06-02)

##### Bug Fixes

* **pie:** 修复饼图 title statistic 没有使用 meta formatter ([165165cc](https://github.com/antvis/G2plot/commit/165165ccb459c603ee3a2bc1a016379141d30283))

##### Tests

* **pie:** add test case for pie statistic ([43402116](https://github.com/antvis/G2plot/commit/434021163bf0f34cda8ebb67aaf1fbe86981d047))

#### 2.4.17 (2022-05-24)

##### New Features
Expand Down
38 changes: 38 additions & 0 deletions __tests__/bugs/pie-statistic-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Pie } from '../../src';
import { createDiv } from '../utils/dom';

const data = [
{ year: '1991', value: 3, count: 10 },
{ year: '1992', value: 4, count: 4 },
{ year: '1993', value: 3.5, count: 5 },
{ year: '1994', value: 5, count: 5 },
{ year: '1995', value: 4.9, count: 4.9 },
{ year: '1996', value: 6, count: 35 },
{ year: '1997', value: 7, count: 7 },
{ year: '1998', value: 9, count: 1 },
{ year: '1999', value: 13, count: 20 },
];

describe('Pie', () => {
it('title statistic using meta formatter', () => {
const plot = new Pie(createDiv(), {
data: [data, data],
colorField: 'year',
angleField: 'value',
innerRadius: 0.4,
statistic: { title: {} },
meta: {
year: {
formatter: () => 'hello',
},
},
});

plot.render();

const htmlAnnotations = document.querySelectorAll('.g2-html-annotation');
expect((htmlAnnotations[0] as HTMLElement).innerText).toBe('hello');

plot.destroy();
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g2plot",
"version": "2.4.17",
"version": "2.4.18",
"description": "An interactive and responsive charting library",
"keywords": [
"chart",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const version = '2.4.17';
export const version = '2.4.18';

// G2 自定义能力透出
import * as G2 from '@antv/g2';
Expand Down
13 changes: 8 additions & 5 deletions src/plots/pie/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,14 @@ export function transformStatisticOptions(options: PieOptions): PieOptions {
{},
{
formatter: (datum: Datum) => {
// 交互中
if (datum) {
return datum[colorField];
}
return !isNil(titleOpt.content) ? titleOpt.content : i18n.get(['statistic', 'total']);
// 交互中, datum existed.
const text = datum
? datum[colorField]
: !isNil(titleOpt.content)
? titleOpt.content
: i18n.get(['statistic', 'total']);
const metaFormatter = get(meta, [colorField, 'formatter']) || ((v) => v);
return metaFormatter(text);
},
},
titleOpt
Expand Down