Skip to content

Commit da3d1a6

Browse files
authored
fix(base): rawFields 添加回调,对 geometry color shape 进行了区分 (#3288)
* fix(base): rawFields 添加回调,对 geometry color shape 进行了区分 * fix(base): rawFields 添加回调,对 geometry color shape 进行了区分 -2 Co-authored-by: ai-qing-hai <[email protected]>
1 parent d47118a commit da3d1a6

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/adaptor/geometries/base.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { uniq, isFunction, isObject, isString, isNumber, isEmpty } from '@antv/util';
22
import { Params } from '../../core/adaptor';
3-
import { ColorAttr, ShapeAttr, SizeAttr, StyleAttr, TooltipAttr, Options, Datum } from '../../types';
3+
import { ColorAttr, ShapeAttr, SizeAttr, StyleAttr, TooltipAttr, Options, Datum, RawFields } from '../../types';
44
import { Label } from '../../types/label';
55
import { State } from '../../types/state';
66
import { transformLabel } from '../../utils';
@@ -43,7 +43,7 @@ export type Geometry = {
4343
/** tooltip 的映射字段 */
4444
readonly tooltipFields?: string[] | false;
4545
/** 其他原始字段, 用于 mapping 回调参数 */
46-
readonly rawFields?: string[];
46+
readonly rawFields?: RawFields;
4747
/** 图形映射规则 */
4848
readonly mapping?: MappingOptions;
4949
/** label 映射通道,因为历史原因导致实现略有区别 */
@@ -73,9 +73,11 @@ export function getMappingField(
7373
mappingFields: string[];
7474
tileMappingField: string;
7575
} {
76-
const { type, xField, yField, colorField, shapeField, sizeField, styleField, rawFields = [] } = o;
76+
const { type, xField, yField, colorField, shapeField, sizeField, styleField } = o;
77+
let { rawFields } = o;
7778

7879
let fields = [];
80+
rawFields = (isFunction(rawFields) ? rawFields(type, field) : rawFields) || [];
7981

8082
// 因为 color 会影响到数据分组,以及最后的图形映射。所以导致 bar 图中的 widthRatio 设置不生效
8183
// 所以对于 color 字段,仅仅保留 colorField 好了! + rawFields

src/types/common.ts

+2
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,5 @@ export type Options = {
249249
*/
250250
readonly defaultInteractions?: string[];
251251
};
252+
253+
export type RawFields = string[] | ((type: string, field: 'color' | 'shape' | 'size' | 'style') => string[] | never);

0 commit comments

Comments
 (0)