Skip to content

Commit

Permalink
fix(geometry): 修改 geometry/base 中存在多个相同的时候,导致索引出错 (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc authored Sep 15, 2020
1 parent 77ac707 commit d0884b0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
6 changes: 5 additions & 1 deletion src/adaptor/geometries/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,9 @@ export function geometry<O extends GeometryOptions>(params: Params<O>): Params<O
.forEach((f: string) => {
chart.legend(f, false);
});
return params;
return {
...params,
// geometry adaptor 额外需要做的事情,就是将创建好的 geometry 返回到下一层 adaptor,防止通过 type 查询的时候容易误判
ext: { geometry },
};
}
35 changes: 19 additions & 16 deletions src/adaptor/geometries/interval.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Geometry } from '@antv/g2';
import { deepMix, isNil } from '@antv/util';
import { Params } from '../../core/adaptor';
import { findGeometry } from '../../utils';
import { GeometryOptions, MappingOptions, geometry } from './base';

export interface IntervalGeometryOptions extends GeometryOptions {
Expand All @@ -27,10 +27,10 @@ export interface IntervalGeometryOptions extends GeometryOptions {
* @param params
*/
function otherAdaptor<O extends IntervalGeometryOptions>(params: Params<O>): Params<O> {
const { chart, options } = params;
const { chart, options, ext } = params;
const { seriesField, isGroup, isStack, marginRatio, widthRatio } = options;

const g = findGeometry(chart, 'interval');
const g = ext.geometry as Geometry;
/**
* adjust
*/
Expand Down Expand Up @@ -64,18 +64,21 @@ export function interval<O extends IntervalGeometryOptions>(params: Params<O>):
const { options } = params;
const { interval, seriesField } = options;

// 如果存在映射才处理
if (interval) {
geometry(
deepMix({}, params, {
options: {
type: 'interval',
colorField: seriesField,
mapping: interval,
},
})
);
}
// 保障一定要存在 interval 映射
const { ext } = interval
? geometry(
deepMix({}, params, {
options: {
type: 'interval',
colorField: seriesField,
mapping: interval,
},
})
)
: params;

return otherAdaptor(params);
return otherAdaptor({
...params,
ext,
});
}
2 changes: 2 additions & 0 deletions src/core/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { View } from '@antv/g2';
export type Params<O> = {
readonly chart: View;
readonly options: O;
/** 一些存储一些扩展信息,用户上游 adaptor 向下游传递临时数据 */
readonly ext?: Record<string, any>;
};

/**
Expand Down

0 comments on commit d0884b0

Please sign in to comment.