From a6c9ecc4761ada20eb62f8786c313299378187ab Mon Sep 17 00:00:00 2001 From: Sachinn-64 Date: Thu, 2 Jul 2026 14:36:28 +0530 Subject: [PATCH] feat: add plot/vega/transform/filter --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../vega/transform/filter/examples/index.js | 27 +++ .../vega/transform/filter/lib/change_event.js | 41 ++++ .../vega/transform/filter/lib/expr/get.js | 43 +++++ .../transform/filter/lib/expr/properties.js | 33 ++++ .../vega/transform/filter/lib/expr/set.js | 61 ++++++ .../plot/vega/transform/filter/lib/index.js | 42 ++++ .../plot/vega/transform/filter/lib/main.js | 182 ++++++++++++++++++ .../vega/transform/filter/lib/properties.json | 3 + .../transform/filter/lib/properties/get.js | 41 ++++ .../plot/vega/transform/filter/package.json | 61 ++++++ 10 files changed, 534 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/examples/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/lib/change_event.js create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/lib/properties.json create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/lib/properties/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/transform/filter/package.json diff --git a/lib/node_modules/@stdlib/plot/vega/transform/filter/examples/index.js b/lib/node_modules/@stdlib/plot/vega/transform/filter/examples/index.js new file mode 100644 index 000000000000..743716f875ef --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/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 FilterTransform = require( './../lib' ); + +var transform = new FilterTransform({ + 'expr': 'datum.x > 10' +}); + +console.log( transform.toJSON() ); diff --git a/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/change_event.js b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/change_event.js new file mode 100644 index 000000000000..e444f9c667b0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/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/filter/lib/expr/get.js b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/get.js new file mode 100644 index 000000000000..02b055120c6c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/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 predicate expression for filtering. If the expression evaluates to false, the data object will be filtered. +* +* @private +* @returns {string} expression +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/properties.js b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/properties.js new file mode 100644 index 000000000000..07fc9fe6515e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/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( 'expr' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/set.js b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/set.js new file mode 100644 index 000000000000..49b169b5087c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/expr/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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var changeEvent = require( './../change_event.js' ); +var prop = require( './properties.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:filter-transform:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the predicate expression for filtering. If the expression evaluates to false, the data object will be filtered. +* +* @private +* @param {string} value - input value +* @throws {TypeError} must be a string +* @returns {void} +*/ +function set( value ) { + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. 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/filter/lib/index.js b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/index.js new file mode 100644 index 000000000000..5376dfa3e556 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/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'; + +/** +* Filter transform constructor. +* +* @module @stdlib/plot/vega/transform/filter +* +* @example +* var FilterTransform = require( '@stdlib/plot/vega/transform/filter' ); +* +* var transform = new FilterTransform({ +* 'expr': 'datum.x > 10' +* }); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/main.js b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/main.js new file mode 100644 index 000000000000..0dbabb463501 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/main.js @@ -0,0 +1,182 @@ +/** +* @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 getExpr = require( './expr/get.js' ); +var setExpr = require( './expr/set.js' ); + +var getProperties = require( './properties/get.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:filter-transform:main' ); + + +// MAIN // + +/** +* Filter transform constructor. +* +* @constructor +* @param {Options} options - constructor options +* @param {string} options.expr - predicate expression for filtering the data +* @throws {TypeError} options argument must be an object +* @throws {Error} must provide valid options +* @returns {FilterTransform} filter transform instance +* +* @example +* var transform = new FilterTransform({ +* 'expr': 'datum.x > 10' +* }); +* // returns +*/ +function FilterTransform( options ) { + var v; + var k; + var i; + if ( !( this instanceof FilterTransform ) ) { + return new FilterTransform( options ); + } + EventEmitter.call( this ); + + 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, 'expr' ) ) { + throw new TypeError( 'invalid argument. Options argument must specify a predicate expression for filtering the data.' ); + } + + // 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( FilterTransform, EventEmitter ); + +/** +* Constructor name. +* +* @private +* @name name +* @memberof FilterTransform +* @readonly +* @type {string} +*/ +setNonEnumerableReadOnly( FilterTransform, 'name', 'FilterTransform' ); + +/** +* Predicate expression for filtering. If the expression evaluates to false, the data object will be filtered. +* +* @name expr +* @memberof FilterTransform.prototype +* @type {string} +* +* @example +* var transform = new FilterTransform({ +* 'expr': 'datum.x > 10' +* }); +* +* var v = transform.expr; +* // returns 'datum.x > 10' +*/ +setReadWriteAccessor( FilterTransform.prototype, 'expr', getExpr, setExpr ); + +/** +* Filter transform properties. +* +* @name properties +* @memberof FilterTransform.prototype +* @type {Array} +* +* @example +* var transform = new FilterTransform({ +* 'expr': 'datum.x > 10' +* }); +* +* var v = transform.properties; +* // returns [...] +*/ +setNonEnumerableReadOnlyAccessor( FilterTransform.prototype, 'properties', getProperties ); + +/** +* Serializes an instance to a JSON object. +* +* ## Notes +* +* - This method is implicitly invoked by `JSON.stringify`. +* +* @name toJSON +* @memberof FilterTransform.prototype +* @type {Function} +* @returns {Object} JSON object +* +* @example +* var transform = new FilterTransform({ +* 'expr': 'datum.x > 10' +* }); +* +* var v = transform.toJSON(); +* // returns {...} +*/ +setNonEnumerableReadOnly( FilterTransform.prototype, 'toJSON', function toJSON() { + return instance2json( this, properties ); +}); + + +// EXPORTS // + +module.exports = FilterTransform; diff --git a/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/properties.json b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/properties.json new file mode 100644 index 000000000000..d0f148875508 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/properties.json @@ -0,0 +1,3 @@ +[ + "expr" +] diff --git a/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/transform/filter/lib/properties/get.js new file mode 100644 index 000000000000..f3cbb28454ea --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/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/filter/package.json b/lib/node_modules/@stdlib/plot/vega/transform/filter/package.json new file mode 100644 index 000000000000..8c077a31ef5f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/transform/filter/package.json @@ -0,0 +1,61 @@ +{ + "name": "@stdlib/plot/vega/transform/filter", + "version": "0.0.0", + "description": "Filter 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", + "filter", + "constructor", + "ctor" + ], + "__stdlib__": {} +}