Skip to content

Commit

Permalink
feat(vega-scale): add function for testing if a given scale config ob…
Browse files Browse the repository at this point in the history
…ject was officially registered
  • Loading branch information
hydrosquall authored and jheer committed Feb 28, 2023
1 parent c450854 commit 75620ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/vega-scale/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export {

export {
scale,
isRegisteredScale,
isValidScaleType,
isContinuous,
isDiscrete,
Expand Down
12 changes: 11 additions & 1 deletion packages/vega-scale/src/scales.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {array, hasOwnProperty, toSet} from 'vega-util';
import { array, hasOwnProperty, toSet } from 'vega-util';
import invertRange from './scales/invertRange';
import invertRangeExtent from './scales/invertRangeExtent';

Expand Down Expand Up @@ -29,6 +29,15 @@ import * as $ from 'd3-scale';
/** Private scale registry: should not be exported */
const scales = new Map();

const REGISTERED_SCALE_IDENTIFIER = Symbol('registered-scale-marker');

/**
* Return true if object was created by a constructor from the vega-scale `scale` function.
*/
export function isRegisteredScale(maybeScale) {
return maybeScale && maybeScale[REGISTERED_SCALE_IDENTIFIER] === true;
}

/**
* Augment scales with their type and needed inverse methods.
*/
Expand All @@ -42,6 +51,7 @@ function create(type, constructor, metadata) {
: undefined;
}

s[REGISTERED_SCALE_IDENTIFIER] = true;
s.type = type;
return s;
};
Expand Down

0 comments on commit 75620ed

Please sign in to comment.