Skip to content

Commit

Permalink
fix(base): rawFields 添加回调,对 geometry color shape 进行了区分 (#3288)
Browse files Browse the repository at this point in the history
* fix(base): rawFields 添加回调,对 geometry color shape 进行了区分

* fix(base): rawFields 添加回调,对 geometry color shape 进行了区分 -2

Co-authored-by: ai-qing-hai <wb-xcf804241@antgroup.com>
  • Loading branch information
ai-qing-hai and ai-qing-hai committed Jul 28, 2022
1 parent d47118a commit da3d1a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/adaptor/geometries/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { uniq, isFunction, isObject, isString, isNumber, isEmpty } from '@antv/util';
import { Params } from '../../core/adaptor';
import { ColorAttr, ShapeAttr, SizeAttr, StyleAttr, TooltipAttr, Options, Datum } from '../../types';
import { ColorAttr, ShapeAttr, SizeAttr, StyleAttr, TooltipAttr, Options, Datum, RawFields } from '../../types';
import { Label } from '../../types/label';
import { State } from '../../types/state';
import { transformLabel } from '../../utils';
Expand Down Expand Up @@ -43,7 +43,7 @@ export type Geometry = {
/** tooltip 的映射字段 */
readonly tooltipFields?: string[] | false;
/** 其他原始字段, 用于 mapping 回调参数 */
readonly rawFields?: string[];
readonly rawFields?: RawFields;
/** 图形映射规则 */
readonly mapping?: MappingOptions;
/** label 映射通道,因为历史原因导致实现略有区别 */
Expand Down Expand Up @@ -73,9 +73,11 @@ export function getMappingField(
mappingFields: string[];
tileMappingField: string;
} {
const { type, xField, yField, colorField, shapeField, sizeField, styleField, rawFields = [] } = o;
const { type, xField, yField, colorField, shapeField, sizeField, styleField } = o;
let { rawFields } = o;

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

// 因为 color 会影响到数据分组,以及最后的图形映射。所以导致 bar 图中的 widthRatio 设置不生效
// 所以对于 color 字段,仅仅保留 colorField 好了! + rawFields
Expand Down
2 changes: 2 additions & 0 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,5 @@ export type Options = {
*/
readonly defaultInteractions?: string[];
};

export type RawFields = string[] | ((type: string, field: 'color' | 'shape' | 'size' | 'style') => string[] | never);

0 comments on commit da3d1a6

Please sign in to comment.