Skip to content

Commit 9bb928a

Browse files
committed
feat: add encode, fontSize, and fontWeight 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 906637c commit 9bb928a

File tree

7 files changed

+382
-0
lines changed

7 files changed

+382
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 copy = require( '@stdlib/utils/copy' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns the mark encodings for custom title styling.
32+
*
33+
* @private
34+
* @returns {(Object|void)} encodings
35+
*/
36+
function get() {
37+
return copy( this._encode ); // FIXME: `copy` is relatively slow. Potential speedup?
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = get;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 isObject = require( '@stdlib/assert/is-object' );
27+
var isUndefined = require( '@stdlib/assert/is-undefined' );
28+
var format = require( '@stdlib/string/format' );
29+
30+
31+
// VARIABLES //
32+
33+
var debug = logger( 'vega:title:set:encode' );
34+
35+
36+
// MAIN //
37+
38+
/**
39+
* Sets mark encodings for custom title styling.
40+
*
41+
* ## Notes
42+
*
43+
* - Providing `undefined` "unsets" the configured value.
44+
*
45+
* @private
46+
* @param {(Object|void)} value - input value
47+
* @throws {TypeError} must be an object
48+
* @returns {void}
49+
*/
50+
function set( value ) {
51+
// FIXME: perform more robust validation of encoding objects (e.g., only support for `group`, `title`, and `subtitle` fields, etc)
52+
if ( !isObject( value ) && !isUndefined( value ) ) {
53+
throw new TypeError( format( 'invalid assignment. `%s` must be an object. Value: `%s`.', 'encode', value ) );
54+
}
55+
if ( value !== this._encode ) {
56+
debug( 'Current value: %s. New value: %s.', JSON.stringify( this._encode ), JSON.stringify( value ) );
57+
this._encode = value;
58+
this.emit( 'change' );
59+
}
60+
}
61+
62+
63+
// EXPORTS //
64+
65+
module.exports = set;
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 font size (in pixels) of title text.
27+
*
28+
* @private
29+
* @returns {(number|void)} font size
30+
*/
31+
function get() {
32+
return this._fontSize;
33+
}
34+
35+
36+
// EXPORTS //
37+
38+
module.exports = get;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
27+
var isUndefined = require( '@stdlib/assert/is-undefined' );
28+
var format = require( '@stdlib/string/format' );
29+
30+
31+
// VARIABLES //
32+
33+
var debug = logger( 'vega:title:set:fontSize' );
34+
35+
36+
// MAIN //
37+
38+
/**
39+
* Sets the font size (in pixels) of title text.
40+
*
41+
* ## Notes
42+
*
43+
* - Providing `undefined` "unsets" the configured value.
44+
*
45+
* @private
46+
* @param {(number|void)} value - input value
47+
* @throws {TypeError} must be a number
48+
* @returns {void}
49+
*/
50+
function set( value ) {
51+
if ( !isNumber( value ) && !isUndefined( value ) ) {
52+
throw new TypeError( format( 'invalid assignment. `%s` must be a number. Value: `%s`.', 'fontSize', value ) );
53+
}
54+
if ( value !== this._fontSize ) {
55+
debug( 'Current value: %s. New value: %s.', this._fontSize, value );
56+
this._fontSize = value;
57+
this.emit( 'change' );
58+
}
59+
}
60+
61+
62+
// EXPORTS //
63+
64+
module.exports = set;
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 font weight of title text.
27+
*
28+
* @private
29+
* @returns {(number|string|void)} font weight
30+
*/
31+
function get() {
32+
return this._fontWeight;
33+
}
34+
35+
36+
// EXPORTS //
37+
38+
module.exports = get;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
27+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
28+
var isUndefined = require( '@stdlib/assert/is-undefined' );
29+
var format = require( '@stdlib/string/format' );
30+
31+
32+
// VARIABLES //
33+
34+
var debug = logger( 'vega:title:set:fontWeight' );
35+
36+
37+
// MAIN //
38+
39+
/**
40+
* Sets the font weight of title text.
41+
*
42+
* ## Notes
43+
*
44+
* - Providing `undefined` "unsets" the configured value.
45+
*
46+
* @private
47+
* @param {(number|string|void)} value - input value
48+
* @throws {TypeError} must be a number or string
49+
* @returns {void}
50+
*/
51+
function set( value ) {
52+
if ( !isNumber( value ) && !isString( value ) && !isUndefined( value ) ) {
53+
throw new TypeError( format( 'invalid assignment. `%s` must be a number or string. Value: `%s`.', 'fontWeight', value ) );
54+
}
55+
if ( value !== this._fontWeight ) {
56+
debug( 'Current value: %s. New value: %s.', this._fontWeight, value );
57+
this._fontWeight = value;
58+
this.emit( 'change' );
59+
}
60+
}
61+
62+
63+
// EXPORTS //
64+
65+
module.exports = set;

0 commit comments

Comments
 (0)