Skip to content

Commit 70bab7c

Browse files
authored
refactor: sunburst 重构和优化 (#2603)
* refactor(hierarchy-utils): 优化 partition 算法 * refactor(sunburst): 重构下旭日图 - [x] style - [x] tooltip - [x] data - [ ] label 待办 * docs(sunburst): 增加若干旭日图 demo * test(sunburst): 暂时修复下旭日图单测 * feat(sunburst): 旭日图 tooltip、label & 文档完善 * test(sunburst): 旭日图增加单测 * docs: 增加 faq * fix(lint): 修复 lint 问题 * docs(sunburst): 移除无用的类型定义 & 增加 rawFields 配置文档 * fix(sunburst): 修复旭日图 cr 和 lint 问题
1 parent 937e365 commit 70bab7c

31 files changed

+1071
-422
lines changed

__tests__/bugs/issue-2572-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('#2572', () => {
143143
it('堆叠分组柱状图 tooltip 更新 formatter', () => {
144144
plot.update({
145145
tooltip: {
146-
formatter: (datum) => ({ name: 'xx', value: 100 }),
146+
formatter: () => ({ name: 'xx', value: 100 }),
147147
},
148148
});
149149
plot.chart.showTooltip(point);

__tests__/data/sunburst.ts

+134
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,137 @@ export const SUNBRUST_DATA = {
562562
},
563563
],
564564
};
565+
566+
export const SIMPLE_SUNBURST_DATA = {
567+
name: 'root',
568+
children: [
569+
{
570+
name: '非洲',
571+
value: 4,
572+
children: [
573+
{
574+
continent: '非洲',
575+
country: '埃塞俄比亚',
576+
symbol: '🇪🇹',
577+
area: '耶加雪菲',
578+
name: '埃塞俄比亚',
579+
value: 1,
580+
},
581+
{
582+
continent: '非洲',
583+
country: '肯尼亚',
584+
symbol: '🇰🇪',
585+
coffee: '阿拉比加卡豆',
586+
name: '肯尼亚',
587+
value: 1,
588+
},
589+
{
590+
continent: '非洲',
591+
country: '坦桑尼亚',
592+
symbol: '🇹🇿',
593+
coffee: '乞力马扎罗咖啡',
594+
name: '坦桑尼亚',
595+
value: 1,
596+
},
597+
{
598+
continent: '非洲',
599+
country: '乌干达',
600+
symbol: '🇺🇬',
601+
name: '乌干达',
602+
value: 1,
603+
},
604+
],
605+
},
606+
{
607+
name: '中南美洲',
608+
value: 6,
609+
children: [
610+
{
611+
continent: '中南美洲',
612+
country: '巴西',
613+
symbol: '🇧🇷',
614+
name: '巴西',
615+
value: 1,
616+
},
617+
{
618+
continent: '中南美洲',
619+
country: '哥伦比亚',
620+
symbol: '🇨🇴',
621+
name: '哥伦比亚',
622+
value: 1,
623+
},
624+
{
625+
continent: '中南美洲',
626+
country: '牙买加',
627+
symbol: '🇯🇲',
628+
name: '牙买加',
629+
value: 1,
630+
},
631+
{
632+
continent: '中南美洲',
633+
country: '巴拿马',
634+
symbol: '🇵🇦',
635+
name: '巴拿马',
636+
value: 1,
637+
},
638+
{
639+
continent: '中南美洲',
640+
country: '危地马拉',
641+
symbol: '🇬🇹',
642+
name: '危地马拉',
643+
value: 1,
644+
},
645+
{
646+
continent: '中南美洲',
647+
country: '哥斯达黎加',
648+
symbol: '🇨🇷',
649+
name: '哥斯达黎加',
650+
value: 1,
651+
},
652+
],
653+
},
654+
{
655+
name: '亚洲',
656+
value: 5,
657+
children: [
658+
{
659+
continent: '亚洲',
660+
country: '印度尼西亚',
661+
symbol: '🇮🇩',
662+
area: '苏门答腊',
663+
coffee: '曼特宁咖啡',
664+
name: '印度尼西亚',
665+
value: 1,
666+
},
667+
{
668+
continent: '亚洲',
669+
country: '印度',
670+
symbol: '🇮🇳',
671+
name: '印度',
672+
value: 1,
673+
},
674+
{
675+
continent: '亚洲',
676+
country: '越南',
677+
symbol: '🇻🇳',
678+
name: '越南',
679+
value: 1,
680+
},
681+
{
682+
continent: '亚洲',
683+
country: '也门',
684+
symbol: '🇾🇪',
685+
name: '也门',
686+
value: 1,
687+
},
688+
{
689+
continent: '亚洲',
690+
country: '中国',
691+
symbol: '🇨🇳',
692+
name: '中国',
693+
value: 1,
694+
},
695+
],
696+
},
697+
],
698+
};

__tests__/unit/plots/facet/geometries-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('facet', () => {
2121
data,
2222
type: 'rect',
2323
fields: ['type'],
24-
eachView: (view, facet) => {
24+
eachView: () => {
2525
return {
2626
geometries: [
2727
{ type: 'interval', xField: 'date', yField: 'value', colorField: 'name', mapping: {} },

__tests__/unit/plots/facet/index-spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('facet', () => {
2222
data,
2323
type: 'rect',
2424
fields: ['type'],
25-
eachView: (view, facet) => {
25+
eachView: () => {
2626
return { geometries: [{ type: 'interval', xField: 'date', yField: 'value', colorField: 'name', mapping: {} }] };
2727
},
2828
theme: {
@@ -62,7 +62,7 @@ describe('facet', () => {
6262
meta: { name: { sync: true, values: ['d', 'c', 'b', 'a'] } },
6363
});
6464

65-
const [view0, view1, view2, view3] = plot.chart.views;
65+
const [view0, , view2, view3] = plot.chart.views;
6666
expect(view0.geometries[0].elements[0].getModel().color).toBe('red');
6767
const data0 = view0.geometries[0].elements[0].getModel().data as any;
6868
const data1 = view0.geometries[0].elements[1].getModel().data as any;
@@ -167,7 +167,7 @@ describe('facet', () => {
167167
expect(element1.shape.attr('stroke')).not.toBe('#000');
168168

169169
plot.update({
170-
eachView: (view, facet) => {
170+
eachView: () => {
171171
return {
172172
geometries: [{ type: 'interval', xField: 'date', yField: 'value', colorField: 'name', mapping: {} }],
173173
interactions: [{ type: 'element-active', enable: false }],

__tests__/unit/plots/stock/style-spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ describe('Stock', () => {
1818

1919
k.render();
2020

21-
const geometry = k.chart.geometries[0];
22-
2321
// 图形元素个数
2422
expect(k.chart.geometries[0].elements[0].shape.attr('stroke')).toBe('red');
2523
expect(k.chart.geometries[0].elements[0].shape.attr('lineWidth')).toBe(2);

__tests__/unit/plots/sunburst/change-data-spec.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { delay } from '../../../utils/delay';
44
import { SUNBRUST_DATA } from '../../../data/sunburst';
55

66
describe('sunburst', () => {
7-
it('init: change data', async () => {
7+
it('旧版本', async () => {
88
const sunburstPlot = new Sunburst(createDiv(), {
99
width: 400,
1010
height: 400,
1111
data: [],
12+
// @ts-ignore
1213
seriesField: 'sum',
1314
colorField: 'value',
1415
color: ['#BAE7FF', '#1890FF', '#0050B3'],
@@ -30,7 +31,8 @@ describe('sunburst', () => {
3031
labelOption: { fields, cfg },
3132
coordinate,
3233
} = geometry;
33-
expect(fields).toEqual(['sum']);
34+
// 默认展示 name(不进行兼容))
35+
expect(fields).toEqual(['name']);
3436
expect(cfg.position).toBe('middle');
3537
const positionFields = geometry.getAttribute('position').getFields();
3638
expect(geometry.elements.length).toBe(geometry.data.length);
@@ -42,11 +44,12 @@ describe('sunburst', () => {
4244
sunburstPlot.destroy();
4345
});
4446

45-
it('init: update', async () => {
47+
it('旧版本: update', async () => {
4648
const sunburstPlot = new Sunburst(createDiv(), {
4749
width: 400,
4850
height: 400,
4951
data: SUNBRUST_DATA,
52+
// @ts-ignore
5053
seriesField: 'sum',
5154
innerRadius: 0.3,
5255
radius: 1,
@@ -63,7 +66,8 @@ describe('sunburst', () => {
6366
labelOption: { fields },
6467
coordinate,
6568
} = geometry;
66-
expect(fields).toEqual(['sum']);
69+
// 默认展示 name(不进行兼容))
70+
expect(fields).toEqual(['name']);
6771
expect(coordinate.innerRadius).toBe(0.3);
6872
// @ts-ignore
6973
sunburstPlot.update({

0 commit comments

Comments
 (0)