Skip to content

Commit 5d65033

Browse files
authored
feat(sunburst): 旭日图支持图例配置 & 单测 (#3011)
* feat(sunburst): 旭日图支持图例配置 & 单测 * chore: 增加包大小限制
1 parent b52164f commit 5d65033

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Sunburst } from '../../../../src';
2+
import { SUNBRUST_DATA } from '../../../data/sunburst';
3+
import { createDiv } from '../../../utils/dom';
4+
5+
describe('plot legend', () => {
6+
const div = createDiv();
7+
const plot = new Sunburst(div, {
8+
data: SUNBRUST_DATA,
9+
colorField: 'label',
10+
});
11+
plot.render();
12+
13+
it('legend: default is false', () => {
14+
expect(plot.chart.getOptions().legends).toEqual(false);
15+
expect(plot.chart.getComponents().filter((co) => co.type === 'legend').length).toBe(0);
16+
});
17+
18+
it('legend config', () => {
19+
plot.update({
20+
legend: {
21+
position: 'top-left',
22+
},
23+
});
24+
// @ts-ignore
25+
expect(plot.chart.getOptions().legends.label).toEqual({ position: 'top-left' });
26+
expect(plot.chart.getComponents().filter((co) => co.type === 'legend').length).toBe(1);
27+
28+
plot.update({
29+
...plot.options,
30+
legend: {
31+
flipPage: true,
32+
},
33+
});
34+
35+
// @ts-ignore
36+
expect(plot.chart.getOptions().legends.label).toEqual({
37+
position: 'top-left',
38+
flipPage: true,
39+
});
40+
expect(plot.chart.getComponents().filter((co) => co.type === 'legend').length).toBe(1);
41+
});
42+
43+
afterAll(() => {
44+
plot.destroy();
45+
});
46+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"limit-size": [
146146
{
147147
"path": "dist/g2plot.min.js",
148-
"limit": "995 Kb"
148+
"limit": "998 Kb"
149149
},
150150
{
151151
"path": "dist/g2plot.min.js",

src/plots/sunburst/adaptor.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import { isFunction, get, uniq } from '@antv/util';
22
import { Types } from '@antv/g2';
33
import { Params } from '../../core/adaptor';
44
import { polygon as polygonAdaptor } from '../../adaptor/geometries';
5-
import { interaction as baseInteraction, animation, theme, annotation, scale, pattern } from '../../adaptor/common';
5+
import {
6+
interaction as baseInteraction,
7+
animation,
8+
theme,
9+
annotation,
10+
scale,
11+
pattern,
12+
legend,
13+
} from '../../adaptor/common';
614
import { flow, findGeometry, transformLabel, deepAssign } from '../../utils';
715
import { getAdjustAppendPadding } from '../../utils/padding';
816
import { Datum } from '../../types';
@@ -63,18 +71,6 @@ export function axis(params: Params<SunburstOptions>): Params<SunburstOptions> {
6371
return params;
6472
}
6573

66-
/**
67-
* legend 配置(旭日图暂时不支持图例,后续需要支持的话,得自定义数据筛选)
68-
* @param params
69-
* @returns
70-
*/
71-
function legend(params: Params<SunburstOptions>): Params<SunburstOptions> {
72-
const { chart } = params;
73-
74-
chart.legend(false);
75-
return params;
76-
}
77-
7874
/**
7975
* 数据标签
8076
* @param params

src/plots/sunburst/constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const DEFAULT_OPTIONS: Partial<SunburstOptions> = deepAssign({}, Plot.get
4141
offset: 20,
4242
showTitle: false,
4343
},
44+
legend: false,
4445

4546
// 样式设置
4647
sunburstStyle: {

src/plots/sunburst/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ColorAttr, Options, StyleAttr } from '../../types';
22
import { DrillDownCfg } from '../../types/drill-down';
33
import { HierarchyOption } from '../../utils/hierarchy/types';
44

5-
export interface SunburstOptions extends Omit<Options, 'data' | 'legend' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {
5+
export interface SunburstOptions extends Omit<Options, 'data' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {
66
/** 旭日图数据 */
77
readonly data: any;
88
/** 径向类型 */

0 commit comments

Comments
 (0)