Skip to content

Commit d022fd4

Browse files
authored
chore: 迷你图走查 + demo (#1528)
* docs(tiny-line): add tiny demos * fix(tiny-line): remove tiny lineStyle callback params * docs(tiny-line): add tiny area demos * docs(tiny-column): add tiny column demos * docs(ring-progress): add tiny ring progress demos * docs(progress): add tiny progress demos * fix(progress): make ci passed
1 parent ff06358 commit d022fd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+954
-552
lines changed

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

+20-17
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ describe('progress', () => {
1919
expect(progress.chart.geometries[0].elements[1].shape.attr('fill')).toBe('#E8EDF3');
2020

2121
progress.update({
22-
width: 200,
23-
height: 100,
22+
...progress.options,
2423
percent: 0.5,
25-
autoFit: false,
2624
});
2725
expect(progress.chart.geometries[0].elements[0].getData().type).toBe('current');
2826
expect(progress.chart.geometries[0].elements[0].getData().percent).toBe(0.5);
@@ -50,11 +48,8 @@ describe('progress', () => {
5048
expect(progress.chart.geometries[0].elements[1].shape.attr('fill')).toBe('#654321');
5149

5250
progress.update({
53-
width: 200,
54-
height: 100,
55-
percent: 0.6,
56-
color: () => ['#654321', '#123456'],
57-
autoFit: false,
51+
...progress.options,
52+
color: ['#654321', '#123456'],
5853
});
5954
expect(progress.chart.geometries[0].elements[0].getData().type).toBe('current');
6055
expect(progress.chart.geometries[0].elements[0].getData().percent).toBe(0.6);
@@ -91,7 +86,7 @@ describe('progress', () => {
9186
expect(progress.chart.geometries[0].elements[1].shape.attr('lineWidth')).toBe(2);
9287
expect(progress.chart.geometries[0].elements[1].shape.attr('lineDash')).toEqual([2, 2]);
9388

94-
const progressStyle = (x, percent, type) => {
89+
const progressStyle = (percent, type) => {
9590
if (type === 'current') {
9691
return percent > 0.5
9792
? {
@@ -120,11 +115,8 @@ describe('progress', () => {
120115
};
121116

122117
progress.update({
123-
width: 200,
124-
height: 100,
125-
percent: 0.6,
118+
...progress.options,
126119
progressStyle,
127-
autoFit: false,
128120
});
129121
expect(progress.chart.geometries[0].elements[0].getData().type).toBe('current');
130122
expect(progress.chart.geometries[0].elements[0].getData().percent).toBe(0.6);
@@ -140,11 +132,8 @@ describe('progress', () => {
140132
expect(progress.chart.geometries[0].elements[1].shape.attr('lineDash')).toEqual([4, 4]);
141133

142134
progress.update({
143-
width: 200,
144-
height: 100,
135+
...progress.options,
145136
percent: 0.4,
146-
progressStyle,
147-
autoFit: false,
148137
});
149138

150139
expect(progress.chart.geometries[0].elements[0].getData().type).toBe('current');
@@ -160,4 +149,18 @@ describe('progress', () => {
160149
expect(progress.chart.geometries[0].elements[1].shape.attr('lineWidth')).toBe(4);
161150
expect(progress.chart.geometries[0].elements[1].shape.attr('lineDash')).toEqual([4, 4]);
162151
});
152+
153+
it('barWidthRatio', () => {
154+
const progress = new Progress(createDiv(), {
155+
width: 200,
156+
height: 100,
157+
percent: 0.6,
158+
barWidthRatio: 0.1,
159+
autoFit: false,
160+
});
161+
162+
progress.render();
163+
164+
expect(progress.chart.getTheme().columnWidthRatio).toBe(0.1);
165+
});
163166
});

__tests__/unit/plots/ring-progress/index-spec.ts

+96-112
Large diffs are not rendered by default.

__tests__/unit/plots/tiny-area/index-spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ describe('tiny-area', () => {
113113
return item.value;
114114
}),
115115
autoFit: false,
116-
tooltip: true,
117116
});
118117

119118
tinyArea.render();
@@ -127,7 +126,7 @@ describe('tiny-area', () => {
127126
expect(tooltipOption.containerTpl).toBe('<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>');
128127
expect(tooltipOption.domStyles).toEqual({
129128
'g2-tooltip': {
130-
padding: '2px',
129+
padding: '2px 4px',
131130
fontSize: '10px',
132131
},
133132
});

__tests__/unit/plots/tiny-column/index-spec.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('tiny-column', () => {
1010
width: 200,
1111
height: 100,
1212
meta: {
13-
value: {
13+
y: {
1414
min: 0,
1515
max: 5000,
1616
},
@@ -86,7 +86,6 @@ describe('tiny-column', () => {
8686
return item.value;
8787
}),
8888
autoFit: false,
89-
tooltip: true,
9089
});
9190

9291
tinyColumn.render();
@@ -100,7 +99,7 @@ describe('tiny-column', () => {
10099
expect(tooltipOption.containerTpl).toBe('<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>');
101100
expect(tooltipOption.domStyles).toEqual({
102101
'g2-tooltip': {
103-
padding: '2px',
102+
padding: '2px 4px',
104103
fontSize: '10px',
105104
},
106105
});
@@ -150,4 +149,27 @@ describe('tiny-column', () => {
150149
expect(geometryTooltipOption.fields).toEqual(['x', 'y']);
151150
expect(geometryTooltipOption.callback(1, '3000')).toEqual({ value: '有3千' });
152151
});
152+
153+
it('columnWidthRatio', () => {
154+
const tinyColumn = new TinyColumn(createDiv(), {
155+
width: 400,
156+
height: 100,
157+
meta: {
158+
y: {
159+
min: 0,
160+
max: 5000,
161+
},
162+
},
163+
data: partySupport
164+
.filter((o) => o.type === 'FF')
165+
.map((item) => {
166+
return item.value;
167+
}),
168+
autoFit: false,
169+
columnWidthRatio: 0.9,
170+
});
171+
172+
tinyColumn.render();
173+
expect(tinyColumn.chart.getTheme().columnWidthRatio).toBe(0.9);
174+
});
153175
});

__tests__/unit/plots/tiny-line/index-spec.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@ describe('tiny-line', () => {
99
const tinyLine = new TinyLine(createDiv(), {
1010
width: 80,
1111
height: 40,
12-
meta: {
13-
value: {
14-
min: 0,
15-
max: 5000,
16-
},
17-
},
1812
data: partySupport
1913
.filter((o) => o.type === 'FF')
2014
.map((item) => {
2115
return item.value;
2216
}),
23-
autoFit: false,
17+
autoFit: true,
2418
});
2519

2620
tinyLine.render();
@@ -32,7 +26,7 @@ describe('tiny-line', () => {
3226
width: 80,
3327
height: 40,
3428
meta: {
35-
value: {
29+
y: {
3630
min: 0,
3731
max: 5000,
3832
},
@@ -42,7 +36,7 @@ describe('tiny-line', () => {
4236
.map((item) => {
4337
return item.value;
4438
}),
45-
autoFit: false,
39+
autoFit: true,
4640
smooth: true,
4741
});
4842

@@ -63,7 +57,11 @@ describe('tiny-line', () => {
6357
lineStyle: {
6458
lineDash: [2, 2],
6559
},
66-
autoFit: false,
60+
tooltip: {
61+
showCrosshairs: true,
62+
showMarkers: true,
63+
},
64+
autoFit: true,
6765
appendPadding: 10,
6866
});
6967

@@ -91,8 +89,7 @@ describe('tiny-line', () => {
9189
.map((item) => {
9290
return item.value;
9391
}),
94-
autoFit: false,
95-
tooltip: true,
92+
autoFit: true,
9693
});
9794

9895
tinyLine.render();
@@ -106,7 +103,7 @@ describe('tiny-line', () => {
106103
expect(tooltipOption.containerTpl).toBe('<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>');
107104
expect(tooltipOption.domStyles).toEqual({
108105
'g2-tooltip': {
109-
padding: '2px',
106+
padding: '2px 4px',
110107
fontSize: '10px',
111108
},
112109
});
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"title": {
3+
"zh": "中文分类",
4+
"en": "Category"
5+
},
6+
"demos": [
7+
{
8+
"filename": "progress.ts",
9+
"title": {
10+
"zh": "迷你进度条图",
11+
"en": "basic Progress chart"
12+
},
13+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*nBhpT5HbGOAAAAAAAAAAAABkARQnAQ"
14+
},
15+
{
16+
"filename": "progress-style.ts",
17+
"title": {
18+
"zh": "迷你进度条图样式",
19+
"en": "Tiny Progress style"
20+
},
21+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*fQihRrLMIWsAAAAAAAAAAABkARQnAQ"
22+
},
23+
{
24+
"filename": "progress-style-callback.ts",
25+
"title": {
26+
"zh": "迷你进度条图回调样式",
27+
"en": "Tiny Progress style callback"
28+
},
29+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*lSOiS4lGCaIAAAAAAAAAAABkARQnAQ"
30+
},
31+
{
32+
"filename": "progress-width.ts",
33+
"title": {
34+
"zh": "迷你进度条图大小",
35+
"en": "Tiny Progress width"
36+
},
37+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*4NmuSaVRZ44AAAAAAAAAAABkARQnAQ"
38+
}
39+
]
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Progress } from '@antv/g2plot';
2+
3+
const progress = new Progress('container', {
4+
height: 100,
5+
width: 300,
6+
autoFit: false,
7+
percent: 0.7,
8+
progressStyle: (percent: number, type: string) => {
9+
if (type === 'current') {
10+
return { fill: 'green' };
11+
}
12+
return { fill: '#999', lineDash: [1, 1], stroke: '#333' };
13+
},
14+
});
15+
16+
progress.render();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Progress } from '@antv/g2plot';
2+
3+
const progress = new Progress('container', {
4+
height: 100,
5+
width: 300,
6+
autoFit: false,
7+
percent: 0.7,
8+
progressStyle: {
9+
stroke: 'grey',
10+
lineDash: [4, 4],
11+
lineWidth: 1,
12+
},
13+
});
14+
15+
progress.render();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Progress } from '@antv/g2plot';
2+
3+
const progress = new Progress('container', {
4+
height: 100,
5+
width: 300,
6+
autoFit: false,
7+
percent: 0.7,
8+
barWidthRatio: 0.1,
9+
});
10+
11+
progress.render();
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Progress } from '@antv/g2plot';
2+
3+
const progress = new Progress('container', {
4+
height: 100,
5+
width: 300,
6+
autoFit: false,
7+
percent: 0.7,
8+
});
9+
10+
progress.render();

examples/progress/basic/design.en.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: 设计规范
3+
---
4+
5+
设计规范

examples/progress/basic/design.zh.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: 设计规范
3+
---
4+
5+
设计规范

examples/progress/basic/index.en.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: 进度条图
3+
order: 0
4+
---

examples/progress/basic/index.zh.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: 进度条图
3+
order: 0
4+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"title": {
3+
"zh": "中文分类",
4+
"en": "Category"
5+
},
6+
"demos": [
7+
{
8+
"filename": "ring-progress.ts",
9+
"title": {
10+
"zh": "迷你进度环图",
11+
"en": "basic Ring chart"
12+
},
13+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*nBhpT5HbGOAAAAAAAAAAAABkARQnAQ"
14+
},
15+
{
16+
"filename": "ring-progress-style.ts",
17+
"title": {
18+
"zh": "迷你进度环图样式",
19+
"en": "Tiny Ring style"
20+
},
21+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*fQihRrLMIWsAAAAAAAAAAABkARQnAQ"
22+
},
23+
{
24+
"filename": "ring-progress-style-callback.ts",
25+
"title": {
26+
"zh": "迷你进度环图回调样式",
27+
"en": "Tiny Ring style callback"
28+
},
29+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*lSOiS4lGCaIAAAAAAAAAAABkARQnAQ"
30+
},
31+
{
32+
"filename": "ring-progress-radius.ts",
33+
"title": {
34+
"zh": "迷你进度环图半径大小",
35+
"en": "Tiny Ring radius"
36+
},
37+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*4NmuSaVRZ44AAAAAAAAAAABkARQnAQ"
38+
}
39+
]
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { RingProgress } from '@antv/g2plot';
2+
3+
const ringProgress = new RingProgress('container', {
4+
height: 100,
5+
width: 100,
6+
autoFit: false,
7+
percent: 0.7,
8+
innerRadius: 0.95,
9+
radius: 0.95,
10+
});
11+
12+
ringProgress.render();

0 commit comments

Comments
 (0)