Skip to content

Commit

Permalink
Merge pull request #108 from VisActor/fix/isvalid-scale-include-thres…
Browse files Browse the repository at this point in the history
…hold

Fix/isvalid scale include threshold
  • Loading branch information
xile611 authored Sep 20, 2023
2 parents e23d33d + dcae132 commit 999dabb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix isValidScale did not include threshold scale\n\n",
"type": "none",
"packageName": "@visactor/vscale"
}
],
"packageName": "@visactor/vscale",
"email": "lixuef1313@163.com"
}
23 changes: 23 additions & 0 deletions packages/vscale/__tests__/common.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { isValidScaleType, ScaleEnum } from '../src/type';

test('scaleLinear() has the expected defaults', function () {
expect(isValidScaleType(ScaleEnum.Identity)).toBe(true);

expect(isValidScaleType(ScaleEnum.Linear)).toBe(true);
expect(isValidScaleType(ScaleEnum.Log)).toBe(true);
expect(isValidScaleType(ScaleEnum.Pow)).toBe(true);
expect(isValidScaleType(ScaleEnum.Sqrt)).toBe(true);
expect(isValidScaleType(ScaleEnum.Symlog)).toBe(true);
expect(isValidScaleType(ScaleEnum.Time)).toBe(true);

expect(isValidScaleType(ScaleEnum.Quantile)).toBe(true);
expect(isValidScaleType(ScaleEnum.Quantize)).toBe(true);
expect(isValidScaleType(ScaleEnum.Threshold)).toBe(true);

expect(isValidScaleType(ScaleEnum.Ordinal)).toBe(true);
expect(isValidScaleType(ScaleEnum.Point)).toBe(true);
expect(isValidScaleType(ScaleEnum.Band)).toBe(true);

expect(isValidScaleType('unknown')).toBe(false);
expect(isValidScaleType('aaaaa')).toBe(false);
});
20 changes: 6 additions & 14 deletions packages/vscale/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export enum ScaleEnum {
// BinOrdinal = 'bin-ordinal',
}

const EnableScaleMap = {};
Object.values(ScaleEnum).forEach(v => {
EnableScaleMap[v] = true;
});

export function isContinuous(type: string) {
switch (type) {
case ScaleEnum.Linear:
Expand All @@ -43,20 +48,7 @@ export function isContinuous(type: string) {
}

export function isValidScaleType(type: string) {
switch (type) {
case ScaleEnum.Linear:
case ScaleEnum.Log:
case ScaleEnum.Pow:
case ScaleEnum.Sqrt:
case ScaleEnum.Symlog:
case ScaleEnum.Time:
case ScaleEnum.Ordinal:
case ScaleEnum.Point:
case ScaleEnum.Band:
return true;
default:
return false;
}
return !!EnableScaleMap[type];
}

export function isDiscrete(type: string) {
Expand Down

0 comments on commit 999dabb

Please sign in to comment.