diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/examples/index.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/examples/index.js new file mode 100644 index 000000000000..2c26c0db959a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/examples/index.js @@ -0,0 +1,28 @@ +/** +* @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 FieldDescriptor = require( './../lib' ); + +var descriptor = new FieldDescriptor({ + 'parent': new FieldDescriptor({ + 'datum': 'f' + }) +}); +console.log( descriptor.toJSON() ); diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/change_event.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/change_event.js new file mode 100644 index 000000000000..cdfeeab3969f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/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': 'value', + 'property': property + }; +} + + +// EXPORTS // + +module.exports = event; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/get.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/get.js new file mode 100644 index 000000000000..0e9600169929 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/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 field lookup on the current data object. +* +* @private +* @returns {(string|FieldDescriptor|void)} field lookup +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/properties.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/properties.js new file mode 100644 index 000000000000..555968fbf7cb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/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( 'datum' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/set.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/set.js new file mode 100644 index 000000000000..3511ad55cce4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/datum/set.js @@ -0,0 +1,66 @@ +/** +* @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 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:value:field-descriptor:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the field lookup on the current data object. +* +* ## Notes +* +* - Providing `undefined` "unsets" the configured value. +* +* @private +* @param {(string|FieldDescriptor|void)} value - input value +* @throws {TypeError} must be a string or a field descriptor instance +* @returns {void} +*/ +function set( value ) { + if ( !isString( value ) && !isUndefined( value ) && !this._isFieldDescriptor( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or a field descriptor instance. Value: `%s`.', prop.name, value ) ); + } + if ( value !== 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 ) ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/defaults.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/defaults.js new file mode 100644 index 000000000000..bf24e8b01aca --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/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 { + // Nesting level for `group` and `parent` references: + 'level': 1 + }; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/get.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/get.js new file mode 100644 index 000000000000..6e5bc8ec7f72 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/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 field lookup on the enclosing group mark instance. +* +* @private +* @returns {(string|FieldDescriptor|void)} field lookup +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/properties.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/properties.js new file mode 100644 index 000000000000..9af1fdbed0fb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/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( 'group' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/set.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/set.js new file mode 100644 index 000000000000..f8d04206f46f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/group/set.js @@ -0,0 +1,66 @@ +/** +* @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 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:value:field-descriptor:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the field lookup on the enclosing group mark instance. +* +* ## Notes +* +* - Providing `undefined` "unsets" the configured value. +* +* @private +* @param {(string|FieldDescriptor|void)} value - input value +* @throws {TypeError} must be a string or a field descriptor instance +* @returns {void} +*/ +function set( value ) { + if ( !isString( value ) && !isUndefined( value ) && !this._isFieldDescriptor( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or a field descriptor instance. Value: `%s`.', prop.name, value ) ); + } + if ( value !== 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 ) ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/index.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/index.js new file mode 100644 index 000000000000..703d88c89bd0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/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'; + +/** +* Field descriptor constructor. +* +* @module @stdlib/plot/vega/value/field-descriptor +* +* @example +* var FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); +* +* var descriptor = new FieldDescriptor({ +* 'datum': 'price' +* }); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/get.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/get.js new file mode 100644 index 000000000000..d2446011f600 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/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 nesting level for `group` and `parent` references. +* +* @private +* @returns {(PositiveInteger|void)} nesting level +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/properties.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/properties.js new file mode 100644 index 000000000000..4a24ed611d44 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/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( 'level' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/set.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/set.js new file mode 100644 index 000000000000..cf4aa59da13f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/level/set.js @@ -0,0 +1,66 @@ +/** +* @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +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:value:field-descriptor:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the nesting level for `group` and `parent` references. +* +* ## Notes +* +* - Providing `undefined` "unsets" the configured value. +* +* @private +* @param {(PositiveInteger|void)} value - input value +* @throws {TypeError} must be a positive integer +* @returns {void} +*/ +function set( value ) { + if ( !isPositiveInteger( value ) && !isUndefined( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a positive integer. Value: `%s`.', prop.name, value ) ); + } + if ( value !== 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 ) ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/main.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/main.js new file mode 100644 index 000000000000..859706fd91d1 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/main.js @@ -0,0 +1,321 @@ +/** +* @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 transformErrorMessage = require( '@stdlib/plot/vega/base/transform-validation-message' ); +var instance2json = require( '@stdlib/plot/vega/base/to-json' ); +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 getDatum = require( './datum/get.js' ); +var setDatum = require( './datum/set.js' ); + +var getGroup = require( './group/get.js' ); +var setGroup = require( './group/set.js' ); + +var getLevel = require( './level/get.js' ); +var setLevel = require( './level/set.js' ); + +var getParent = require( './parent/get.js' ); +var setParent = require( './parent/set.js' ); + +var getProperties = require( './properties/get.js' ); + +var getSignal = require( './signal/get.js' ); +var setSignal = require( './signal/set.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:value:field-descriptor:main' ); + + +// MAIN // + +/** +* Field descriptor constructor. +* +* ## Notes +* +* - Field lookups may be arbitrarily nested in order to perform _indirect_ field lookups (e.g., `{ 'parent': { 'datum': 'f' } }` first retrieves field `f` from the current mark's data and then uses the resolved value as a property name on the parent's data object). +* +* @constructor +* @param {Options} [options] - constructor options +* @param {(string|FieldDescriptor)} [options.datum] - field lookup on the current data object +* @param {(string|FieldDescriptor)} [options.group] - field lookup on the enclosing group mark instance +* @param {PositiveInteger} [options.level=1] - nesting level for `group` and `parent` references +* @param {(string|FieldDescriptor)} [options.parent] - field lookup on the enclosing group mark's data object +* @param {string} [options.signal] - signal name or expression to evaluate and use as the field name to lookup +* @throws {TypeError} options argument must be an object +* @throws {Error} must provide valid options +* @returns {FieldDescriptor} field descriptor instance +* +* @example +* var descriptor = new FieldDescriptor(); +* // returns +*/ +function FieldDescriptor( options ) { + var nargs; + var opts; + var keys; + var v; + var k; + var i; + + nargs = arguments.length; + if ( !( this instanceof FieldDescriptor ) ) { + if ( nargs ) { + return new FieldDescriptor( options ); + } + return new FieldDescriptor(); + } + EventEmitter.call( this ); + + // Set internal properties to undefined... + for ( i = 0; i < properties.length; i++ ) { + this[ '_'+properties[ i ] ] = void 0; + } + // 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 ( nargs ) { + 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( FieldDescriptor, EventEmitter ); + +/** +* Constructor name. +* +* @private +* @name name +* @memberof FieldDescriptor +* @readonly +* @type {string} +*/ +setNonEnumerableReadOnly( FieldDescriptor, 'name', 'FieldDescriptor' ); + +/** +* Returns a boolean indicating if a value is a field descriptor instance. +* +* ## Notes +* +* - This method is intended for use within this class only and is present in order to avoid a circular dependency on `@stdlib/plot/vega/base/assert/is-value-field-descriptor`. The method should use the same brand checks. +* +* @private +* @name _isFieldDescriptor +* @memberof FieldDescriptor.prototype +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a field descriptor instance +*/ +setNonEnumerableReadOnly( FieldDescriptor.prototype, '_isFieldDescriptor', function isFieldDescriptor( value ) { + return ( + value instanceof FieldDescriptor || + + // The following is a set of rather imperfect heuristics for handling instances originating in a different realm... + ( + isObject( value ) && + ( + hasProp( value, 'datum' ) || + hasProp( value, 'group' ) || + hasProp( value, 'parent' ) || + hasProp( value, 'signal' ) + ) + ) + ); +}); + +/** +* Field lookup on the current data object. +* +* @name datum +* @memberof FieldDescriptor.prototype +* @type {(string|FieldDescriptor|void)} +* @default undefined +* +* @example +* var descriptor = new FieldDescriptor({ +* 'datum': 'price' +* }); +* +* var v = descriptor.datum; +* // returns 'price' +*/ +setReadWriteAccessor( FieldDescriptor.prototype, 'datum', getDatum, setDatum ); + +/** +* Field lookup on the enclosing group mark instance. +* +* @name group +* @memberof FieldDescriptor.prototype +* @type {(string|FieldDescriptor|void)} +* @default undefined +* +* @example +* var descriptor = new FieldDescriptor({ +* 'group': 'width' +* }); +* +* var v = descriptor.group; +* // returns 'width' +*/ +setReadWriteAccessor( FieldDescriptor.prototype, 'group', getGroup, setGroup ); + +/** +* Nesting level for `group` and `parent` references. +* +* @name level +* @memberof FieldDescriptor.prototype +* @type {(PositiveInteger|void)} +* @default 1 +* +* @example +* var descriptor = new FieldDescriptor({ +* 'parent': 'price', +* 'level': 2 +* }); +* +* var v = descriptor.level; +* // returns 2 +*/ +setReadWriteAccessor( FieldDescriptor.prototype, 'level', getLevel, setLevel ); + +/** +* Field lookup on the enclosing group mark's data object. +* +* @name parent +* @memberof FieldDescriptor.prototype +* @type {(string|FieldDescriptor|void)} +* @default undefined +* +* @example +* var descriptor = new FieldDescriptor({ +* 'parent': 'price' +* }); +* +* var v = descriptor.parent; +* // returns 'price' +*/ +setReadWriteAccessor( FieldDescriptor.prototype, 'parent', getParent, setParent ); + +/** +* Field descriptor properties. +* +* @name properties +* @memberof FieldDescriptor.prototype +* @type {Array} +* +* @example +* var descriptor = new FieldDescriptor(); +* +* var v = descriptor.properties; +* // returns [...] +*/ +setNonEnumerableReadOnlyAccessor( FieldDescriptor.prototype, 'properties', getProperties ); + +/** +* Signal name or expression to evaluate and use as the field name to lookup. +* +* @name signal +* @memberof FieldDescriptor.prototype +* @type {(string|void)} +* @default undefined +* +* @example +* var descriptor = new FieldDescriptor({ +* 'signal': 'fieldName' +* }); +* +* var v = descriptor.signal; +* // returns 'fieldName' +*/ +setReadWriteAccessor( FieldDescriptor.prototype, 'signal', getSignal, setSignal ); + +/** +* Serializes an instance to a JSON object. +* +* ## Notes +* +* - This method is implicitly invoked by `JSON.stringify`. +* +* @name toJSON +* @memberof FieldDescriptor.prototype +* @type {Function} +* @returns {Object} JSON object +* +* @example +* var descriptor = new FieldDescriptor({ +* 'datum': 'price' +* }); +* +* var json = descriptor.toJSON(); +* // returns {...} +*/ +setNonEnumerableReadOnly( FieldDescriptor.prototype, 'toJSON', function toJSON() { + return instance2json( this, properties ); +}); + + +// EXPORTS // + +module.exports = FieldDescriptor; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/get.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/get.js new file mode 100644 index 000000000000..d6eaf172f986 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/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 field lookup on the enclosing group mark's data object. +* +* @private +* @returns {(string|FieldDescriptor|void)} field lookup +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/properties.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/properties.js new file mode 100644 index 000000000000..7df7a718639d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/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( 'parent' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/set.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/set.js new file mode 100644 index 000000000000..ae418f0f927c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/parent/set.js @@ -0,0 +1,66 @@ +/** +* @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 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:value:field-descriptor:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the field lookup on the enclosing group mark's data object. +* +* ## Notes +* +* - Providing `undefined` "unsets" the configured value. +* +* @private +* @param {(string|FieldDescriptor|void)} value - input value +* @throws {TypeError} must be a string or a field descriptor instance +* @returns {void} +*/ +function set( value ) { + if ( !isString( value ) && !isUndefined( value ) && !this._isFieldDescriptor( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or a field descriptor instance. Value: `%s`.', prop.name, value ) ); + } + if ( value !== 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 ) ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/properties.json b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/properties.json new file mode 100644 index 000000000000..8ab269fd0099 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/properties.json @@ -0,0 +1,7 @@ +[ + "datum", + "group", + "level", + "parent", + "signal" +] diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/properties/get.js new file mode 100644 index 000000000000..f3cbb28454ea --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/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/value/field-descriptor/lib/signal/get.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/signal/get.js new file mode 100644 index 000000000000..0ec0be8b313b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/signal/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 signal name or expression to evaluate and use as the field name to lookup. +* +* @private +* @returns {(string|void)} signal +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/signal/properties.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/signal/properties.js new file mode 100644 index 000000000000..9a15daba64d4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/signal/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( 'signal' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/signal/set.js b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/signal/set.js new file mode 100644 index 000000000000..981156584e7d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/lib/signal/set.js @@ -0,0 +1,66 @@ +/** +* @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 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:value:field-descriptor:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the signal name or expression to evaluate and use as the field name to lookup. +* +* ## Notes +* +* - Providing `undefined` "unsets" the configured value. +* +* @private +* @param {(string|void)} value - input value +* @throws {TypeError} must be a string +* @returns {void} +*/ +function set( value ) { + if ( !isString( value ) && !isUndefined( 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.', JSON.stringify( this[ prop.private ] ), JSON.stringify( value ) ); + this[ prop.private ] = value; + this.emit( 'change', changeEvent( prop.name ) ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/package.json b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/package.json new file mode 100644 index 000000000000..bbf6cf34f07a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/value/field-descriptor/package.json @@ -0,0 +1,62 @@ +{ + "name": "@stdlib/plot/vega/value/field-descriptor", + "version": "0.0.0", + "description": "Field descriptor 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", + "value", + "field-descriptor", + "encoding", + "constructor", + "ctor" + ], + "__stdlib__": {} +}