diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/examples/index.js b/lib/node_modules/@stdlib/plot/vega/transform/collect/examples/index.js new file mode 100644 index 000000000000..4a81cdf88842 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 Compare = require( '@stdlib/plot/vega/compare/ctor' ); +var CollectTransform = require( './../lib' ); + +var compare = new Compare({ + 'field': 'amount' +}); + +var transform = new CollectTransform({ + 'sort': compare +}); +console.log( transform.toJSON() ); + +compare = new Compare({ + 'field': [ 'amount', 'date' ], + 'order': [ 'descending', 'ascending' ] +}); +transform.sort = compare; +console.log( transform.toJSON() ); diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/change_event.js b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/change_event.js new file mode 100644 index 000000000000..e444f9c667b0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/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': 'transform', + 'property': property + }; +} + + +// EXPORTS // + +module.exports = event; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/index.js b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/index.js new file mode 100644 index 000000000000..2a64e3353b14 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/index.js @@ -0,0 +1,48 @@ +/** +* @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'; + +/** +* Collect transform constructor. +* +* @module @stdlib/plot/vega/transform/collect +* +* @example +* var Compare = require( '@stdlib/plot/vega/compare/ctor' ); +* var CollectTransform = require( '@stdlib/plot/vega/transform/collect' ); +* +* var compare = new Compare({ +* 'field': 'amount' +* }); +* // returns +* +* var transform = new CollectTransform({ +* 'sort': compare +* }); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/main.js b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/main.js new file mode 100644 index 000000000000..40c13905c50d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/main.js @@ -0,0 +1,293 @@ +/** +* @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, stdlib/no-empty-lines-between-requires */ + +'use strict'; + +// MODULES // + +var EventEmitter = require( 'events' ).EventEmitter; +var logger = require( 'debug' ); +var isObject = require( '@stdlib/assert/is-object' ); +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' ); + +// Note: keep the following in alphabetical order according to the `require` path... +var getProperties = require( './properties/get.js' ); + +var getSort = require( './sort/get.js' ); +var setSort = require( './sort/set.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:collect-transform:main' ); + + +// MAIN // + +/** +* Collect transform constructor. +* +* @constructor +* @param {Options} options - constructor options +* @param {Compare} options.sort - comparator definition for sorting data objects +* @throws {TypeError} options argument must be an object +* @throws {Error} must provide valid options +* @returns {CollectTransform} collect transform instance +* +* @example +* var Compare = require( '@stdlib/plot/vega/compare/ctor' ); +* +* var compare = new Compare({ +* 'field': 'amount' +* }); +* // returns +* +* var transform = new CollectTransform({ +* 'sort': compare +* }); +* // returns +*/ +function CollectTransform( options ) { + var self; + var v; + var k; + var i; + if ( !( this instanceof CollectTransform ) ) { + return new CollectTransform( options ); + } + self = this; + EventEmitter.call( this ); + + if ( !isObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + + // Define an internal change event listener: + this._onChange = onChange; + + // Add change listeners to default event emitters: + if ( this._sort && typeof this._sort.on === 'function' ) { + this._addChangeListener( this._sort ); + } + + // 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; + + /** + * Callback invoked upon a change event. + * + * @private + * @param {Object} event - event object + */ + function onChange( event ) { + debug( 'Received a change event: %s', JSON.stringify( event ) ); + self.emit( 'change', event ); + } +} + +/* +* Inherit from the `EventEmitter` prototype. +*/ +inherit( CollectTransform, EventEmitter ); + +/** +* Constructor name. +* +* @private +* @name name +* @memberof CollectTransform +* @readonly +* @type {string} +*/ +setNonEnumerableReadOnly( CollectTransform, 'name', 'CollectTransform' ); + +/** +* Adds an internal listener to a change event on a child instance. +* +* @private +* @name _addChangeListener +* @memberof CollectTransform.prototype +* @type {Function} +* @param {Object} emitter - event emitter +* @returns {CollectTransform} collect transform instance +*/ +setNonEnumerableReadOnly( CollectTransform.prototype, '_addChangeListener', function addChangeListener( emitter ) { + if ( emitter && typeof emitter.on === 'function' ) { + emitter.on( 'change', this._onChange ); + } + return this; +}); + +/** +* Adds internal listeners to change events on child instances. +* +* @private +* @name _addChangeListeners +* @memberof CollectTransform.prototype +* @type {Function} +* @param {ArrayLikeObject} emitters - list of event emitters +* @returns {CollectTransform} collect transform instance +*/ +setNonEnumerableReadOnly( CollectTransform.prototype, '_addChangeListeners', function addChangeListeners( emitters ) { + var i; + for ( i = 0; i < emitters.length; i++ ) { + this._addChangeListener( emitters[ i ] ); + } + return this; +}); + +/** +* Removes an internal listener to a change event on a child instance. +* +* @private +* @name _removeChangeListener +* @memberof CollectTransform.prototype +* @type {Function} +* @param {Object} emitter - event emitter +* @returns {CollectTransform} collect transform instance +*/ +setNonEnumerableReadOnly( CollectTransform.prototype, '_removeChangeListener', function removeChangeListener( emitter ) { + if ( emitter && typeof emitter.removeListener === 'function' ) { + emitter.removeListener( 'change', this._onChange ); + } + return this; +}); + +/** +* Removes internal listeners to change events on child instances. +* +* @private +* @name _removeChangeListeners +* @memberof CollectTransform.prototype +* @type {Function} +* @param {ArrayLikeObject} emitters - list of event emitters +* @returns {CollectTransform} collect transform instance +*/ +setNonEnumerableReadOnly( CollectTransform.prototype, '_removeChangeListeners', function removeChangeListeners( emitters ) { + var i; + for ( i = 0; i < emitters.length; i++ ) { + this._removeChangeListener( emitters[ i ] ); + } + return this; +}); + +/** +* Collect transform properties. +* +* @name properties +* @memberof CollectTransform.prototype +* @type {Array} +* +* @example +* var Compare = require( '@stdlib/plot/vega/compare/ctor' ); +* +* var compare = new Compare({ +* 'field': 'amount' +* }); +* +* var transform = new CollectTransform({ +* 'sort': compare +* }); +* +* var v = transform.properties; +* // returns [...] +*/ +setNonEnumerableReadOnlyAccessor( CollectTransform.prototype, 'properties', getProperties ); + +/** +* Comparator definition for sorting data objects. +* +* @name sort +* @memberof CollectTransform.prototype +* @type {(Compare|void)} +* +* @example +* var Compare = require( '@stdlib/plot/vega/compare/ctor' ); +* +* var compare = new Compare({ +* 'field': 'amount' +* }); +* +* var transform = new CollectTransform({ +* 'sort': compare +* }); +* +* var v = transform.sort; +* // returns +*/ +setReadWriteAccessor( CollectTransform.prototype, 'sort', getSort, setSort ); + +/** +* Serializes an instance to a JSON object. +* +* ## Notes +* +* - This method is implicitly invoked by `JSON.stringify`. +* +* @name toJSON +* @memberof CollectTransform.prototype +* @type {Function} +* @returns {Object} JSON object +* +* @example +* var Compare = require( '@stdlib/plot/vega/compare/ctor' ); +* +* var compare = new Compare({ +* 'field': 'amount' +* }); +* +* var transform = new CollectTransform({ +* 'sort': compare +* }); +* +* var v = transform.toJSON(); +* // returns {...} +*/ +setNonEnumerableReadOnly( CollectTransform.prototype, 'toJSON', function toJSON() { + return instance2json( this, properties ); +}); + + +// EXPORTS // + +module.exports = CollectTransform; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/properties.json b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/properties.json new file mode 100644 index 000000000000..7d9fc5df228b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/properties.json @@ -0,0 +1,3 @@ +[ + "sort" +] diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/properties/get.js new file mode 100644 index 000000000000..f3cbb28454ea --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/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/transform/collect/lib/sort/get.js b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/sort/get.js new file mode 100644 index 000000000000..7c7a930a8c68 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/sort/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 comparator definition for sorting data objects. +* +* @private +* @returns {(Compare|void)} comparator +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/sort/properties.js b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/sort/properties.js new file mode 100644 index 000000000000..9a3846787a90 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/sort/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( 'sort' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/sort/set.js b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/sort/set.js new file mode 100644 index 000000000000..797534b0eba9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/lib/sort/set.js @@ -0,0 +1,68 @@ +/** +* @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 isCompare = require( '@stdlib/plot/vega/base/assert/is-compare' ); +var isUndefined = require( '@stdlib/assert/is-undefined' ); +var format = require( '@stdlib/string/format' ); +var changeEvent = require( './../change_event.js' ); +var prop = require( './properties.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:collect-transform:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the comparator definition for sorting data objects. +* +* ## Notes +* +* - Providing `undefined` "unsets" the configured value. +* +* @private +* @param {(Compare|void)} value - input value +* @throws {TypeError} must be a compare instance +* @returns {void} +*/ +function set( value ) { + if ( !isCompare( value ) && !isUndefined( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a compare instance. Value: `%s`.', prop.name, value ) ); + } + if ( value !== this[ prop.private ] ) { + this._removeChangeListener( this[ prop.private ] ); + debug( 'Current value: %s. New value: %s.', JSON.stringify( this[ prop.private ] ), JSON.stringify( value ) ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + this._addChangeListener( this[ prop.private ] ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/collect/package.json b/lib/node_modules/@stdlib/plot/vega/transform/collect/package.json new file mode 100644 index 000000000000..25ef619b06dd --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/collect/package.json @@ -0,0 +1,61 @@ +{ + "name": "@stdlib/plot/vega/transform/collect", + "version": "0.0.0", + "description": "Collect transform 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", + "transform", + "collect", + "constructor", + "ctor" + ], + "__stdlib__": {} +}