Skip to content

Commit

Permalink
fix: attr 实例化时不判断数据相关的特征 (#1243)
Browse files Browse the repository at this point in the history
Co-authored-by: zengyue ye <yezengyue@gmail.com>
  • Loading branch information
ACERY1 and zengyue authored Nov 10, 2021
1 parent 4da711a commit d94db4f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/f2/src/attr/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scale } from '@antv/scale';
import { Scale, ScaleConfig } from '@antv/scale';
import { mix, isFunction, isNil, isArray } from '@antv/util';
import { values as arrayValues } from '../util/array';

Expand All @@ -19,7 +19,7 @@ class Base {
}
}

createScale(_scale): Scale {
createScale(scaleConfig: ScaleConfig): Scale {
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/f2/src/attr/category.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Category as CategoryScale } from '@antv/scale';
import { Category as CategoryScale, ScaleConfig } from '@antv/scale';
import Base from './base';

class Category extends Base {
createScale(scale) {
return new CategoryScale(scale);
createScale(scaleConfig: ScaleConfig) {
return new CategoryScale(scaleConfig);
}

_mapping(value: any) {
Expand Down
6 changes: 3 additions & 3 deletions packages/f2/src/attr/identity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Identity as IdentityScale } from '@antv/scale';
import { Identity as IdentityScale, ScaleConfig } from '@antv/scale';
import Base from './base';

class Identity extends Base {
createScale(scale) {
return new IdentityScale(scale);
createScale(scaleConfig: ScaleConfig) {
return new IdentityScale(scaleConfig);
}

_mapping() {
Expand Down
6 changes: 3 additions & 3 deletions packages/f2/src/attr/linear.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Linear as LinearScale } from '@antv/scale';
import { Linear as LinearScale, ScaleConfig } from '@antv/scale';
import { isArray } from '@antv/util';
import Base from './base';

class Linear extends Base {
createScale(scale) {
return new LinearScale(scale);
createScale(scaleConfig: ScaleConfig) {
return new LinearScale(scaleConfig);
}

_mapping(value: any) {
Expand Down
19 changes: 10 additions & 9 deletions packages/f2/src/controller/attr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {
mix,
isNil,
isFunction,
isNumber,
} from '@antv/util';
import { Identity, Linear, Category } from '../attr';
import * as Attrs from '../attr';
import equal from '../base/equal';
import { isArray } from '../util';
import ScaleController from './scale';

const { Identity, Linear, Category } = Attrs;

type AttrOption = {
field: string | Record<any, any>;
range?: any[];
Expand Down Expand Up @@ -59,20 +60,20 @@ class AttrController {
return new Identity(option);
}
const scale = this.scaleController.getScale(field);
const { values } = scale;
const firstValue = values[0];

// identity
if (scale && scale.type === 'identity') {
return new Identity(option);
}


// linear & category
const AttrConstructor = type
? type
: typeof firstValue === 'number'
? Linear
: Category;
let AttrConstructor = Attrs[type] || Category;

if(isFunction(type)) {
AttrConstructor = type;
}

return new AttrConstructor({
...option,
scale,
Expand Down
7 changes: 2 additions & 5 deletions packages/f2/test/components/point/point.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@ describe.skip('Point Chart', () => {
<Point
x="x"
y="y"
color={{
field: 'name',
values: ['#1890ff'],
}}
color="name"
size={{
field: 'z',
range: [10, 40, 60, 80],
range: [10, 20, 30, 40],
}}
/>
</Chart>
Expand Down

0 comments on commit d94db4f

Please sign in to comment.