Skip to content

Commit 55fb37c

Browse files
committed
refactor: allow title text field to be optional
--- 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: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent d91fe61 commit 55fb37c

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function transformErrorMessage( msg ) {
130130
* Title constructor.
131131
*
132132
* @constructor
133-
* @param {Options} options - constructor options
133+
* @param {Options} [options] - constructor options
134134
* @param {boolean} [options.aria=true] - boolean indicating whether ARIA attributes should be included in SVG output
135135
*
136136
* // FIXME: add parameters
@@ -146,18 +146,22 @@ function transformErrorMessage( msg ) {
146146
* // returns <Title>
147147
*/
148148
function Title( options ) {
149+
var nargs;
149150
var opts;
150151
var keys;
151152
var v;
152153
var k;
153154
var i;
155+
156+
nargs = arguments.length;
154157
if ( !( this instanceof Title ) ) {
155-
return new Title( options );
158+
if ( nargs ) {
159+
return new Title( options );
160+
}
161+
return new Title();
156162
}
157163
EventEmitter.call( this );
158-
if ( !isPlainObject( options ) ) {
159-
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
160-
}
164+
161165
// Resolve the default configuration:
162166
opts = defaults();
163167

@@ -167,24 +171,25 @@ function Title( options ) {
167171
k = keys[ i ];
168172
this[ '_'+k ] = opts[ k ];
169173
}
170-
// Check for required properties...
171-
if ( !hasProp( options, 'text' ) ) {
172-
throw new TypeError( 'invalid argument. Options argument must specify title text.' );
173-
}
174-
// Validate provided options by attempting to assign option values to corresponding fields...
175-
for ( i = 0; i < properties.length; i++ ) {
176-
k = properties[ i ];
177-
if ( !hasProp( options, k ) ) {
178-
continue;
174+
if ( nargs ) {
175+
if ( !isPlainObject( options ) ) {
176+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
179177
}
180-
v = options[ k ];
181-
try {
182-
this[ k ] = v;
183-
} catch ( err ) {
184-
debug( 'Encountered an error. Error: %s', err.message );
185-
186-
// FIXME: retain thrown error type
187-
throw new Error( transformErrorMessage( err.message ) );
178+
// Validate provided options by attempting to assign option values to corresponding fields...
179+
for ( i = 0; i < properties.length; i++ ) {
180+
k = properties[ i ];
181+
if ( !hasProp( options, k ) ) {
182+
continue;
183+
}
184+
v = options[ k ];
185+
try {
186+
this[ k ] = v;
187+
} catch ( err ) {
188+
debug( 'Encountered an error. Error: %s', err.message );
189+
190+
// FIXME: retain thrown error type
191+
throw new Error( transformErrorMessage( err.message ) );
192+
}
188193
}
189194
}
190195
return this;

lib/node_modules/@stdlib/plot/vega/title/lib/text/set.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
var logger = require( 'debug' );
2626
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2727
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
28+
var isEmptyArrayLikeObject = require( '@stdlib/assert/is-empty-array-like-object' );
2829
var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' );
2930
var copy = require( '@stdlib/array/base/copy' );
3031
var join = require( '@stdlib/array/base/join' );
@@ -48,7 +49,7 @@ var debug = logger( 'vega:title:set:text' );
4849
*/
4950
function set( value ) {
5051
var isStr = isString( value );
51-
if ( !isStr && !isStringArray( value ) ) {
52+
if ( !isStr && !isStringArray( value ) && !isEmptyArrayLikeObject( value ) ) { // eslint-disable-line max-len
5253
throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', 'text', value ) );
5354
}
5455
if ( isStr ) {

lib/node_modules/@stdlib/plot/vega/visualization/examples/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ var Visualization = require( './../lib' );
2727

2828
var autosize = new Autosize();
2929
var padding = new Padding();
30-
var title = new Title({
31-
'text': 'Hello World!'
32-
});
30+
var title = new Title();
3331
var xScale = new LinearScale({
3432
'name': 'xScale',
3533
'domain': [ 0, 99 ],

0 commit comments

Comments
 (0)