Skip to content

Commit 399e924

Browse files
committed
feat: add autosize and padding support
--- 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 2827f8a commit 399e924

File tree

8 files changed

+280
-4
lines changed

8 files changed

+280
-4
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818

1919
'use strict';
2020

21+
var Autosize = require( '@stdlib/plot/vega/autosize' );
22+
var Padding = require( '@stdlib/plot/vega/padding' );
2123
var Title = require( '@stdlib/plot/vega/title' );
2224
var LinearScale = require( '@stdlib/plot/vega/linear-scale' );
2325
var Axis = require( '@stdlib/plot/vega/axis' );
2426
var Visualization = require( './../lib' );
2527

28+
var autosize = new Autosize();
29+
var padding = new Padding();
2630
var title = new Title({
2731
'text': 'Hello World!'
2832
});
@@ -51,6 +55,8 @@ var viz = new Visualization({
5155
'description': 'Beep boop',
5256
'width': 640,
5357
'height': 480,
58+
'padding': padding,
59+
'autosize': autosize,
5460
'title': title,
5561
'scales': [ xScale, yScale ],
5662
'axes': [ xAxis, yAxis ]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MAIN //
24+
25+
/**
26+
* Returns the autosize configuration.
27+
*
28+
* @private
29+
* @returns {(void|string|Autosize|Signal)} autosize configuration
30+
*/
31+
function get() {
32+
return this._autosize;
33+
}
34+
35+
36+
// EXPORTS //
37+
38+
module.exports = get;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var logger = require( 'debug' );
26+
var isAutosize = require( '@stdlib/plot/vega/base/assert/is-autosize' );
27+
var isString = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitive;
28+
var isUndefined = require( '@stdlib/assert/is-undefined' );
29+
var isObject = require( '@stdlib/assert/is-object' );
30+
var format = require( '@stdlib/string/format' );
31+
32+
33+
// VARIABLES //
34+
35+
var debug = logger( 'vega:visualization:set:autosize' );
36+
37+
38+
// MAIN //
39+
40+
/**
41+
* Sets the autosize configuration.
42+
*
43+
* ## Notes
44+
*
45+
* - Providing `undefined` "unsets" the configured value.
46+
*
47+
* @private
48+
* @param {(string|Autosize|Signal|void)} value - input value
49+
* @throws {TypeError} must be either a string, an autosize instance, or a signal
50+
* @returns {void}
51+
*/
52+
function set( value ) {
53+
var flg = isAutosize( value );
54+
if (
55+
!flg &&
56+
!isString( value ) &&
57+
!isObject( value ) &&
58+
!isUndefined( value )
59+
) {
60+
throw new TypeError( format( 'invalid assignment. `%s` must be either a string, an autosize instance, or a signal. Value: `%s`.', 'autosize', value ) );
61+
}
62+
if ( value !== this._autosize ) {
63+
if ( isAutosize( this._autosize ) ) {
64+
this._removeChangeListener( this._autosize );
65+
}
66+
debug( 'Current value: %s. New value: %s.', JSON.stringify( this._autosize ), JSON.stringify( value ) );
67+
this._autosize = value;
68+
this.emit( 'change' );
69+
if ( flg ) {
70+
this._addChangeListener( this._autosize );
71+
}
72+
}
73+
}
74+
75+
76+
// EXPORTS //
77+
78+
module.exports = set;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ var debug = logger( 'vega:visualization:set:height' );
4545
*
4646
* @private
4747
* @param {(NonNegativeNumber|Signal|void)} value - input value
48-
* @throws {TypeError} must be either a nonnegative number or a signal instance
48+
* @throws {TypeError} must be either a nonnegative number or a signal
4949
* @returns {void}
5050
*/
5151
function set( value ) {
5252
if ( !isNonNegativeNumber( value ) && !isObject( value ) && !isUndefined( value ) ) {
53-
throw new TypeError( format( 'invalid assignment. `%s` must be either a nonnegative number or a signal instance. Value: `%s`.', 'height', value ) );
53+
throw new TypeError( format( 'invalid assignment. `%s` must be either a nonnegative number or a signal. Value: `%s`.', 'height', value ) );
5454
}
5555
if ( value !== this._height ) {
5656
debug( 'Current value: %s. New value: %s.', this._height, value );

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ var defaults = require( './defaults.js' );
3737
var toJSON = require( './to_json.js' );
3838

3939
// Note: keep the following in alphabetical order according to the `require` path...
40+
var getAutosize = require( './autosize/get.js' );
41+
var setAutosize = require( './autosize/set.js' );
4042
var getAxes = require( './axes/get.js' );
4143
var setAxes = require( './axes/set.js' );
4244

@@ -46,6 +48,9 @@ var setDescription = require( './description/set.js' );
4648
var getHeight = require( './height/get.js' );
4749
var setHeight = require( './height/set.js' );
4850

51+
var getPadding = require( './padding/get.js' );
52+
var setPadding = require( './padding/set.js' );
53+
4954
var getScales = require( './scales/get.js' );
5055
var setScales = require( './scales/set.js' );
5156

@@ -252,6 +257,26 @@ setReadOnly( Visualization.prototype, '_removeChangeListeners', function removeC
252257
return this;
253258
});
254259

260+
/**
261+
* Visualization autosize configuration.
262+
*
263+
* @name autosize
264+
* @memberof Visualization.prototype
265+
* @type {(string|Signal|Autosize)}
266+
*
267+
* @example
268+
* var Autosize = require( '@stdlib/plot/vega/autosize' );
269+
*
270+
* var autosize = new Autosize();
271+
* var viz = new Visualization({
272+
* 'autosize': autosize
273+
* });
274+
*
275+
* var v = viz.autosize;
276+
* // returns <Autosize>
277+
*/
278+
setReadWriteAccessor( Visualization.prototype, 'autosize', getAutosize, setAutosize );
279+
255280
/**
256281
* Visualization coordinate axes.
257282
*
@@ -310,6 +335,26 @@ setReadWriteAccessor( Visualization.prototype, 'description', getDescription, se
310335
*/
311336
setReadWriteAccessor( Visualization.prototype, 'height', getHeight, setHeight );
312337

338+
/**
339+
* Visualization padding.
340+
*
341+
* @name padding
342+
* @memberof Visualization.prototype
343+
* @type {(Signal|Padding)}
344+
*
345+
* @example
346+
* var Padding = require( '@stdlib/plot/vega/padding' );
347+
*
348+
* var padding = new Padding();
349+
* var viz = new Visualization({
350+
* 'padding': padding
351+
* });
352+
*
353+
* var v = viz.padding;
354+
* // returns <Padding>
355+
*/
356+
setReadWriteAccessor( Visualization.prototype, 'padding', getPadding, setPadding );
357+
313358
/**
314359
* Visualization scales.
315360
*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MAIN //
24+
25+
/**
26+
* Returns the visualization padding.
27+
*
28+
* @private
29+
* @returns {(Padding|Signal|void)} padding
30+
*/
31+
function get() {
32+
return this._padding;
33+
}
34+
35+
36+
// EXPORTS //
37+
38+
module.exports = get;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var logger = require( 'debug' );
26+
var isUndefined = require( '@stdlib/assert/is-undefined' );
27+
var isPadding = require( '@stdlib/plot/vega/base/assert/is-padding' );
28+
var format = require( '@stdlib/string/format' );
29+
30+
31+
// VARIABLES //
32+
33+
var debug = logger( 'vega:visualization:set:padding' );
34+
35+
36+
// MAIN //
37+
38+
/**
39+
* Sets the visualization padding.
40+
*
41+
* ## Notes
42+
*
43+
* - Providing `undefined` "unsets" the configured value.
44+
*
45+
* @private
46+
* @param {(Padding|Signal|void)} value - input value
47+
* @throws {TypeError} must be a padding instance or a signal
48+
* @returns {void}
49+
*/
50+
function set( value ) {
51+
var flg = isPadding( value );
52+
if ( !flg && !isUndefined( value ) ) { // TODO: add signal support
53+
throw new TypeError( format( 'invalid assignment. `%s` must be a padding instance or a signal. Value: `%s`.', 'padding', value ) );
54+
}
55+
if ( value !== this._padding ) {
56+
if ( isPadding( this._padding ) ) {
57+
this._removeChangeListener( this._padding );
58+
}
59+
debug( 'Current value: %s. New value: %s.', JSON.stringify( this._padding ), JSON.stringify( value ) );
60+
this._padding = value;
61+
this.emit( 'change' );
62+
if ( flg ) {
63+
this._addChangeListener( this._padding );
64+
}
65+
}
66+
}
67+
68+
69+
// EXPORTS //
70+
71+
module.exports = set;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ var debug = logger( 'vega:visualization:set:width' );
4545
*
4646
* @private
4747
* @param {(NonNegativeNumber|Signal|void)} value - input value
48-
* @throws {TypeError} must be either a nonnegative number or a signal instance
48+
* @throws {TypeError} must be either a nonnegative number or a signal
4949
* @returns {void}
5050
*/
5151
function set( value ) {
5252
if ( !isNonNegativeNumber( value ) && !isObject( value ) && !isUndefined( value ) ) {
53-
throw new TypeError( format( 'invalid assignment. `%s` must be either a nonnegative number or a signal instance. Value: `%s`.', 'width', value ) );
53+
throw new TypeError( format( 'invalid assignment. `%s` must be either a nonnegative number or a signal. Value: `%s`.', 'width', value ) );
5454
}
5555
if ( value !== this._width ) {
5656
debug( 'Current value: %s. New value: %s.', this._width, value );

0 commit comments

Comments
 (0)