From 491a90948e8d89f54c6758d30020ab48e6d2d7f2 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sun, 4 Jan 2026 20:01:40 +0530 Subject: [PATCH 1/3] feat: add plot/vega/scale/discrete --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../vega/scale/discrete/examples/index.js | 28 +++ .../vega/scale/discrete/lib/change_event.js | 41 ++++ .../plot/vega/scale/discrete/lib/index.js | 43 ++++ .../plot/vega/scale/discrete/lib/main.js | 200 ++++++++++++++++++ .../vega/scale/discrete/lib/properties.json | 13 ++ .../vega/scale/discrete/lib/properties/get.js | 41 ++++ .../plot/vega/scale/discrete/lib/type/get.js | 43 ++++ .../scale/discrete/lib/type/properties.js | 33 +++ .../plot/vega/scale/discrete/lib/type/set.js | 63 ++++++ .../plot/vega/scale/discrete/package.json | 61 ++++++ 10 files changed, 566 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/change_event.js create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties.json create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/package.json diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js new file mode 100644 index 000000000000..5f3b1e98caf9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js @@ -0,0 +1,28 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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() ); diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/change_event.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/change_event.js new file mode 100644 index 000000000000..730718cd6454 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/change_event.js @@ -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; diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js new file mode 100644 index 000000000000..dd8bc841a54a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js @@ -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 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js new file mode 100644 index 000000000000..d705672e65ac --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js @@ -0,0 +1,200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 +*/ +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} +* +* @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; diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties.json b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties.json new file mode 100644 index 000000000000..9bea25e4e1b6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties.json @@ -0,0 +1,13 @@ +[ + "domain", + "domainMax", + "domainMin", + "domainMid", + "domainRaw", + "interpolate", + "name", + "range", + "reverse", + "round", + "type" +] diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties/get.js new file mode 100644 index 000000000000..f3cbb28454ea --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/properties/get.js @@ -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} properties +*/ +function get() { + return properties.slice(); +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/get.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/get.js new file mode 100644 index 000000000000..980667aae73b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/get.js @@ -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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var prop = require( './properties.js' ); + + +// MAIN // + +/** +* Returns the scale type. +* +* @private +* @returns {string} scale type +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/properties.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/properties.js new file mode 100644 index 000000000000..d111b590ade9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/properties.js @@ -0,0 +1,33 @@ +/** +* @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 property2object = require( '@stdlib/plot/vega/base/property2object' ); + + +// MAIN // + +var obj = property2object( 'type' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/set.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/set.js new file mode 100644 index 000000000000..54978b45f03a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/type/set.js @@ -0,0 +1,63 @@ +/** +* @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-invalid-this */ + +'use strict'; + +// MODULES // + +var logger = require( 'debug' ); +var isDiscreteScaleName = require( '@stdlib/plot/vega/base/assert/is-discrete-scale-name' ); +var join = require( '@stdlib/array/base/join' ); +var scales = require( '@stdlib/plot/vega/scale/names' ); +var format = require( '@stdlib/string/format' ); +var changeEvent = require( './../change_event.js' ); +var prop = require( './properties.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:discrete-scale:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the scale type. +* +* @private +* @param {string} value - input value +* @throws {TypeError} must be a valid scale +* @returns {void} +*/ +function set( value ) { + if ( !isDiscreteScaleName( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( scales( 'discrete' ), '", "' ), value ) ); + } + if ( value !== this[ prop.private ] ) { + debug( 'Current value: %s. New value: %s.', this[ prop.private ], value ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/package.json b/lib/node_modules/@stdlib/plot/vega/scale/discrete/package.json new file mode 100644 index 000000000000..1b9262dcfa13 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/package.json @@ -0,0 +1,61 @@ +{ + "name": "@stdlib/plot/vega/scale/discrete", + "version": "0.0.0", + "description": "Discrete scale constructor.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "plot", + "vega", + "scale", + "discrete", + "constructor", + "ctor" + ], + "__stdlib__": {} +} From ee5f99e7bf3c39f9753843771a9336d9b4f56a4f Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sun, 4 Jan 2026 20:19:09 +0530 Subject: [PATCH 2/3] chore: update copyright year --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/plot/vega/scale/discrete/examples/index.js | 2 +- lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js index 5f3b1e98caf9..3485a1d403b7 100644 --- a/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js index d705672e65ac..ff99952c5539 100644 --- a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. From df425d101287e4ef82732710caddab5cc2b7474b Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sat, 10 Jan 2026 01:35:08 +0530 Subject: [PATCH 3/3] feat: update DiscreteScale to use ordinal type as default scale type --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../vega/scale/discrete/examples/index.js | 2 +- .../plot/vega/scale/discrete/lib/defaults.js | 43 +++++++++++++++++++ .../plot/vega/scale/discrete/lib/index.js | 3 +- .../plot/vega/scale/discrete/lib/main.js | 34 +++++++++------ 4 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/defaults.js diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js index 3485a1d403b7..835a6afb20b1 100644 --- a/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js @@ -22,7 +22,7 @@ var DiscreteScale = require( './../lib' ); var scale = new DiscreteScale({ 'name': 'xScale', - 'type': 'ordinal' + 'type': 'point' }); console.log( scale.toJSON() ); diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/defaults.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/defaults.js new file mode 100644 index 000000000000..07eeb85f8ad8 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/defaults.js @@ -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'; + +// MAIN // + +/** +* Returns defaults. +* +* @private +* @returns {Object} default options +* +* @example +* var o = defaults(); +* // returns {...} +*/ +function defaults() { + return { + // Scale type: + 'type': 'ordinal' + }; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js index dd8bc841a54a..b16fe1e287e7 100644 --- a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js @@ -27,8 +27,7 @@ * var DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' ); * * var scale = new DiscreteScale({ -* 'name': 'xScale', -* 'type': 'ordinal' +* 'name': 'xScale' * }); * // returns */ diff --git a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js index ff99952c5539..5f8fda9f9205 100644 --- a/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js +++ b/lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/main.js @@ -29,11 +29,13 @@ var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read 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 objectKeys = require( '@stdlib/utils/keys' ); 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' ); +var defaults = require( './defaults.js' ); // Note: keep the following in alphabetical order according to the `require` path... var getProperties = require( './properties/get.js' ); @@ -55,7 +57,6 @@ var debug = logger( 'vega:discrete-scale:main' ); * @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) @@ -65,18 +66,20 @@ var debug = logger( 'vega:discrete-scale:main' ); * @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 +* @param {string} [options.type='ordinal'] - scale type * @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' +* 'name': 'xScale' * }); * // returns */ function DiscreteScale( options ) { + var opts; + var keys; var v; var k; var i; @@ -90,14 +93,19 @@ function DiscreteScale( options ) { 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 + 'name': options.name }); + // Resolve the default configuration: + opts = defaults(); + + // Set internal properties according to the default configuration... + keys = objectKeys( opts ); + for ( i = 0; i < keys.length; i++ ) { + k = keys[ i ]; + this[ '_'+k ] = opts[ k ]; + } // Validate provided options by attempting to assign option values to corresponding fields... for ( i = 0; i < properties.length; i++ ) { k = properties[ i ]; @@ -142,8 +150,7 @@ setNonEnumerableReadOnly( DiscreteScale, 'name', 'DiscreteScale' ); * * @example * var scale = new DiscreteScale({ -* 'name': 'xScale', -* 'type': 'ordinal' +* 'name': 'xScale' * }); * * var v = scale.properties; @@ -157,11 +164,11 @@ setNonEnumerableReadOnlyAccessor( DiscreteScale.prototype, 'properties', getProp * @name type * @memberof DiscreteScale.prototype * @type {string} +* @default 'ordinal' * * @example * var scale = new DiscreteScale({ -* 'name': 'xScale', -* 'type': 'ordinal' +* 'name': 'xScale' * }); * * var v = scale.type; @@ -183,8 +190,7 @@ setReadWriteAccessor( DiscreteScale.prototype, 'type', getType, setType ); * * @example * var scale = new DiscreteScale({ -* 'name': 'xScale', -* 'type': 'ordinal' +* 'name': 'xScale' * }); * * var v = scale.toJSON();