diff --git a/common/changes/@visactor/vscale/fix-identity-scale_2023-08-29-08-09.json b/common/changes/@visactor/vscale/fix-identity-scale_2023-08-29-08-09.json new file mode 100644 index 0000000..3f0e84b --- /dev/null +++ b/common/changes/@visactor/vscale/fix-identity-scale_2023-08-29-08-09.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix(vscale): identity scale may have no domain\n\n", + "type": "none", + "packageName": "@visactor/vscale" + } + ], + "packageName": "@visactor/vscale", + "email": "dingling112@gmail.com" +} \ No newline at end of file diff --git a/packages/vscale/__tests__/identity-scale.test.ts b/packages/vscale/__tests__/identity-scale.test.ts index 66d3c55..94f005d 100644 --- a/packages/vscale/__tests__/identity-scale.test.ts +++ b/packages/vscale/__tests__/identity-scale.test.ts @@ -3,6 +3,8 @@ import { IdentityScale } from '../src/identity-scale'; test('IdentityScale of any values', () => { const scale = new IdentityScale(); + expect(scale.domain()).toBeUndefined(); + expect(scale.range()).toBeUndefined(); expect(scale.scale('x')).toBe('x'); expect(scale.scale(12)).toBe(12); }); diff --git a/packages/vscale/src/identity-scale.ts b/packages/vscale/src/identity-scale.ts index f6f4063..d205889 100644 --- a/packages/vscale/src/identity-scale.ts +++ b/packages/vscale/src/identity-scale.ts @@ -54,7 +54,7 @@ export class IdentityScale implements IBaseScale { domain(_: any[]): this; domain(_?: any[]): this | any { if (!_) { - return this._domain.slice(); + return this._domain ? this._domain.slice() : undefined; } this._domain = _; @@ -65,7 +65,7 @@ export class IdentityScale implements IBaseScale { range(_: any[]): this; range(_?: any[]): this | any { if (!_) { - return this._domain.slice(); + return this._domain ? this._domain.slice() : undefined; } return this;