From 0a584c95b7a3ad4f0457b9bc56db5458a11b9a06 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 12 Feb 2026 21:10:18 +0530 Subject: [PATCH 1/6] feat: add plot/vega/mark/compare --- 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 --- --- .../plot/vega/mark/compare/examples/index.js | 27 ++ .../vega/mark/compare/lib/change_event.js | 41 +++ .../plot/vega/mark/compare/lib/defaults.js | 43 +++ .../plot/vega/mark/compare/lib/field/get.js | 44 +++ .../vega/mark/compare/lib/field/properties.js | 33 +++ .../plot/vega/mark/compare/lib/field/set.js | 107 ++++++++ .../plot/vega/mark/compare/lib/index.js | 42 +++ .../plot/vega/mark/compare/lib/main.js | 250 ++++++++++++++++++ .../plot/vega/mark/compare/lib/order/get.js | 44 +++ .../vega/mark/compare/lib/order/properties.js | 33 +++ .../plot/vega/mark/compare/lib/order/set.js | 112 ++++++++ .../vega/mark/compare/lib/properties.json | 4 + .../vega/mark/compare/lib/properties/get.js | 41 +++ .../plot/vega/mark/compare/package.json | 61 +++++ 14 files changed, 882 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/change_event.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/defaults.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties.json create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/compare/package.json diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js new file mode 100644 index 000000000000..32de9141be80 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js @@ -0,0 +1,27 @@ +/** +* @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 Compare = require( './../lib' ); + +var compare = new Compare({ + 'field': [ 'amount', 'date' ], + 'order': [ 'descending' ] +}); +console.log( compare.toJSON() ); diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/change_event.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/change_event.js new file mode 100644 index 000000000000..4ae853bb4693 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/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': 'compare', + 'property': property + }; +} + + +// EXPORTS // + +module.exports = event; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/defaults.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/defaults.js new file mode 100644 index 000000000000..dac17c37011c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/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 { + // Desired sort order for each field: + 'order': [ 'ascending' ] + }; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js new file mode 100644 index 000000000000..812a7e51b87f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js @@ -0,0 +1,44 @@ +/** +* @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 copy = require( '@stdlib/array/base/copy-indexed' ); +var prop = require( './properties.js' ); + + +// MAIN // + +/** +* Returns the data fields to sort. +* +* @private +* @returns {(Array|void)} data fields +*/ +function get() { + return ( this[ prop.private ] ) ? copy( this[ prop.private ] ) : this[ prop.private ]; // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/properties.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/properties.js new file mode 100644 index 000000000000..639ddb612903 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/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( 'field' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js new file mode 100644 index 000000000000..4c7cb073736f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js @@ -0,0 +1,107 @@ +/** +* @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 isUndefined = require( '@stdlib/assert/is-undefined' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' ); +var copy = require( '@stdlib/array/base/copy' ); +var join = require( '@stdlib/array/base/join' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( './../defaults.js' ); +var changeEvent = require( './../change_event.js' ); +var prop = require( './properties.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:compare:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the data fields to sort. +* +* ## Notes +* +* - When the number of fields changes, the order array is automatically adjusted: +* - If fields are added, 'ascending' is appended to the order array. +* - If fields are removed, excess order entries are truncated. +* +* @private +* @param {(string|Array)} value - input value +* @throws {TypeError} must be a string or an array of strings +* @returns {void} +*/ +function set( value ) { + var nfields; + var order; + var isStr; + var opts; + var i; + + isStr = isString( value ); + if ( !isStr && !isStringArray( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', prop.name, value ) ); + } + if ( isStr ) { + value = [ value ]; + } else { + value = copy( value ); + } + if ( isUndefined( this[ prop.private ] ) ) { + debug( 'Current value: %s. New value: ["%s"].', this[ prop.private ], join( value, '", "' ) ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + return; + } + if ( !hasEqualValues( value, this[ prop.private ] ) ) { + debug( 'Current value: ["%s"]. New value: ["%s"].', join( this[ prop.private ], '", "' ), join( value, '", "' ) ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + + // Adjust the order array to match the new number of fields... + nfields = value.length; + order = this._order; + if ( order ) { + if ( order.length < nfields ) { + // Pad with default 'ascending' values... + opts = defaults(); + for ( i = order.length; i < nfields; i++ ) { + order.push( opts.order[ 0 ] ); + } + } else if ( order.length > nfields ) { + // Truncate excess order entries... + order.length = nfields; + } + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/index.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/index.js new file mode 100644 index 000000000000..4c1bdc215c8e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/index.js @@ -0,0 +1,42 @@ +/** +* @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'; + +/** +* Compare constructor. +* +* @module @stdlib/plot/vega/mark/compare +* +* @example +* var Compare = require( '@stdlib/plot/vega/mark/compare' ); +* +* var compare = new Compare({ +* 'field': 'amount' +* }); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js new file mode 100644 index 000000000000..660201c60ee9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js @@ -0,0 +1,250 @@ +/** +* @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 EventEmitter = require( 'events' ).EventEmitter; +var logger = require( 'debug' ); +var isObject = require( '@stdlib/assert/is-object' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +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 setReadWriteAccessor = require( '@stdlib/utils/define-read-write-accessor' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var inherit = require( '@stdlib/utils/inherit' ); +var instance2json = require( '@stdlib/plot/vega/base/to-json' ); +var transformErrorMessage = require( '@stdlib/plot/vega/base/transform-validation-message' ); +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 getField = require( './field/get.js' ); +var setField = require( './field/set.js' ); + +var getOrder = require( './order/get.js' ); +var setOrder = require( './order/set.js' ); + +var getProperties = require( './properties/get.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:compare:main' ); + + +// MAIN // + +/** +* Compare constructor. +* +* @constructor +* @param {Options} [options] - constructor options +* @param {(string|Array)} [field] - data fields to sort +* @param {(string|Array)} [options.order=['ascending']] - desired sort order for each field +* @throws {TypeError} options argument must be an object +* @throws {Error} must provide valid options +* @returns {Compare} compare instance +* +* @example +* var compare = new Compare({ +* 'field': 'amount' +* }); +* // returns +*/ +function Compare( options ) { + var nfields; + var nargs; + var order; + var opts; + var v; + var k; + var i; + + nargs = arguments.length; + if ( !( this instanceof Compare ) ) { + if ( nargs ) { + return new Compare( options ); + } + return new Compare(); + } + 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, 'field' ) ) { + throw new TypeError( 'invalid argument. Options argument must contain a field property.' ); + } + + EventEmitter.call( this ); + + // Resolve the default configuration: + opts = defaults(); + + // Determine the number of fields: + if ( isArray( options.field ) ) { + nfields = options.field.length; + } else if ( isString( options.field ) ) { + nfields = 1; + } else { + nfields = 0; + } + + // Resolve the order array, padding with defaults as needed... + if ( hasProp( options, 'order' ) ) { + if ( isArray( options.order ) ) { + order = options.order.slice(); + } else if ( isString( options.order ) ) { + order = [ options.order ]; + } else { + order = []; + } + } else { + order = []; + } + + // Pad the order array with default values if there are fewer order entries than field entries: + for ( i = order.length; i < nfields; i++ ) { + order.push( opts.order[ 0 ] ); + } + + // Validate provided options by attempting to assign option values to corresponding fields... + for ( i = 0; i < properties.length; i++ ) { + k = properties[ i ]; + if ( k === 'order' ) { + v = order; + } else if ( hasProp( options, k ) ) { + v = options[ k ]; + } else { + continue; + } + 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 the `EventEmitter` prototype. +*/ +inherit( Compare, EventEmitter ); + +/** +* Constructor name. +* +* @private +* @name name +* @memberof Compare +* @readonly +* @type {string} +*/ +setNonEnumerableReadOnly( Compare, 'name', 'Compare' ); + +/** +* Data fields to sort. +* +* @name field +* @memberof Compare.prototype +* @type {(string|Array)} +* +* @example +* var compare = new Compare({ +* 'field': 'amount' +* }); +* +* var v = compare.field; +* // returns [ 'amount' ] +*/ +setReadWriteAccessor( Compare.prototype, 'field', getField, setField ); + +/** +* Desired sort order for each field. +* +* @name order +* @memberof Compare.prototype +* @type {(string|Array|void)} +* @default [ 'ascending' ] +* +* @example +* var compare = new Compare({ +* 'field': 'amount', +* 'order': 'descending' +* }); +* +* var v = compare.order; +* // returns [ 'descending' ] +*/ +setReadWriteAccessor( Compare.prototype, 'order', getOrder, setOrder ); + +/** +* Compare properties. +* +* @name properties +* @memberof Compare.prototype +* @type {Array} +* +* @example +* var compare = new Compare({ +* 'field': 'amount' +* }); +* +* var v = compare.properties; +* // returns [...] +*/ +setNonEnumerableReadOnlyAccessor( Compare.prototype, 'properties', getProperties ); + +/** +* Serializes an instance to a JSON object. +* +* ## Notes +* +* - This method is implicitly invoked by `JSON.stringify`. +* +* @name toJSON +* @memberof Compare.prototype +* @type {Function} +* @returns {Object} JSON object +* +* @example +* var compare = new Compare({ +* 'field': 'amount' +* }); +* +* var v = compare.toJSON(); +* // returns {...} +*/ +setNonEnumerableReadOnly( Compare.prototype, 'toJSON', function toJSON() { + return instance2json( this, properties ); +}); + + +// EXPORTS // + +module.exports = Compare; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js new file mode 100644 index 000000000000..ff83e2a98d3a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js @@ -0,0 +1,44 @@ +/** +* @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 copy = require( '@stdlib/array/base/copy-indexed' ); +var prop = require( './properties.js' ); + + +// MAIN // + +/** +* Returns the desired sort order for each field. +* +* @private +* @returns {(Array|void)} sort order +*/ +function get() { + return ( this[ prop.private ] ) ? copy( this[ prop.private ] ) : this[ prop.private ]; // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/properties.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/properties.js new file mode 100644 index 000000000000..d48ece2b868d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/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( 'order' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js new file mode 100644 index 000000000000..a5828d040ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js @@ -0,0 +1,112 @@ +/** +* @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 isUndefined = require( '@stdlib/assert/is-undefined' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' ); +var copy = require( '@stdlib/array/base/copy' ); +var join = require( '@stdlib/array/base/join' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( './../defaults.js' ); +var changeEvent = require( './../change_event.js' ); +var prop = require( './properties.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:compare:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the desired sort order for each field. +* +* ## Notes +* +* - Providing `undefined` "unsets" the configured value. +* - If fewer order entries than field entries are provided, the order array is padded with 'ascending' values. +* +* @private +* @param {(string|Array|void)} value - input value +* @throws {TypeError} must be a string or an array of strings +* @returns {void} +*/ +function set( value ) { + var nfields; + var isVoid; + var isStr; + var opts; + var i; + + isStr = isString( value ); + if ( !isStr ) { + isVoid = isUndefined( value ); + if ( !isVoid && !isStringArray( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', prop.name, value ) ); + } + } + if ( isVoid ) { + if ( value === this[ prop.private ] ) { + return; + } + debug( 'Current value: ["%s"]. New value: %s.', join( this[ prop.private ], '", "' ), value ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + return; + } + if ( isStr ) { + value = [ value ]; + } else { + value = copy( value ); + } + + // If there are fewer order entries than field entries, pad with default 'ascending' values... + nfields = ( this._field ) ? this._field.length : 0; + if ( value.length < nfields ) { + opts = defaults(); + for ( i = value.length; i < nfields; i++ ) { + value.push( opts.order[ 0 ] ); + } + } + + if ( isUndefined( this[ prop.private ] ) ) { + debug( 'Current value: %s. New value: ["%s"].', this[ prop.private ], join( value, '", "' ) ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + return; + } + if ( !hasEqualValues( value, this[ prop.private ] ) ) { + debug( 'Current value: ["%s"]. New value: ["%s"].', join( this[ prop.private ], '", "' ), join( value, '", "' ) ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties.json b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties.json new file mode 100644 index 000000000000..cb752719b507 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties.json @@ -0,0 +1,4 @@ +[ + "field", + "order" +] diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js new file mode 100644 index 000000000000..8fc57de14e90 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js @@ -0,0 +1,41 @@ +/** +* @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'; + +// 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/mark/compare/package.json b/lib/node_modules/@stdlib/plot/vega/mark/compare/package.json new file mode 100644 index 000000000000..8b1051609990 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/package.json @@ -0,0 +1,61 @@ +{ + "name": "@stdlib/plot/vega/mark/compare", + "version": "0.0.0", + "description": "Compare 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", + "mark", + "compare", + "constructor", + "ctor" + ], + "__stdlib__": {} +} From d594f1b3244c054255e0ce853776bfe850e47c66 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Thu, 12 Feb 2026 21:14:45 +0530 Subject: [PATCH 2/6] Update copyright year from 2025 to 2026 Signed-off-by: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> --- .../@stdlib/plot/vega/mark/compare/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js index 32de9141be80..dfa2b0fa069c 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/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. From deeb789cd9d37aeb563343e007d35a1bdae9faad Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Thu, 12 Feb 2026 21:16:34 +0530 Subject: [PATCH 3/6] Update copyright year in get.js file Signed-off-by: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> --- .../@stdlib/plot/vega/mark/compare/lib/properties/get.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js index 8fc57de14e90..f3cbb28454ea 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.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 f437fdc2ab256daebcc1ab4adfd0276be7a79606 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Mon, 2 Mar 2026 22:06:31 +0530 Subject: [PATCH 4/6] refactor: change as per suggested --- .../plot/vega/mark/compare/examples/index.js | 18 +++- .../plot/vega/mark/compare/lib/field/get.js | 5 +- .../plot/vega/mark/compare/lib/field/set.js | 27 +++--- .../plot/vega/mark/compare/lib/main.js | 83 +++++++++++-------- .../plot/vega/mark/compare/lib/order/get.js | 5 +- .../plot/vega/mark/compare/lib/order/set.js | 64 +++++++------- 6 files changed, 117 insertions(+), 85 deletions(-) diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js index dfa2b0fa069c..af523fbf38b0 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js @@ -18,10 +18,26 @@ 'use strict'; +var SignalReference = require( '@stdlib/plot/vega/signal/reference' ); var Compare = require( './../lib' ); +// Single field comparator: var compare = new Compare({ + 'field': 'amount', + 'order': 'ascending' +}); +console.log( compare.toJSON() ); + +// Multi-field comparator: +compare = new Compare({ 'field': [ 'amount', 'date' ], - 'order': [ 'descending' ] + 'order': [ 'descending', 'ascending' ] +}); +console.log( compare.toJSON() ); + +// Signal reference comparator: +compare = new Compare({ + 'field': new SignalReference( 'sortField' ), + 'order': new SignalReference( 'sortOrder' ) }); console.log( compare.toJSON() ); diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js index 812a7e51b87f..48371be24021 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js @@ -22,7 +22,6 @@ // MODULES // -var copy = require( '@stdlib/array/base/copy-indexed' ); var prop = require( './properties.js' ); @@ -32,10 +31,10 @@ var prop = require( './properties.js' ); * Returns the data fields to sort. * * @private -* @returns {(Array|void)} data fields +* @returns {(Array|SignalReference|void)} data fields */ function get() { - return ( this[ prop.private ] ) ? copy( this[ prop.private ] ) : this[ prop.private ]; // eslint-disable-line max-len + return this[ prop.private ]; } diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js index 4c7cb073736f..12401c763d6f 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js @@ -26,6 +26,7 @@ var logger = require( 'debug' ); var isUndefined = require( '@stdlib/assert/is-undefined' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var isSignalReference = require( '@stdlib/plot/vega/base/assert/is-signal-reference' ); var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' ); var copy = require( '@stdlib/array/base/copy' ); var join = require( '@stdlib/array/base/join' ); @@ -45,15 +46,9 @@ var debug = logger( 'vega:compare:set:'+prop.name ); /** * Sets the data fields to sort. * -* ## Notes -* -* - When the number of fields changes, the order array is automatically adjusted: -* - If fields are added, 'ascending' is appended to the order array. -* - If fields are removed, excess order entries are truncated. -* * @private -* @param {(string|Array)} value - input value -* @throws {TypeError} must be a string or an array of strings +* @param {(string|Array|SignalReference)} value - input value +* @throws {TypeError} must be a string, an array of strings, or a SignalReference * @returns {void} */ function set( value ) { @@ -63,21 +58,23 @@ function set( value ) { var opts; var i; + if ( isSignalReference( value ) ) { + if ( this[ prop.private ] !== value ) { + debug( 'Current value: %s. New value: %s.', this[ prop.private ], value ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + } + return; + } isStr = isString( value ); if ( !isStr && !isStringArray( value ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', prop.name, value ) ); + throw new TypeError( format( 'invalid assignment. `%s` must be a string, an array of strings, or a signal reference. Value: `%s`.', prop.name, value ) ); } if ( isStr ) { value = [ value ]; } else { value = copy( value ); } - if ( isUndefined( this[ prop.private ] ) ) { - debug( 'Current value: %s. New value: ["%s"].', this[ prop.private ], join( value, '", "' ) ); - this[ prop.private ] = value; - this.emit( 'change', changeEvent( prop.name ) ); - return; - } if ( !hasEqualValues( value, this[ prop.private ] ) ) { debug( 'Current value: ["%s"]. New value: ["%s"].', join( this[ prop.private ], '", "' ), join( value, '", "' ) ); this[ prop.private ] = value; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js index 660201c60ee9..220fea5fca7e 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js @@ -27,6 +27,8 @@ var logger = require( 'debug' ); var isObject = require( '@stdlib/assert/is-object' ); var isArray = require( '@stdlib/assert/is-array' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isSignalReference = require( '@stdlib/plot/vega/base/assert/is-signal-reference' ); +var objectKeys = require( '@stdlib/utils/keys' ); 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 setReadWriteAccessor = require( '@stdlib/utils/define-read-write-accessor' ); @@ -60,8 +62,8 @@ var debug = logger( 'vega:compare:main' ); * * @constructor * @param {Options} [options] - constructor options -* @param {(string|Array)} [field] - data fields to sort -* @param {(string|Array)} [options.order=['ascending']] - desired sort order for each field +* @param {(string|Array|SignalReference)} options.field - data fields to sort +* @param {(string|Array|SignalReference)} [options.order=['ascending']] - desired sort order for each field * @throws {TypeError} options argument must be an object * @throws {Error} must provide valid options * @returns {Compare} compare instance @@ -74,8 +76,9 @@ var debug = logger( 'vega:compare:main' ); */ function Compare( options ) { var nfields; + var norders; var nargs; - var order; + var keys; var opts; var v; var k; @@ -91,53 +94,63 @@ function Compare( 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, 'field' ) ) { throw new TypeError( 'invalid argument. Options argument must contain a field property.' ); } - EventEmitter.call( this ); // Resolve the default configuration: opts = defaults(); - // Determine the number of fields: - if ( isArray( options.field ) ) { - nfields = options.field.length; - } else if ( isString( options.field ) ) { - nfields = 1; - } else { - nfields = 0; - } + // Initialize internal state for the required `field` property: + this._field = []; - // Resolve the order array, padding with defaults as needed... - if ( hasProp( options, 'order' ) ) { - if ( isArray( options.order ) ) { - order = options.order.slice(); - } else if ( isString( options.order ) ) { - order = [ options.order ]; - } else { - order = []; - } - } else { - order = []; + // 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 ]; } - // Pad the order array with default values if there are fewer order entries than field entries: - for ( i = order.length; i < nfields; i++ ) { - order.push( opts.order[ 0 ] ); + if ( isSignalReference( options.field ) ) { + if ( !hasProp( options, 'order' ) || !isSignalReference( options.order ) ) { + throw new TypeError( format( 'invalid argument. `%s` must be a signal reference when `field` is a signal reference.', 'order' ) ); + } + } else if ( isString( options.field ) ) { + if ( hasProp( options, 'order' ) && !isString( options.order ) ) { + throw new TypeError( format( 'invalid argument. `%s` must be a string when `field` is a string.', 'order' ) ); + } + if ( !hasProp( options, 'order' ) ) { + options.order = opts.order[ 0 ]; + } + } else if ( isArray( options.field ) ) { + nfields = options.field.length; + if ( hasProp( options, 'order' ) ) { + norders = options.order.length; + if ( isSignalReference( options.order ) ) { + throw new TypeError( format( 'invalid argument. `%s` must be a string or an array of strings when `field` is an array of strings.', 'order' ) ); + } + if ( isString( options.order ) ) { + options.order = [ options.order ]; + } + if ( isArray( options.order ) && norders !== 0 && norders !== nfields ) { + throw new RangeError( format( 'invalid argument. `%s` array length must equal the number of fields. Number of fields: `%u`. Value: `%s`.', 'order', nfields, options.order ) ); + } + } + if ( !hasProp( options, 'order' ) || norders === 0 ) { + options.order = []; + for ( i = 0; i < nfields; i++ ) { + options.order.push( opts.order[ 0 ] ); + } + } } - // Validate provided options by attempting to assign option values to corresponding fields... for ( i = 0; i < properties.length; i++ ) { k = properties[ i ]; - if ( k === 'order' ) { - v = order; - } else if ( hasProp( options, k ) ) { - v = options[ k ]; - } else { + if ( !hasProp( options, k ) ) { continue; } + v = options[ k ]; try { this[ k ] = v; } catch ( err ) { @@ -172,7 +185,7 @@ setNonEnumerableReadOnly( Compare, 'name', 'Compare' ); * * @name field * @memberof Compare.prototype -* @type {(string|Array)} +* @type {(string|Array|SignalReference)} * * @example * var compare = new Compare({ @@ -189,7 +202,7 @@ setReadWriteAccessor( Compare.prototype, 'field', getField, setField ); * * @name order * @memberof Compare.prototype -* @type {(string|Array|void)} +* @type {(string|Array|SignalReference)} * @default [ 'ascending' ] * * @example diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js index ff83e2a98d3a..0dd522ed8e9a 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js @@ -22,7 +22,6 @@ // MODULES // -var copy = require( '@stdlib/array/base/copy-indexed' ); var prop = require( './properties.js' ); @@ -32,10 +31,10 @@ var prop = require( './properties.js' ); * Returns the desired sort order for each field. * * @private -* @returns {(Array|void)} sort order +* @returns {(Array|SignalReference|void)} sort order */ function get() { - return ( this[ prop.private ] ) ? copy( this[ prop.private ] ) : this[ prop.private ]; // eslint-disable-line max-len + return this[ prop.private ]; } diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js index a5828d040ed3..50b6f3f8779a 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js +++ b/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js @@ -23,10 +23,12 @@ // MODULES // var logger = require( 'debug' ); -var isUndefined = require( '@stdlib/assert/is-undefined' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var isSignalReference = require( '@stdlib/plot/vega/base/assert/is-signal-reference' ); var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' ); +var isSortOrder = require( '@stdlib/plot/vega/base/assert/is-sort-order' ); +var sortOrders = require( '@stdlib/plot/vega/mark/orders' ); var copy = require( '@stdlib/array/base/copy' ); var join = require( '@stdlib/array/base/join' ); var format = require( '@stdlib/string/format' ); @@ -45,60 +47,66 @@ var debug = logger( 'vega:compare:set:'+prop.name ); /** * Sets the desired sort order for each field. * -* ## Notes -* -* - Providing `undefined` "unsets" the configured value. -* - If fewer order entries than field entries are provided, the order array is padded with 'ascending' values. -* * @private -* @param {(string|Array|void)} value - input value -* @throws {TypeError} must be a string or an array of strings +* @param {(string|Array|SignalReference|void)} value - input value +* @throws {TypeError} must be a string, an array of strings, or a SignalReference +* @throws {TypeError} each order value must be a valid order +* @throws {TypeError} when field is a SignalReference, order must also be a SignalReference +* @throws {RangeError} order array length must not exceed field array length * @returns {void} */ function set( value ) { var nfields; - var isVoid; + var isSigRef; var isStr; var opts; var i; - isStr = isString( value ); - if ( !isStr ) { - isVoid = isUndefined( value ); - if ( !isVoid && !isStringArray( value ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', prop.name, value ) ); + isSigRef = isSignalReference( value ); + if ( isSigRef ) { + // When order is a SignalReference, field must also be a SignalReference... + if ( !isSignalReference( this._field ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a signal reference when `field` is a signal reference. Value: `%s`.', prop.name, value ) ); } - } - if ( isVoid ) { - if ( value === this[ prop.private ] ) { - return; + if ( this[ prop.private ] !== value ) { + debug( 'Current value: %s. New value: %s.', this[ prop.private ], value ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); } - debug( 'Current value: ["%s"]. New value: %s.', join( this[ prop.private ], '", "' ), value ); - this[ prop.private ] = value; - this.emit( 'change', changeEvent( prop.name ) ); return; } + isStr = isString( value ); + if ( !isStr ) { + if ( !isStringArray( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string, an array of strings, or a signal reference. Value: `%s`.', prop.name, value ) ); + } + } if ( isStr ) { + if ( !isSortOrder( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( sortOrders(), '", "' ), value ) ); + } value = [ value ]; } else { + // Validate each order value... + for ( i = 0; i < value.length; i++ ) { + if ( !isSortOrder( value[ i ] ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( sortOrders(), '", "' ), value[ i ] ) ); + } + } value = copy( value ); } // If there are fewer order entries than field entries, pad with default 'ascending' values... nfields = ( this._field ) ? this._field.length : 0; + if ( value.length > nfields && nfields > 0 ) { + throw new RangeError( format( 'invalid assignment. `%s` array length must not exceed the number of fields. Number of fields: `%u`. Value: `%s`.', prop.name, nfields, value ) ); + } if ( value.length < nfields ) { opts = defaults(); for ( i = value.length; i < nfields; i++ ) { value.push( opts.order[ 0 ] ); } } - - if ( isUndefined( this[ prop.private ] ) ) { - debug( 'Current value: %s. New value: ["%s"].', this[ prop.private ], join( value, '", "' ) ); - this[ prop.private ] = value; - this.emit( 'change', changeEvent( prop.name ) ); - return; - } if ( !hasEqualValues( value, this[ prop.private ] ) ) { debug( 'Current value: ["%s"]. New value: ["%s"].', join( this[ prop.private ], '", "' ), join( value, '", "' ) ); this[ prop.private ] = value; From f37a3caf9f597723ee7e4962a43ba6f78efc37ef Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 3 Mar 2026 11:14:13 +0530 Subject: [PATCH 5/6] refactor: migrate to compare/ctor --- .../vega/{mark/compare => compare/ctor}/examples/index.js | 0 .../vega/{mark/compare => compare/ctor}/lib/change_event.js | 0 .../plot/vega/{mark/compare => compare/ctor}/lib/defaults.js | 0 .../plot/vega/{mark/compare => compare/ctor}/lib/field/get.js | 0 .../{mark/compare => compare/ctor}/lib/field/properties.js | 0 .../plot/vega/{mark/compare => compare/ctor}/lib/field/set.js | 0 .../plot/vega/{mark/compare => compare/ctor}/lib/index.js | 4 ++-- .../plot/vega/{mark/compare => compare/ctor}/lib/main.js | 0 .../plot/vega/{mark/compare => compare/ctor}/lib/order/get.js | 0 .../{mark/compare => compare/ctor}/lib/order/properties.js | 0 .../plot/vega/{mark/compare => compare/ctor}/lib/order/set.js | 0 .../vega/{mark/compare => compare/ctor}/lib/properties.json | 0 .../vega/{mark/compare => compare/ctor}/lib/properties/get.js | 0 .../plot/vega/{mark/compare => compare/ctor}/package.json | 3 +-- 14 files changed, 3 insertions(+), 4 deletions(-) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/examples/index.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/change_event.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/defaults.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/field/get.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/field/properties.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/field/set.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/index.js (89%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/main.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/order/get.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/order/properties.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/order/set.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/properties.json (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/lib/properties/get.js (100%) rename lib/node_modules/@stdlib/plot/vega/{mark/compare => compare/ctor}/package.json (95%) diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/examples/index.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/examples/index.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/examples/index.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/change_event.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/change_event.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/change_event.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/change_event.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/defaults.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/defaults.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/defaults.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/defaults.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/field/get.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/get.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/field/get.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/properties.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/field/properties.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/properties.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/field/properties.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/field/set.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/field/set.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/field/set.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/index.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/index.js similarity index 89% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/index.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/index.js index 4c1bdc215c8e..fcf753945c8c 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/index.js +++ b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/index.js @@ -21,10 +21,10 @@ /** * Compare constructor. * -* @module @stdlib/plot/vega/mark/compare +* @module @stdlib/plot/vega/compare/ctor * * @example -* var Compare = require( '@stdlib/plot/vega/mark/compare' ); +* var Compare = require( '@stdlib/plot/vega/compare/ctor' ); * * var compare = new Compare({ * 'field': 'amount' diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/main.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/main.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/main.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/get.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/get.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/get.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/properties.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/properties.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/properties.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/properties.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/set.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/order/set.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/set.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties.json b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/properties.json similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties.json rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/properties.json diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/properties/get.js similarity index 100% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/lib/properties/get.js rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/properties/get.js diff --git a/lib/node_modules/@stdlib/plot/vega/mark/compare/package.json b/lib/node_modules/@stdlib/plot/vega/compare/ctor/package.json similarity index 95% rename from lib/node_modules/@stdlib/plot/vega/mark/compare/package.json rename to lib/node_modules/@stdlib/plot/vega/compare/ctor/package.json index 8b1051609990..c7e89bdb7810 100644 --- a/lib/node_modules/@stdlib/plot/vega/mark/compare/package.json +++ b/lib/node_modules/@stdlib/plot/vega/compare/ctor/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/plot/vega/mark/compare", + "name": "@stdlib/plot/vega/compare/ctor", "version": "0.0.0", "description": "Compare constructor.", "license": "Apache-2.0", @@ -52,7 +52,6 @@ "stdlib", "plot", "vega", - "mark", "compare", "constructor", "ctor" From 013fd9aeac77aa6e6c84e7ebe169dcb3da0b9fa6 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 3 Mar 2026 11:51:57 +0530 Subject: [PATCH 6/6] refactor: update sort order validation to use compare orders --- .../@stdlib/plot/vega/compare/ctor/lib/order/set.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/set.js b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/set.js index 50b6f3f8779a..848a6ec72409 100644 --- a/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/set.js +++ b/lib/node_modules/@stdlib/plot/vega/compare/ctor/lib/order/set.js @@ -27,8 +27,8 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; var isSignalReference = require( '@stdlib/plot/vega/base/assert/is-signal-reference' ); var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' ); -var isSortOrder = require( '@stdlib/plot/vega/base/assert/is-sort-order' ); -var sortOrders = require( '@stdlib/plot/vega/mark/orders' ); +var isCompareOrder = require( '@stdlib/plot/vega/base/assert/is-compare-order' ); +var compareOrders = require( '@stdlib/plot/vega/compare/orders' ); var copy = require( '@stdlib/array/base/copy' ); var join = require( '@stdlib/array/base/join' ); var format = require( '@stdlib/string/format' ); @@ -82,15 +82,15 @@ function set( value ) { } } if ( isStr ) { - if ( !isSortOrder( value ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( sortOrders(), '", "' ), value ) ); + if ( !isCompareOrder( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( compareOrders(), '", "' ), value ) ); } value = [ value ]; } else { // Validate each order value... for ( i = 0; i < value.length; i++ ) { - if ( !isSortOrder( value[ i ] ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( sortOrders(), '", "' ), value[ i ] ) ); + if ( !isCompareOrder( value[ i ] ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( compareOrders(), '", "' ), value[ i ] ) ); } } value = copy( value );