From a9e338f6c4e465f658159871aaacbf21e87e5026 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sat, 25 Apr 2026 02:06:58 +0530 Subject: [PATCH] feat: add plot/vega/mark/facet --- .../plot/vega/mark/facet/examples/index.js | 35 ++ .../plot/vega/mark/facet/lib/aggregate/get.js | 43 ++ .../mark/facet/lib/aggregate/properties.js | 33 ++ .../plot/vega/mark/facet/lib/aggregate/set.js | 68 +++ .../plot/vega/mark/facet/lib/change_event.js | 41 ++ .../plot/vega/mark/facet/lib/data/get.js | 43 ++ .../vega/mark/facet/lib/data/properties.js | 33 ++ .../plot/vega/mark/facet/lib/data/set.js | 61 +++ .../plot/vega/mark/facet/lib/field/get.js | 43 ++ .../vega/mark/facet/lib/field/properties.js | 33 ++ .../plot/vega/mark/facet/lib/field/set.js | 63 +++ .../plot/vega/mark/facet/lib/groupby/get.js | 46 ++ .../vega/mark/facet/lib/groupby/properties.js | 33 ++ .../plot/vega/mark/facet/lib/groupby/set.js | 77 +++ .../@stdlib/plot/vega/mark/facet/lib/index.js | 50 ++ .../@stdlib/plot/vega/mark/facet/lib/main.js | 448 ++++++++++++++++++ .../plot/vega/mark/facet/lib/name/get.js | 43 ++ .../vega/mark/facet/lib/name/properties.js | 33 ++ .../plot/vega/mark/facet/lib/name/set.js | 61 +++ .../plot/vega/mark/facet/lib/properties.json | 7 + .../vega/mark/facet/lib/properties/get.js | 41 ++ .../@stdlib/plot/vega/mark/facet/package.json | 61 +++ 22 files changed, 1396 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/examples/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/change_event.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/properties.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/set.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/properties.json create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/lib/properties/get.js create mode 100644 lib/node_modules/@stdlib/plot/vega/mark/facet/package.json diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/examples/index.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/examples/index.js new file mode 100644 index 000000000000..7629d5a01189 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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 Field = require( '@stdlib/plot/vega/field/ctor' ); +var Facet = require( './../lib' ); + +var field = new Field({ + 'field': 'sum', + 'as': 'sum_field' +}); +var facet = new Facet({ + 'data': 'foo bar', + 'field': field, + 'groupby': field, + 'name': 'beep boop' +}); + +console.log( facet.toJSON() ); diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/get.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/get.js new file mode 100644 index 000000000000..772151ef9b1a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/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 X. +* +* @private +* @returns {(Object|void)} aggregate data items +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/properties.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/properties.js new file mode 100644 index 000000000000..907dc943d124 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/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( 'aggregate' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/set.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/set.js new file mode 100644 index 000000000000..fde3d76c69ca --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/aggregate/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 isAggregateFacetTransform = require( '@stdlib/plot/vega/base/assert/is-aggregate-facet-transform' ); +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:facet-mark:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the X. +* +* ## Notes +* +* - Providing `undefined` "unsets" the configured value. +* +* @private +* @param {(Field|void)} value - input value +* @throws {TypeError} must be a aggregate-facet instance +* @returns {void} +*/ +function set( value ) { + if ( !isAggregateFacetTransform( value ) && !isUndefined( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a aggregate-facet 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/mark/facet/lib/change_event.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/change_event.js new file mode 100644 index 000000000000..359afbfa206b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/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': 'mark', + 'property': property + }; +} + + +// EXPORTS // + +module.exports = event; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/get.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/get.js new file mode 100644 index 000000000000..18ff95b2ff7b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/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 X. +* +* @private +* @returns {string} data +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/properties.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/properties.js new file mode 100644 index 000000000000..2e4970225343 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/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( 'data' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/set.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/set.js new file mode 100644 index 000000000000..9005d67747f2 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/data/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:facet-mark:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the X. +* +* @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/mark/facet/lib/field/get.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/get.js new file mode 100644 index 000000000000..d77e5d13fdd6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/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 X. +* +* @private +* @returns {Field} field +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/properties.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/properties.js new file mode 100644 index 000000000000..639ddb612903 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/properties.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var property2object = require( '@stdlib/plot/vega/base/property2object' ); + + +// MAIN // + +var obj = property2object( 'field' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/set.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/set.js new file mode 100644 index 000000000000..8e9599fde380 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/field/set.js @@ -0,0 +1,63 @@ +/** +* @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 isField = require( '@stdlib/plot/vega/base/assert/is-field' ); +var format = require( '@stdlib/string/format' ); +var changeEvent = require( './../change_event.js' ); +var prop = require( './properties.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:facet-mark:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the x. +* +* @private +* @param {Field} value - input value +* @throws {TypeError} must be a field instance +* @returns {void} +*/ +function set( value ) { + if ( !isField( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a field 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/mark/facet/lib/groupby/get.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/get.js new file mode 100644 index 000000000000..3cf3bdc799bb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/get.js @@ -0,0 +1,46 @@ +/** +* @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 isFieldArray = require( '@stdlib/plot/vega/base/assert/is-field-array' ); +var copy = require( '@stdlib/utils/copy' ); +var prop = require( './properties.js' ); + + +// MAIN // + +/** +* Returns the X. +* +* @private +* @returns {(Field|Array)} field +*/ +function get() { + var v = this[ prop.private ]; + return ( isFieldArray( v ) ) ? copy( v ) : [ v ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/properties.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/properties.js new file mode 100644 index 000000000000..9132e7e77a3a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/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( 'groupby' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/set.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/set.js new file mode 100644 index 000000000000..0feaed8e4b75 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/groupby/set.js @@ -0,0 +1,77 @@ +/** +* @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 isField = require( '@stdlib/plot/vega/base/assert/is-field' ); +var isFieldArray = require( '@stdlib/plot/vega/base/assert/is-field-array' ); + +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); +var changeEvent = require( './../change_event.js' ); +var prop = require( './properties.js' ); +const isUndefined = require('@stdlib/assert/is-undefined'); + + +// VARIABLES // + +var debug = logger( 'vega:facet-mark:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the x. +* +* @private +* @param {Field|FieldArray} value - input value +* @throws {TypeError} must be a field instance or an array of field instances +* @returns {void} +*/ +function set( value ) { + var isArr; + + isArr = isFieldArray( value ); + if ( !isField( value ) && !isArr ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a field instance or an array of field instances. Value: `%s`.', prop.name, value ) ); + } + if ( isArr ) { + value = copy( value ); + } else { + value = [ value ]; + } + if ( value != this[ prop.private ] ) { + if ( !isUndefined( this[ prop.private ] ) ) { + this._removeChangeListeners( 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._addChangeListeners( this[ prop.private ] ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/index.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/index.js new file mode 100644 index 000000000000..45265eade979 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/index.js @@ -0,0 +1,50 @@ +/** +* @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'; + +/** +* Facet constructor. +* +* @module @stdlib/plot/vega/mark/facet +* +* @example +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* var Facet = require( '@stdlib/plot/vega/mark/facet' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var facet = new Facet({ +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/main.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/main.js new file mode 100644 index 000000000000..5d602469ddeb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/main.js @@ -0,0 +1,448 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var EventEmitter = require( 'events' ).EventEmitter; +var logger = require( 'debug' ); +var isObject = require( '@stdlib/assert/is-object' ); +var 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 getAggregate = require( './aggregate/get.js' ); +var setAggregate = require( './aggregate/set.js' ); + +var getData = require( './data/get.js' ); +var setData = require( './data/set.js' ); + +var getField = require( './field/get.js' ); +var setField = require( './field/set.js' ); + +var getGroupby = require( './groupby/get.js' ); +var setGroupby = require( './groupby/set.js' ); + +var getName = require( './name/get.js' ); +var setName = require( './name/set.js' ); + +var getProperties = require( './properties/get.js' ); + + +// VARIABLES // + +var debug = logger( 'vega:facet-mark:main' ); + + +// MAIN // + +/** +* Facet constructor. +* +* @constructor +* @param {Options} [options] - constructor options +* @param {Object} [options.aggregate] - +* @param {string} [options.data] - +* @param {Field} [options.field] - +* @param {Field|Array} [options.groupby] - +* @param {string} [options.name] - +* @throws {TypeError} options argument must be an object +* @throws {Error} must provide valid options +* @returns {Facet} facet instance +* +* @example +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var facet = new Facet({ +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* // returns +*/ +function Facet( options ) { + var nargs; + var self; + var v; + var k; + var i; + + nargs = arguments.length; + if ( !( this instanceof Facet ) ) { + if ( nargs ) { + return new Facet( options ); + } + return new Facet(); + } + self = this; + EventEmitter.call( this ); + + // Define an internal change event listener: + this._onChange = onChange; + + // Add change listeners to default event emitters: + this._addChangeListener( this._aggregate ); + this._addChangeListener( this._field ); + this._addChangeListener( this._groupby ); + + if ( nargs ) { + 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, 'data' ) ) { + throw new TypeError( 'invalid argument. Options argument must specify the facet data.' ); + } + if ( !hasProp( options, 'field' ) ) { + throw new TypeError( 'invalid argument. Options argument must specify the facet field.' ); + } + if ( !hasProp( options, 'groupby' ) ) { + throw new TypeError( 'invalid argument. Options argument must specify the facet groupby.' ); + } + if ( !hasProp( options, 'name' ) ) { + throw new TypeError( 'invalid argument. Options argument must specify the facet name.' ); + } + // 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 facet the `EventEmitter` prototype. +*/ +inherit( Facet, EventEmitter ); + +/** +* Constructor name. +* +* @private +* @name name +* @memberof Facet +* @readonly +* @type {string} +*/ +setNonEnumerableReadOnly( Facet, 'name', 'Facet' ); + +/** +* Adds an internal listener to a change event on a child instance. +* +* @private +* @name _addChangeListener +* @memberof Facet.prototype +* @type {Function} +* @param {Object} emitter - event emitter +* @returns {Facet} facet instance +*/ +setNonEnumerableReadOnly( Facet.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 Facet.prototype +* @type {Function} +* @param {ArrayLikeObject} emitters - list of event emitters +* @returns {Facet} facet instance +*/ +setNonEnumerableReadOnly( Facet.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 Facet.prototype +* @type {Function} +* @param {Object} emitter - event emitter +* @returns {Facet} facet instance +*/ +setNonEnumerableReadOnly( Facet.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 Facet.prototype +* @type {Function} +* @param {ArrayLikeObject} emitters - list of event emitters +* @returns {Facet} facet instance +*/ +setNonEnumerableReadOnly( Facet.prototype, '_removeChangeListeners', function removeChangeListeners( emitters ) { + var i; + for ( i = 0; i < emitters.length; i++ ) { + this._removeChangeListener( emitters[ i ] ); + } + return this; +}); + +/** +* AGGREGATE +* +* @name aggregate +* @memberof Facet.prototype +* @type {(Object|void)} +* +* @example +* var AggregateFacetTransform = require( '@stdlib/plot/vega/transform/' ); +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var transform = new AggregateFacetTransform(); +* +* var facet = new Facet({ +* 'aggregate': transform, +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* +* var v = facet.aggregate; +* // returns +*/ +setReadWriteAccessor( Facet.prototype, 'aggregate', getAggregate, setAggregate ); + +/** +* DATA +* +* @name data +* @memberof Facet.prototype +* @type {string} +* +* @example +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var facet = new Facet({ +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* +* var v = facet.data; +* // returns 'foo bar' +*/ +setReadWriteAccessor( Facet.prototype, 'data', getData, setData ); + +/** +* FIELD +* +* @name field +* @memberof Facet.prototype +* @type {Field} +* +* @example +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var facet = new Facet({ +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* +* var v = facet.field; +* // returns +*/ +setReadWriteAccessor( Facet.prototype, 'field', getField, setField ); + +/** +* GROUPBY +* +* @name groupby +* @memberof Facet.prototype +* @type {(Field|Array)} +* +* @example +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var facet = new Facet({ +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* +* var v = facet.groupby; +* // returns +*/ +setReadWriteAccessor( Facet.prototype, 'groupby', getGroupby, setGroupby ); + +/** +* NAME +* +* @name name +* @memberof Facet.prototype +* @type {string} +* +* @example +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var facet = new Facet({ +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* +* var v = facet.name; +* // returns 'beep boop' +*/ +setReadWriteAccessor( Facet.prototype, 'name', getName, setName ); + +/** +* Facet properties. +* +* @name properties +* @memberof Facet.prototype +* @type {Array} +* +* @example +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var facet = new Facet({ +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* +* var v = facet.properties; +* // returns [...] +*/ +setNonEnumerableReadOnlyAccessor( Facet.prototype, 'properties', getProperties ); + +/** +* Serializes an instance to a JSON object. +* +* ## Notes +* +* - This method is implicitly invoked by `JSON.stringify`. +* +* @name toJSON +* @memberof Facet.prototype +* @type {Function} +* @returns {Object} JSON object +* +* @example +* var Field = require( '@stdlib/plot/vega/field/ctor' ); +* +* var field = new Field({ +* 'field': 'sum', +* 'as': 'sum_field' +* }) +* var facet = new Facet({ +* 'data': 'foo bar', +* 'field': field, +* 'groupby': field, +* 'name': 'beep boop' +* }); +* +* var v = facet.toJSON(); +* // returns {...} +*/ +setNonEnumerableReadOnly( Facet.prototype, 'toJSON', function toJSON() { + return instance2json( this, properties ); +}); + + +// EXPORTS // + +module.exports = Facet; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/get.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/get.js new file mode 100644 index 000000000000..8fbf5ba60752 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/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 X. +* +* @private +* @returns {string} name +*/ +function get() { + return this[ prop.private ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/properties.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/properties.js new file mode 100644 index 000000000000..73c88d38ea23 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/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( 'name' ); + + +// EXPORTS // + +module.exports = obj; diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/set.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/set.js new file mode 100644 index 000000000000..9005d67747f2 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/name/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:facet-mark:set:'+prop.name ); + + +// MAIN // + +/** +* Sets the X. +* +* @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/mark/facet/lib/properties.json b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/properties.json new file mode 100644 index 000000000000..2515c06ffb10 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/properties.json @@ -0,0 +1,7 @@ +[ + "aggregate", + "data", + "field", + "groupby", + "name" +] diff --git a/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/properties/get.js b/lib/node_modules/@stdlib/plot/vega/mark/facet/lib/properties/get.js new file mode 100644 index 000000000000..f3cbb28454ea --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/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/mark/facet/package.json b/lib/node_modules/@stdlib/plot/vega/mark/facet/package.json new file mode 100644 index 000000000000..e0e20382b2d4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/mark/facet/package.json @@ -0,0 +1,61 @@ +{ + "name": "@stdlib/plot/vega/mark/facet", + "version": "0.0.0", + "description": "Facet 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", + "facet", + "mark", + "constructor", + "ctor" + ], + "__stdlib__": {} +}