diff --git a/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/examples/index.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/examples/index.js new file mode 100644 index 000000000000..752940238ccc --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/examples/index.js @@ -0,0 +1,27 @@ +/** +* @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 SampleTransform = require( './../lib' ); + +var transform = new SampleTransform({ + 'size': 500 +}); + +console.log( transform.toJSON() ); diff --git a/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/change_event.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/change_event.js new file mode 100644 index 000000000000..e444f9c667b0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/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/sample/ctor/lib/defaults.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/defaults.js new file mode 100644 index 000000000000..818c29ae1eb6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/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 { + // The maximum number of data objects to include in the sample: + 'size': 1000 + }; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/index.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/index.js new file mode 100644 index 000000000000..23e974f7b729 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/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'; + +/** +* Sample transform constructor. +* +* @module @stdlib/plot/vega/transform/sample/ctor +* +* @example +* var SampleTransform = require( '@stdlib/plot/vega/transform/sample/ctor' ); +* +* var transform = new SampleTransform({ +* 'size': 500 +* }); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/main.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/main.js new file mode 100644 index 000000000000..a6f89a0673ea --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/main.js @@ -0,0 +1,199 @@ +/** +* @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 objectKeys = require( '@stdlib/utils/keys' ); +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 getProperties = require( './properties/get.js' ); + +var getSize = require( './size/get.js' ); +var setSize = require( './size/set.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:sample-transform:main' ); + + +// MAIN // + +/** +* Sample transform constructor. +* +* @constructor +* @param {Options} options - constructor options +* @param {NonNegativeNumber} [options.size=1000] - maximum number of data objects to include in the sample +* @throws {TypeError} options argument must be an object +* @throws {Error} must provide valid options +* @returns {SampleTransform} sample transform instance +* +* @example +* var transform = new SampleTransform({ +* 'size': 500 +* }); +* // returns +*/ +function SampleTransform( options ) { + var opts; + var keys; + var v; + var k; + var i; + if ( !( this instanceof SampleTransform ) ) { + if ( arguments.length ) { + return new SampleTransform( options ); + } + return new SampleTransform(); + } + EventEmitter.call( this ); + + // 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 ]; + } + + // If no options were provided, return early with defaults... + if ( arguments.length === 0 ) { + return this; + } + if ( !isObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + + // 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 the `EventEmitter` prototype. +*/ +inherit( SampleTransform, EventEmitter ); + +/** +* Constructor name. +* +* @private +* @name name +* @memberof SampleTransform +* @readonly +* @type {string} +*/ +setNonEnumerableReadOnly( SampleTransform, 'name', 'SampleTransform' ); + +/** +* Maximum number of data objects to include in the sample. +* +* @name size +* @memberof SampleTransform.prototype +* @type {NonNegativeNumber} +* @default 1000 +* +* @example +* var transform = new SampleTransform({ +* 'size': 500 +* }); +* +* var v = transform.size; +* // returns 500 +*/ +setReadWriteAccessor( SampleTransform.prototype, 'size', getSize, setSize ); + +/** +* Sample transform properties. +* +* @name properties +* @memberof SampleTransform.prototype +* @type {Array} +* +* @example +* var transform = new SampleTransform({ +* 'size': 500 +* }); +* +* var v = transform.properties; +* // returns [...] +*/ +setNonEnumerableReadOnlyAccessor( SampleTransform.prototype, 'properties', getProperties ); + +/** +* Serializes an instance to a JSON object. +* +* ## Notes +* +* - This method is implicitly invoked by `JSON.stringify`. +* +* @name toJSON +* @memberof SampleTransform.prototype +* @type {Function} +* @returns {Object} JSON object +* +* @example +* var transform = new SampleTransform({ +* 'size': 500 +* }); +* +* var v = transform.toJSON(); +* // returns {...} +*/ +setNonEnumerableReadOnly( SampleTransform.prototype, 'toJSON', function toJSON() { + return instance2json( this, properties ); +}); + + +// EXPORTS // + +module.exports = SampleTransform; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/properties.json b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/properties.json new file mode 100644 index 000000000000..d7dca0202285 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/properties.json @@ -0,0 +1,3 @@ +[ + "size" +] diff --git a/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/properties/get.js new file mode 100644 index 000000000000..f3cbb28454ea --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/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/sample/ctor/lib/size/get.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/size/get.js new file mode 100644 index 000000000000..2d320c386670 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/size/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 maximum number of data objects to include in the sample. +* +* @private +* @returns {number} sample size +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/size/properties.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/size/properties.js new file mode 100644 index 000000000000..bf1bd182f0eb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/size/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( 'size' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/size/set.js b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/size/set.js new file mode 100644 index 000000000000..0da5a0be061b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/size/set.js @@ -0,0 +1,61 @@ +/** +* @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 isNonNegativeNumber = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var changeEvent = require( './../change_event.js' ); +var prop = require( './properties.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:sample-transform:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the maximum number of data objects to include in the sample. +* +* @private +* @param {NonNegativeNumber} value - input value +* @throws {TypeError} must be a nonnegative number +* @returns {void} +*/ +function set( value ) { + if ( !isNonNegativeNumber( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a number. Value: `%s`.', prop.name, 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/transform/sample/ctor/package.json b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/package.json new file mode 100644 index 000000000000..496283c4efcc --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/package.json @@ -0,0 +1,61 @@ +{ + "name": "@stdlib/plot/vega/transform/sample/ctor", + "version": "0.0.0", + "description": "Sample 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", + "sample", + "constructor", + "ctor" + ], + "__stdlib__": {} +}