Skip to content

Commit ae12f6e

Browse files
lxfu1liufu.lf
and
liufu.lf
authored
fix: 修改 scatter 写法 (#1456)
Co-authored-by: liufu.lf <[email protected]>
1 parent 076c758 commit ae12f6e

File tree

3 files changed

+29
-50
lines changed

3 files changed

+29
-50
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"site:develop": "cross-env PORT=8080 gatsby develop --open -H 0.0.0.0",
2828
"site:build": "npm run site:clean && gatsby build --prefix-paths",
2929
"site:clean": "gatsby clean",
30-
"site:deploy": "npm run doc && npm run site:build && gh-pages -d public",
30+
"site:deploy": "npm run site:build && gh-pages -d public",
3131
"fix": "eslint --ext .ts ./src ./__tests__ --fix && prettier --write ./src ./__tests__",
3232
"build": "run-s clean lib dist",
3333
"clean": "rimraf lib esm dist",

src/plots/scatter/adaptor.ts

+28-24
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { deepMix, isFunction } from '@antv/util';
1+
import { deepMix, isFunction, isNumber, isString } from '@antv/util';
22
import { Params } from '../../core/adaptor';
3-
import { flow, pick, log, LEVEL } from '../../utils';
3+
import { flow, pick } from '../../utils';
44
import { ScatterOptions } from './types';
55
import { tooltip, interaction, animation, theme } from '../../adaptor/common';
66
import { findGeometry } from '../../utils';
77
import { AXIS_META_CONFIG_KEYS } from '../../constant';
8-
import { REFLECTS } from './reflect';
98

109
/**
1110
* 字段
1211
* @param params
1312
*/
1413
function field(params: Params<ScatterOptions>): Params<ScatterOptions> {
1514
const { chart, options } = params;
16-
const { data, xField, yField, type } = options;
15+
const { data, xField, yField, type, color, colorField, shape, shapeField, size, sizeField } = options;
1716

1817
// 散点图操作逻辑
1918
chart.data(data);
@@ -24,27 +23,32 @@ function field(params: Params<ScatterOptions>): Params<ScatterOptions> {
2423
geometry.adjust(type);
2524
}
2625

27-
// 统一处理 color、 size、 shape
28-
const reflectKeys = Object.keys(REFLECTS);
29-
reflectKeys.forEach((key: string) => {
30-
if (options[key] || options[REFLECTS[key].field]) {
31-
let validateRules = false;
32-
(REFLECTS[key].rules || []).forEach((fn: (arg: any) => boolean) => {
33-
// 满足任一规则即可
34-
if (fn && fn(options[key])) {
35-
validateRules = true;
36-
}
37-
});
38-
if (validateRules) {
39-
if (!options[REFLECTS[key].field]) {
40-
log(LEVEL.WARN, false, '*** For accurate mapping, specify %s please. ***', REFLECTS[key].field);
41-
}
42-
geometry[REFLECTS[key].action](options[REFLECTS[key].field] || xField, options[key]);
43-
} else {
44-
geometry[REFLECTS[key].action](options[key] || options[REFLECTS[key].field]);
45-
}
26+
// shape
27+
if (shape) {
28+
if (isString(shape)) {
29+
geometry.shape(shape);
30+
} else {
31+
geometry.shape(shapeField || xField, shape);
4632
}
47-
});
33+
}
34+
35+
// color
36+
if (color) {
37+
if (isString(color)) {
38+
geometry.color(color);
39+
} else {
40+
geometry.color(colorField || xField, color);
41+
}
42+
}
43+
44+
// size
45+
if (size) {
46+
if (isNumber(size)) {
47+
geometry.size(size);
48+
} else {
49+
geometry.size(sizeField || xField, size);
50+
}
51+
}
4852

4953
return params;
5054
}

src/plots/scatter/reflect.ts

-25
This file was deleted.

0 commit comments

Comments
 (0)