Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var SampleTransform = require( './../lib' );

var transform = new SampleTransform({
'size': 500
});

console.log( transform.toJSON() );
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MAIN //

/**
* Returns defaults.
*
* @private
* @returns {Object} default options
*
* @example
* var o = defaults();
* // returns {...}
*/
function defaults() {
return {
// The maximum number of data objects to include in the sample:
'size': 1000
};
}


// EXPORTS //

module.exports = defaults;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/**
* Sample transform constructor.
*
* @module @stdlib/plot/vega/transform/sample/ctor
*
* @example
* var SampleTransform = require( '@stdlib/plot/vega/transform/sample/ctor' );
*
* var transform = new SampleTransform({
* 'size': 500
* });
* // returns <SampleTransform>
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
199 changes: 199 additions & 0 deletions lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-disable no-restricted-syntax, no-invalid-this, stdlib/no-empty-lines-between-requires */

'use strict';

// MODULES //

var EventEmitter = require( 'events' ).EventEmitter;
var logger = require( 'debug' );
var isObject = require( '@stdlib/assert/is-object' );
var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
var setNonEnumerableReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); // eslint-disable-line id-length
var setReadWriteAccessor = require( '@stdlib/utils/define-read-write-accessor' );
var hasProp = require( '@stdlib/assert/has-property' );
var inherit = require( '@stdlib/utils/inherit' );
var objectKeys = require( '@stdlib/utils/keys' );
var instance2json = require( '@stdlib/plot/vega/base/to-json' );
var transformErrorMessage = require( '@stdlib/plot/vega/base/transform-validation-message' );
var format = require( '@stdlib/string/format' );
var properties = require( './properties.json' );
var defaults = require( './defaults.js' );

// Note: keep the following in alphabetical order according to the `require` path...
var getProperties = require( './properties/get.js' );

var getSize = require( './size/get.js' );
var setSize = require( './size/set.js' );


// VARIABLES //

var debug = logger( 'vega:sample-transform:main' );


// MAIN //

/**
* Sample transform constructor.
*
* @constructor
* @param {Options} options - constructor options
* @param {NonNegativeNumber} [options.size=1000] - maximum number of data objects to include in the sample
* @throws {TypeError} options argument must be an object
* @throws {Error} must provide valid options
* @returns {SampleTransform} sample transform instance
*
* @example
* var transform = new SampleTransform({
* 'size': 500
* });
* // returns <SampleTransform>
*/
function SampleTransform( options ) {
var opts;
var keys;
var v;
var k;
var i;
if ( !( this instanceof SampleTransform ) ) {
if ( arguments.length ) {
return new SampleTransform( options );
}
return new SampleTransform();
}
EventEmitter.call( this );

// Resolve the default configuration:
opts = defaults();

// Set internal properties according to the default configuration...
keys = objectKeys( opts );
for ( i = 0; i < keys.length; i++ ) {
k = keys[ i ];
this[ '_'+k ] = opts[ k ];
}

// If no options were provided, return early with defaults...
if ( arguments.length === 0 ) {
return this;
}
if ( !isObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}

// Validate provided options by attempting to assign option values to corresponding fields...
for ( i = 0; i < properties.length; i++ ) {
k = properties[ i ];
if ( !hasProp( options, k ) ) {
continue;
}
v = options[ k ];
try {
this[ k ] = v;
} catch ( err ) {
debug( 'Encountered an error. Error: %s', err.message );

// FIXME: retain thrown error type

Check warning on line 114 in lib/node_modules/@stdlib/plot/vega/transform/sample/ctor/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: retain thrown error type'
throw new Error( transformErrorMessage( err.message ) );
}
}
return this;
}

/*
* Inherit from the `EventEmitter` prototype.
*/
inherit( SampleTransform, EventEmitter );

/**
* Constructor name.
*
* @private
* @name name
* @memberof SampleTransform
* @readonly
* @type {string}
*/
setNonEnumerableReadOnly( SampleTransform, 'name', 'SampleTransform' );

/**
* Maximum number of data objects to include in the sample.
*
* @name size
* @memberof SampleTransform.prototype
* @type {NonNegativeNumber}
* @default 1000
*
* @example
* var transform = new SampleTransform({
* 'size': 500
* });
*
* var v = transform.size;
* // returns 500
*/
setReadWriteAccessor( SampleTransform.prototype, 'size', getSize, setSize );

/**
* Sample transform properties.
*
* @name properties
* @memberof SampleTransform.prototype
* @type {Array<string>}
*
* @example
* var transform = new SampleTransform({
* 'size': 500
* });
*
* var v = transform.properties;
* // returns [...]
*/
setNonEnumerableReadOnlyAccessor( SampleTransform.prototype, 'properties', getProperties );

/**
* Serializes an instance to a JSON object.
*
* ## Notes
*
* - This method is implicitly invoked by `JSON.stringify`.
*
* @name toJSON
* @memberof SampleTransform.prototype
* @type {Function}
* @returns {Object} JSON object
*
* @example
* var transform = new SampleTransform({
* 'size': 500
* });
*
* var v = transform.toJSON();
* // returns {...}
*/
setNonEnumerableReadOnly( SampleTransform.prototype, 'toJSON', function toJSON() {
return instance2json( this, properties );
});


// EXPORTS //

module.exports = SampleTransform;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"size"
]
Loading
Loading