-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add plot/vega/scale/discrete
#9538
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
Draft
gururaj1512
wants to merge
3
commits into
stdlib-js:refactor/plot
Choose a base branch
from
gururaj1512:refactor/plot-vega-scale-discrete
base: refactor/plot
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+614
−0
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| var DiscreteScale = require( './../lib' ); | ||
|
|
||
| var scale = new DiscreteScale({ | ||
| 'name': 'xScale', | ||
| 'type': 'ordinal' | ||
| }); | ||
|
|
||
| console.log( scale.toJSON() ); |
41 changes: 41 additions & 0 deletions
41
lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/change_event.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // MAIN // | ||
|
|
||
| /** | ||
| * Returns a new change event object. | ||
| * | ||
| * @private | ||
| * @param {string} property - property name | ||
| * @returns {Object} event object | ||
| */ | ||
| function event( property ) { // eslint-disable-line stdlib/no-redeclare | ||
| return { | ||
| 'type': 'update', | ||
| 'source': 'scale', | ||
| 'property': property | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| module.exports = event; |
43 changes: 43 additions & 0 deletions
43
lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Discrete scale constructor. | ||
| * | ||
| * @module @stdlib/plot/vega/scale/discrete | ||
| * | ||
| * @example | ||
| * var DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' ); | ||
| * | ||
| * var scale = new DiscreteScale({ | ||
| * 'name': 'xScale', | ||
| * 'type': 'ordinal' | ||
| * }); | ||
| * // returns <DiscreteScale> | ||
| */ | ||
|
|
||
| // MODULES // | ||
|
|
||
| var main = require( './main.js' ); | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| module.exports = main; |
200 changes: 200 additions & 0 deletions
200
lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* eslint-disable no-restricted-syntax, no-invalid-this */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // MODULES // | ||
|
|
||
| var logger = require( 'debug' ); | ||
| var isObject = require( '@stdlib/assert/is-object' ); | ||
| var setReadWriteAccessor = require( '@stdlib/utils/define-read-write-accessor' ); | ||
| var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); | ||
| var setNonEnumerableReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); // eslint-disable-line id-length | ||
| var hasProp = require( '@stdlib/assert/has-property' ); | ||
| var inherit = require( '@stdlib/utils/inherit' ); | ||
| var transformErrorMessage = require( '@stdlib/plot/vega/base/transform-validation-message' ); | ||
| var instance2json = require( '@stdlib/plot/vega/base/to-json' ); | ||
| var Scale = require( '@stdlib/plot/vega/scale/base/ctor' ); | ||
| var format = require( '@stdlib/string/format' ); | ||
| var properties = require( './properties.json' ); | ||
|
|
||
| // Note: keep the following in alphabetical order according to the `require` path... | ||
| var getProperties = require( './properties/get.js' ); | ||
|
|
||
| var getType = require( './type/get.js' ); | ||
| var setType = require( './type/set.js' ); | ||
|
|
||
|
|
||
| // VARIABLES // | ||
|
|
||
| var debug = logger( 'vega:discrete-scale:main' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| /** | ||
| * Discrete scale constructor. | ||
| * | ||
| * @constructor | ||
| * @param {Options} options - constructor options | ||
| * @param {string} options.name - scale name | ||
| * @param {string} options.type - scale type | ||
| * @param {(Collection|Object|Signal)} [options.domain] - domain of associated data values | ||
| * @param {number} [options.domainMax] - maximum value in the scale domain (overrides the `domain` option) | ||
| * @param {number} [options.domainMin] - minimum value in the scale domain (overrides the `domain` option) | ||
| * @param {number} [options.domainMid] - single mid-point value inserted into a two-element domain | ||
| * @param {Collection} [options.domainRaw] - array of raw domain values which overrides the `domain` property | ||
| * @param {(string|Object)} [options.interpolate] - scale range interpolation method | ||
| * @param {(Collection|Object|Signal|string)} [options.range] - scale range | ||
| * @param {boolean} [options.reverse=false] - boolean indicating whether to reverse the order of the scale range | ||
| * @param {boolean} [options.round=false] - boolean indicating whether to round numeric output values to integers | ||
| * @throws {TypeError} options argument must be an object | ||
| * @throws {Error} must provide valid options | ||
| * @returns {DiscreteScale} scale instance | ||
| * | ||
| * @example | ||
| * var scale = new DiscreteScale({ | ||
| * 'name': 'xScale', | ||
| * 'type': 'ordinal' | ||
| * }); | ||
| * // returns <DiscreteScale> | ||
| */ | ||
| function DiscreteScale( options ) { | ||
| var v; | ||
| var k; | ||
| var i; | ||
| if ( !( this instanceof DiscreteScale ) ) { | ||
| return new DiscreteScale( options ); | ||
| } | ||
| if ( !isObject( options ) ) { | ||
| throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); | ||
| } | ||
| // Check for required properties... | ||
| if ( !hasProp( options, 'name' ) ) { | ||
| throw new TypeError( 'invalid argument. Options argument must specify the scale name.' ); | ||
| } | ||
| if ( !hasProp( options, 'type' ) ) { | ||
| throw new TypeError( 'invalid argument. Options argument must specify the scale type.' ); | ||
| } | ||
| Scale.call( this, { | ||
| 'name': options.name, | ||
| 'type': options.type | ||
| }); | ||
|
|
||
| // Validate provided options by attempting to assign option values to corresponding fields... | ||
| for ( i = 0; i < properties.length; i++ ) { | ||
| k = properties[ i ]; | ||
| if ( !hasProp( options, k ) ) { | ||
| continue; | ||
| } | ||
| v = options[ k ]; | ||
| try { | ||
| this[ k ] = v; | ||
| } catch ( err ) { | ||
| debug( 'Encountered an error. Error: %s', err.message ); | ||
|
|
||
| // FIXME: retain thrown error type | ||
| throw new Error( transformErrorMessage( err.message ) ); | ||
| } | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /* | ||
| * Inherit from a parent prototype. | ||
| */ | ||
| inherit( DiscreteScale, Scale ); | ||
|
|
||
| /** | ||
| * Constructor name. | ||
| * | ||
| * @private | ||
| * @name name | ||
| * @memberof DiscreteScale | ||
| * @readonly | ||
| * @type {string} | ||
| */ | ||
| setNonEnumerableReadOnly( DiscreteScale, 'name', 'DiscreteScale' ); | ||
|
|
||
| /** | ||
| * Scale properties. | ||
| * | ||
| * @name properties | ||
| * @memberof DiscreteScale.prototype | ||
| * @type {Array<string>} | ||
| * | ||
| * @example | ||
| * var scale = new DiscreteScale({ | ||
| * 'name': 'xScale', | ||
| * 'type': 'ordinal' | ||
| * }); | ||
| * | ||
| * var v = scale.properties; | ||
| * // returns [...] | ||
| */ | ||
| setNonEnumerableReadOnlyAccessor( DiscreteScale.prototype, 'properties', getProperties ); | ||
|
|
||
| /** | ||
| * Scale type. | ||
| * | ||
| * @name type | ||
| * @memberof DiscreteScale.prototype | ||
| * @type {string} | ||
| * | ||
| * @example | ||
| * var scale = new DiscreteScale({ | ||
| * 'name': 'xScale', | ||
| * 'type': 'ordinal' | ||
| * }); | ||
| * | ||
| * var v = scale.type; | ||
| * // returns 'ordinal' | ||
| */ | ||
| setReadWriteAccessor( DiscreteScale.prototype, 'type', getType, setType ); | ||
|
|
||
| /** | ||
| * Serializes an instance to a JSON object. | ||
| * | ||
| * ## Notes | ||
| * | ||
| * - This method is implicitly invoked by `JSON.stringify`. | ||
| * | ||
| * @name toJSON | ||
| * @memberof DiscreteScale.prototype | ||
| * @type {Function} | ||
| * @returns {Object} JSON object | ||
| * | ||
| * @example | ||
| * var scale = new DiscreteScale({ | ||
| * 'name': 'xScale', | ||
| * 'type': 'ordinal' | ||
| * }); | ||
| * | ||
| * var v = scale.toJSON(); | ||
| * // returns {...} | ||
| */ | ||
| setNonEnumerableReadOnly( DiscreteScale.prototype, 'toJSON', function toJSON() { | ||
| return instance2json( this, properties ); | ||
| }); | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| module.exports = DiscreteScale; | ||
13 changes: 13 additions & 0 deletions
13
lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [ | ||
| "domain", | ||
| "domainMax", | ||
| "domainMin", | ||
| "domainMid", | ||
| "domainRaw", | ||
| "interpolate", | ||
| "name", | ||
| "range", | ||
| "reverse", | ||
| "round", | ||
| "type" | ||
| ] |
41 changes: 41 additions & 0 deletions
41
lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties/get.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // MODULES // | ||
|
|
||
| var properties = require( './../properties.json' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| /** | ||
| * Returns the list of enumerable properties. | ||
| * | ||
| * @private | ||
| * @returns {Array<string>} properties | ||
| */ | ||
| function get() { | ||
| return properties.slice(); | ||
| } | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| module.exports = get; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kgryte, I have added
typeproperty as the required property.As linear is default type which lies in the
QuantitativeScale. Is this correct approach?