Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(geometry): 修改 geometry/base 中存在多个相同的时候,导致索引出错 #1575

Merged
merged 1 commit into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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