Skip to content

Commit c9d2906

Browse files
committed
refactor: ensure all properties have defaults and disallow undefined
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 04656cd commit c9d2906

File tree

18 files changed

+75
-104
lines changed

18 files changed

+75
-104
lines changed

lib/node_modules/@stdlib/plot/vega/visualization/lib/autosize/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Returns the autosize configuration.
2727
*
2828
* @private
29-
* @returns {(void|string|Autosize|Signal)} autosize configuration
29+
* @returns {(Autosize|Signal)} autosize configuration
3030
*/
3131
function get() {
3232
return this._autosize;

lib/node_modules/@stdlib/plot/vega/visualization/lib/autosize/set.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
var logger = require( 'debug' );
2626
var isAutosize = require( '@stdlib/plot/vega/base/assert/is-autosize' );
2727
var isString = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitive;
28-
var isUndefined = require( '@stdlib/assert/is-undefined' );
2928
var isObject = require( '@stdlib/assert/is-object' );
29+
var Autosize = require( '@stdlib/plot/vega/autosize' );
3030
var format = require( '@stdlib/string/format' );
3131

3232

@@ -40,35 +40,27 @@ var debug = logger( 'vega:visualization:set:autosize' );
4040
/**
4141
* Sets the autosize configuration.
4242
*
43-
* ## Notes
44-
*
45-
* - Providing `undefined` "unsets" the configured value.
46-
*
4743
* @private
48-
* @param {(string|Autosize|Signal|void)} value - input value
44+
* @param {(string|Autosize|Signal)} value - input value
4945
* @throws {TypeError} must be either a string, an autosize instance, or a signal
5046
* @returns {void}
5147
*/
5248
function set( value ) {
53-
var flg = isAutosize( value );
54-
if (
55-
!flg &&
56-
!isString( value ) &&
57-
!isObject( value ) &&
58-
!isUndefined( value )
59-
) {
49+
if ( isString( value ) ) {
50+
value = new Autosize({
51+
'type': value
52+
});
53+
} else if ( isObject( value ) ) {
54+
// TODO: add signal support
55+
} else if ( !isAutosize( value ) ) {
6056
throw new TypeError( format( 'invalid assignment. `%s` must be either a string, an autosize instance, or a signal. Value: `%s`.', 'autosize', value ) );
6157
}
6258
if ( value !== this._autosize ) {
63-
if ( isAutosize( this._autosize ) ) {
64-
this._removeChangeListener( this._autosize );
65-
}
59+
this._removeChangeListener( this._autosize );
6660
debug( 'Current value: %s. New value: %s.', JSON.stringify( this._autosize ), JSON.stringify( value ) );
6761
this._autosize = value;
6862
this.emit( 'change' );
69-
if ( flg ) {
70-
this._addChangeListener( this._autosize );
71-
}
63+
this._addChangeListener( this._autosize );
7264
}
7365
}
7466

lib/node_modules/@stdlib/plot/vega/visualization/lib/config/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Returns the visualization theme.
2727
*
2828
* @private
29-
* @returns {(Config|void)} theme
29+
* @returns {Config} theme
3030
*/
3131
function get() {
3232
return this._config;

lib/node_modules/@stdlib/plot/vega/visualization/lib/config/set.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
// MODULES //
2424

2525
var logger = require( 'debug' );
26-
var isUndefined = require( '@stdlib/assert/is-undefined' );
2726
var isObject = require( '@stdlib/assert/is-object' );
2827
var format = require( '@stdlib/string/format' );
2928

@@ -38,29 +37,21 @@ var debug = logger( 'vega:visualization:set:config' );
3837
/**
3938
* Sets the visualization theme.
4039
*
41-
* ## Notes
42-
*
43-
* - Providing `undefined` "unsets" the configured value.
44-
*
4540
* @private
46-
* @param {(Config|void)} value - input value
41+
* @param {Config} value - input value
4742
* @throws {TypeError} must be a configuration instance
4843
* @returns {void}
4944
*/
5045
function set( value ) {
51-
if ( !isObject( value ) && !isUndefined( value ) ) { // FIXME: validate configuration instance
46+
if ( !isObject( value ) ) { // FIXME: validate configuration instance
5247
throw new TypeError( format( 'invalid assignment. `%s` must be a configuration instance. Value: `%s`.', 'config', value ) );
5348
}
5449
if ( value !== this._config ) {
55-
if ( this._config ) {
56-
this._removeChangeListener( this._config );
57-
}
50+
this._removeChangeListener( this._config );
5851
debug( 'Current value: %s. New value: %s.', JSON.stringify( this._config ), JSON.stringify( value ) );
5952
this._config = value;
6053
this.emit( 'change' );
61-
if ( this._config ) {
62-
this._addChangeListener( this._config );
63-
}
54+
this._addChangeListener( this._config );
6455
}
6556
}
6657

lib/node_modules/@stdlib/plot/vega/visualization/lib/defaults.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818

1919
'use strict';
2020

21+
// MODULES //
22+
23+
var Autosize = require( '@stdlib/plot/vega/autosize' );
24+
var Padding = require( '@stdlib/plot/vega/padding' );
25+
var Title = require( '@stdlib/plot/vega/title' );
26+
27+
2128
// MAIN //
2229

2330
/**
@@ -35,29 +42,53 @@ function defaults() {
3542
// Schema URL:
3643
'$schema': 'https://vega.github.io/schema/vega/v6.json',
3744

45+
// Autosize configuration:
46+
'autosize': new Autosize(),
47+
3848
// Coordinate axes:
3949
'axes': [],
4050

51+
// Visualization theme:
52+
'config': {},
53+
4154
// Data set definitions and transforms:
4255
'data': [],
4356

4457
// Visualization description:
4558
'description': '',
4659

60+
// Visual encodings:
61+
'encode': {},
62+
63+
// Height (in pixels):
64+
'height': 0,
65+
4766
// Legends:
4867
'legends': [],
4968

5069
// Graphical marks:
5170
'marks': [],
5271

72+
// Padding (in pixels):
73+
'padding': new Padding(),
74+
5375
// Cartographic projections:
5476
'projections': [],
5577

5678
// Visualization scales:
5779
'scales': [],
5880

5981
// Signals for parameterizing a visualization:
60-
'signals': []
82+
'signals': [],
83+
84+
// Visualization title:
85+
'title': new Title(),
86+
87+
// Optional meta data:
88+
'usermeta': {},
89+
90+
// Width (in pixels):
91+
'width': 0
6192
};
6293
}
6394

lib/node_modules/@stdlib/plot/vega/visualization/lib/encode/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Returns encoding directives for the visual properties of the top-level group mark representing a visualization's data rectangle.
2727
*
2828
* @private
29-
* @returns {(Encode|void)} encoding directives
29+
* @returns {Encode} encoding directives
3030
*/
3131
function get() {
3232
return this._encode;

lib/node_modules/@stdlib/plot/vega/visualization/lib/encode/set.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
// MODULES //
2424

2525
var logger = require( 'debug' );
26-
var isUndefined = require( '@stdlib/assert/is-undefined' );
2726
var isObject = require( '@stdlib/assert/is-object' );
2827
var format = require( '@stdlib/string/format' );
2928

@@ -38,29 +37,21 @@ var debug = logger( 'vega:visualization:set:encode' );
3837
/**
3938
* Sets encoding directives for the visual properties of the top-level group mark representing a visualization's data rectangle.
4039
*
41-
* ## Notes
42-
*
43-
* - Providing `undefined` "unsets" the configured value.
44-
*
4540
* @private
46-
* @param {(Encode|void)} value - input value
41+
* @param {Encode} value - input value
4742
* @throws {TypeError} must be an encoding object
4843
* @returns {void}
4944
*/
5045
function set( value ) {
51-
if ( !isObject( value ) && !isUndefined( value ) ) { // FIXME: validate encoding object
46+
if ( !isObject( value ) ) { // FIXME: validate encoding object
5247
throw new TypeError( format( 'invalid assignment. `%s` must be a valid encoding. Value: `%s`.', 'encode', value ) );
5348
}
5449
if ( value !== this._encode ) {
55-
if ( this._encode ) {
56-
this._removeChangeListener( this._encode );
57-
}
50+
this._removeChangeListener( this._encode );
5851
debug( 'Current value: %s. New value: %s.', JSON.stringify( this._encode ), JSON.stringify( value ) );
5952
this._encode = value;
6053
this.emit( 'change' );
61-
if ( this._encode ) {
62-
this._addChangeListener( this._encode );
63-
}
54+
this._addChangeListener( this._encode );
6455
}
6556
}
6657

lib/node_modules/@stdlib/plot/vega/visualization/lib/height/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Returns the visualization height (in pixels).
2727
*
2828
* @private
29-
* @returns {(void|NonNegativeNumber|Signal)} height
29+
* @returns {(NonNegativeNumber|Signal)} height
3030
*/
3131
function get() {
3232
return this._height;

lib/node_modules/@stdlib/plot/vega/visualization/lib/height/set.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
var logger = require( 'debug' );
2626
var isNonNegativeNumber = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitive;
27-
var isUndefined = require( '@stdlib/assert/is-undefined' );
2827
var isObject = require( '@stdlib/assert/is-object' );
2928
var format = require( '@stdlib/string/format' );
3029

@@ -39,17 +38,13 @@ var debug = logger( 'vega:visualization:set:height' );
3938
/**
4039
* Sets the visualization height (in pixels).
4140
*
42-
* ## Notes
43-
*
44-
* - Providing `undefined` "unsets" the configured value.
45-
*
4641
* @private
47-
* @param {(NonNegativeNumber|Signal|void)} value - input value
42+
* @param {(NonNegativeNumber|Signal)} value - input value
4843
* @throws {TypeError} must be either a nonnegative number or a signal
4944
* @returns {void}
5045
*/
5146
function set( value ) {
52-
if ( !isNonNegativeNumber( value ) && !isObject( value ) && !isUndefined( value ) ) {
47+
if ( !isNonNegativeNumber( value ) && !isObject( value ) ) {
5348
throw new TypeError( format( 'invalid assignment. `%s` must be either a nonnegative number or a signal. Value: `%s`.', 'height', value ) );
5449
}
5550
if ( value !== this._height ) {

lib/node_modules/@stdlib/plot/vega/visualization/lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ setReadOnlyAccessor( Visualization.prototype, '$schema', getSchema );
300300
*
301301
* @name autosize
302302
* @memberof Visualization.prototype
303-
* @type {(string|Signal|Autosize)}
303+
* @type {(Signal|Autosize)}
304304
*
305305
* @example
306306
* var Autosize = require( '@stdlib/plot/vega/autosize' );
@@ -505,7 +505,7 @@ setReadWriteAccessor( Visualization.prototype, 'signals', getSignals, setSignals
505505
*
506506
* @name title
507507
* @memberof Visualization.prototype
508-
* @type {(Title|void)}
508+
* @type {Title}
509509
*
510510
* @example
511511
* var Title = require( '@stdlib/plot/vega/title' );

0 commit comments

Comments
 (0)