Skip to content

Commit 6a12bc4

Browse files
authored
docs: api 走查 (#1880)
* docs: api 走查 * fix: conversation
1 parent 4e7e022 commit 6a12bc4

File tree

7 files changed

+168
-16
lines changed

7 files changed

+168
-16
lines changed

__tests__/unit/core/index-spec.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,17 @@ describe('core', () => {
177177
});
178178

179179
it('getChartSize', () => {
180-
const line = new Line(createDiv(), {
180+
createDiv('', document.body, 'changeSize');
181+
document.getElementById('changeSize').style.width = '0px';
182+
const line = new Line('changeSize', {
181183
data: partySupport.filter((o) => o.type === 'FF'),
182184
xField: 'date',
183185
yField: 'value',
184186
});
185187

186188
line.render();
187-
expect(line.chart.height).toBe(300);
188-
189+
expect(line.chart.width).toBe(400);
190+
expect(line.chart.height).toBe(400);
189191
line.destroy();
190192
});
191193
});

__tests__/utils/dom.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* 创建一个 div 节点,并放到 container,默认放到 body 上
33
* @param title
44
* @param container
5+
* @param id 容器 id
56
*/
67
export function createDiv(title: string = '', container: HTMLElement = document.body, id?: string): HTMLElement {
78
const div = document.createElement('div');
@@ -13,10 +14,6 @@ export function createDiv(title: string = '', container: HTMLElement = document.
1314
container.appendChild(titleDiv);
1415
}
1516

16-
if (id) {
17-
div.setAttribute('id', id);
18-
}
19-
2017
container.appendChild(div);
2118

2219
return div;

docs/manual/plots/scatter.en.md

+46-4
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ scatterPlot.render();
7272

7373
点大小映射对应的数据字段名。
7474

75-
#### size
75+
#### size
7676

77-
<description>**optional** \_number | [number, number] | Function_</description>
77+
<description>**optional** \_number | [number, number] | Function\_</description>
7878

7979
[**DEMO1**](../../scatter/basic#color-mapping)
8080

@@ -106,7 +106,7 @@ scatterPlot.render();
106106

107107
点形状映射对应的数据字段名。
108108

109-
#### shape
109+
#### shape
110110

111111
<description>**optional** \_string | string[] | Function\_</description>
112112

@@ -139,7 +139,7 @@ scatterPlot.render();
139139
}
140140
```
141141

142-
#### pointStyle
142+
#### pointStyle
143143

144144
<description>**optional** _object_</description>
145145

@@ -192,6 +192,48 @@ scatterPlot.render();
192192

193193
`markdown:docs/common/component.en.md`
194194

195+
#### quadrant
196+
197+
[**DEMO**](../../scatter/basic#quadrant)
198+
199+
<description>**optional** _object_</description>
200+
201+
四象限组件。
202+
203+
| 细分配置 | 类型 | 功能描述 |
204+
| ----------- | -------- | ------------------------------------------ |
205+
| xBaseline | number | x 方向上的象限分割基准线,默认为 0 |
206+
| yBaseline | number | y 方向上的象限分割基准线,默认为 0 |
207+
| lineStyle | object | 配置象限分割线的样式,详细配置参考绘图属性 |
208+
| regionStyle | object[] | 象限样式,详细配置参考绘图属性 |
209+
| labels | object[] | 象限文本配置,详细配置参考绘图属性 |
210+
211+
#### regressionLine
212+
213+
[**DEMO**](../../scatter/basic#line)
214+
215+
<description>**optional** _object_</description>
216+
217+
回归线。
218+
219+
| 细分配置 | 类型 | 功能描述 |
220+
| --------- | ------------------------------------------------------------------- | ---------------------------------------------------------------- |
221+
| type | string | 回归线类型, exp \| linear \| loess \| log \| poly \| pow \| quad |
222+
| style | object | 配置回归线样式,详细配置参考绘图属性 |
223+
| algorithm | Array<[number, number]> \| ((data: any) => Array<[number, number]>) | 自定义算法,优先级高于 type |
224+
225+
```ts
226+
regressionLine: {
227+
algorithm: () => {
228+
return [
229+
[8, 6],
230+
[16, 7],
231+
[24, 7],
232+
];
233+
},
234+
}
235+
```
236+
195237
### Event
196238

197239
`markdown:docs/common/events.en.md`

docs/manual/plots/scatter.zh.md

+46-4
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ scatterPlot.render();
7272

7373
点大小映射对应的数据字段名。
7474

75-
#### size
75+
#### size
7676

77-
<description>**optional** \_number | [number, number] | Function_</description>
77+
<description>**optional** \_number | [number, number] | Function\_</description>
7878

7979
[**DEMO1**](../../scatter/basic#color-mapping)
8080

@@ -106,7 +106,7 @@ scatterPlot.render();
106106

107107
点形状映射对应的数据字段名。
108108

109-
#### shape
109+
#### shape
110110

111111
<description>**optional** \_string | string[] | Function\_</description>
112112

@@ -139,7 +139,7 @@ scatterPlot.render();
139139
}
140140
```
141141

142-
#### pointStyle
142+
#### pointStyle
143143

144144
<description>**optional** _object_</description>
145145

@@ -192,6 +192,48 @@ scatterPlot.render();
192192

193193
`markdown:docs/common/component.zh.md`
194194

195+
#### quadrant
196+
197+
[**DEMO**](../../scatter/basic#quadrant)
198+
199+
<description>**optional** _object_</description>
200+
201+
四象限组件。
202+
203+
| 细分配置 | 类型 | 功能描述 |
204+
| ----------- | -------- | ------------------------------------------ |
205+
| xBaseline | number | x 方向上的象限分割基准线,默认为 0 |
206+
| yBaseline | number | y 方向上的象限分割基准线,默认为 0 |
207+
| lineStyle | object | 配置象限分割线的样式,详细配置参考绘图属性 |
208+
| regionStyle | object[] | 象限样式,详细配置参考绘图属性 |
209+
| labels | object[] | 象限文本配置,详细配置参考绘图属性 |
210+
211+
#### regressionLine
212+
213+
[**DEMO**](../../scatter/basic#line)
214+
215+
<description>**optional** _object_</description>
216+
217+
回归线。
218+
219+
| 细分配置 | 类型 | 功能描述 |
220+
| --------- | ------------------------------------------------------------------- | ---------------------------------------------------------------- |
221+
| type | string | 回归线类型, exp \| linear \| loess \| log \| poly \| pow \| quad |
222+
| style | object | 配置回归线样式,详细配置参考绘图属性 |
223+
| algorithm | Array<[number, number]> \| ((data: any) => Array<[number, number]>) | 自定义算法,优先级高于 type |
224+
225+
```ts
226+
regressionLine: {
227+
algorithm: () => {
228+
return [
229+
[8, 6],
230+
[16, 7],
231+
[24, 7],
232+
];
233+
},
234+
}
235+
```
236+
195237
### 事件
196238

197239
`markdown:docs/common/events.zh.md`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Scatter, G2 } from '@antv/g2plot';
2+
3+
// 注册主体有 point | interval | polygon | line 等,详细参考 G2: https://g2.antv.vision/
4+
G2.registerShape('point', 'custom-shape', {
5+
draw(cfg, group) {
6+
const cx = cfg.x;
7+
const cy = cfg.y;
8+
const radius = cfg.size || 5;
9+
const polygon = group.addShape('path', {
10+
attrs: {
11+
path: [['M', cx - radius, cy - radius], ['L', cx + radius, cy - radius], ['L', cx, cy + radius], ['Z']],
12+
...cfg.defaultStyle,
13+
...cfg.style,
14+
},
15+
});
16+
return polygon;
17+
},
18+
});
19+
20+
fetch('https://gw.alipayobjects.com/os/bmw-prod/3e4db10a-9da1-4b44-80d8-c128f42764a8.json')
21+
.then((res) => res.json())
22+
.then((data) => {
23+
const scatterPlot = new Scatter('container', {
24+
appendPadding: 30,
25+
data,
26+
xField: 'xG conceded',
27+
yField: 'Shot conceded',
28+
shape: 'custom-shape',
29+
pointStyle: {
30+
lineWidth: 2,
31+
},
32+
size: 6,
33+
yAxis: {
34+
nice: true,
35+
line: {
36+
style: {
37+
stroke: '#aaa',
38+
},
39+
},
40+
},
41+
tooltip: {
42+
showMarkers: false,
43+
},
44+
xAxis: {
45+
grid: {
46+
line: {
47+
style: {
48+
stroke: '#eee',
49+
},
50+
},
51+
},
52+
line: {
53+
style: {
54+
stroke: '#aaa',
55+
},
56+
},
57+
},
58+
label: {},
59+
});
60+
scatterPlot.render();
61+
});

examples/scatter/basic/demo/meta.json

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
"en": "Bubble plot yAxis on the right"
4444
},
4545
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*0luHTJODdMUAAAAAAAAAAAAAARQnAQ"
46+
},
47+
{
48+
"filename": "custom-shape.ts",
49+
"title": {
50+
"zh": "散点图-自定义图形",
51+
"en": "Scatter plot custom shape"
52+
},
53+
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*zfwOTZE7KwcAAAAAAAAAAAAAARQnAQ"
4654
}
4755
]
4856
}

src/core/plot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export abstract class Plot<O extends PickOptions> extends EE {
8383
*/
8484
private getChartSize(width: number, height: number): Size {
8585
const chartSize = getContainerSize(this.container);
86-
return { width: width || chartSize.width, height: height || chartSize.height || 300 };
86+
return { width: width || chartSize.width || 400, height: height || chartSize.height || 400 };
8787
}
8888

8989
/**

0 commit comments

Comments
 (0)