Skip to content

Commit 1771c47

Browse files
committed
feat: add background 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: 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 58533d5 commit 1771c47

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed
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 background color.
27+
*
28+
* @private
29+
* @returns {string} background color
30+
*/
31+
function get() {
32+
return this._background;
33+
}
34+
35+
36+
// EXPORTS //
37+
38+
module.exports = get;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 isString = require( '@stdlib/assert/is-string' ).isPrimitive;
27+
var format = require( '@stdlib/string/format' );
28+
29+
30+
// VARIABLES //
31+
32+
var debug = logger( 'vega:visualization:set:background' );
33+
34+
35+
// MAIN //
36+
37+
/**
38+
* Sets the visualization background color.
39+
*
40+
* @private
41+
* @param {string} value - input value
42+
* @throws {TypeError} must be a string
43+
* @returns {void}
44+
*/
45+
function set( value ) {
46+
if ( !isString( value ) ) {
47+
throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'background', value ) );
48+
}
49+
if ( value !== this._background ) {
50+
debug( 'Current value: %s. New value: %s.', this._background, value );
51+
this._background = value;
52+
this.emit( 'change' );
53+
}
54+
}
55+
56+
57+
// EXPORTS //
58+
59+
module.exports = set;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function defaults() {
4848
// Coordinate axes:
4949
'axes': [],
5050

51+
'background': '',
52+
5153
// Visualization theme:
5254
'config': {},
5355

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var setAutosize = require( './autosize/set.js' );
4343
var getAxes = require( './axes/get.js' );
4444
var setAxes = require( './axes/set.js' );
4545

46+
var getBackground = require( './background/get.js' );
47+
var setBackground = require( './background/set.js' );
48+
4649
var getConfig = require( './config/get.js' );
4750
var setConfig = require( './config/set.js' );
4851

@@ -338,6 +341,24 @@ setReadWriteAccessor( Visualization.prototype, 'autosize', getAutosize, setAutos
338341
*/
339342
setReadWriteAccessor( Visualization.prototype, 'axes', getAxes, setAxes );
340343

344+
/**
345+
* Visualization background color.
346+
*
347+
* @name background
348+
* @memberof Visualization.prototype
349+
* @type {string}
350+
* @default ''
351+
*
352+
* @example
353+
* var viz = new Visualization({
354+
* 'background': 'white'
355+
* });
356+
*
357+
* var v = viz.background;
358+
* // returns 'white'
359+
*/
360+
setReadWriteAccessor( Visualization.prototype, 'background', getBackground, setBackground );
361+
341362
/**
342363
* Visualization theme.
343364
*

0 commit comments

Comments
 (0)