Skip to content

Commit fe08c2f

Browse files
committed
feat: add format 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 0b8305f commit fe08c2f

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 isObject = require( '@stdlib/assert/is-object' );
26+
var objectAssignIn = require( '@stdlib/object/assign-in' );
27+
var prop = require( './properties.js' );
28+
29+
30+
// MAIN //
31+
32+
/**
33+
* Returns a format specifier for axis tick labels.
34+
*
35+
* @private
36+
* @returns {(string|Object|void)} format specifier
37+
*/
38+
function get() {
39+
var v = this[ prop.private ];
40+
return ( isObject( v ) ) ? objectAssignIn( {}, v ) : v;
41+
}
42+
43+
44+
// EXPORTS //
45+
46+
module.exports = get;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var property2object = require( '@stdlib/plot/vega/base/property2object' );
24+
25+
26+
// MAIN //
27+
28+
var obj = property2object( 'format' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 isString = require( '@stdlib/assert/is-string' ).isPrimitive;
28+
var isUndefined = require( '@stdlib/assert/is-undefined' );
29+
var objectAssignIn = require( '@stdlib/object/assign-in' );
30+
var format = require( '@stdlib/string/format' );
31+
var changeEvent = require( './../change_event.js' );
32+
var prop = require( './properties.js' );
33+
34+
35+
// VARIABLES //
36+
37+
var debug = logger( 'vega:axis:set:'+prop.name );
38+
39+
40+
// MAIN //
41+
42+
/**
43+
* Sets a format specifier for axis tick labels.
44+
*
45+
* ## Notes
46+
*
47+
* - Providing `undefined` "unsets" the configured value.
48+
*
49+
* @private
50+
* @param {(string|Object|void)} value - input value
51+
* @throws {TypeError} must be a string or valid format object
52+
* @returns {void}
53+
*/
54+
function set( value ) {
55+
var isObj = isObject( value );
56+
57+
// FIXME: validate that an object is a valid TimeMultiFormat object
58+
59+
if ( !isObj && !isString( value ) && !isUndefined( value ) ) {
60+
throw new TypeError( format( 'invalid assignment. `%s` must be a string or a valid format object. Value: `%s`.', prop.name, value ) );
61+
}
62+
63+
// TODO: consider a deep equality check for format objects in order to avoid false positive change events
64+
65+
if ( value !== this[ prop.private ] ) {
66+
debug( 'Current value: %s. New value: %s.', JSON.stringify( this[ prop.private ] ), JSON.stringify( value ) );
67+
this[ prop.private ] = ( isObj ) ? objectAssignIn( {}, value ) : value;
68+
this.emit( 'change', changeEvent( prop.name ) );
69+
}
70+
}
71+
72+
73+
// EXPORTS //
74+
75+
module.exports = set;

lib/node_modules/@stdlib/plot/vega/axis/ctor/lib/main.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ var setDomainOpacity = require( './domain-opacity/set.js' );
6262
var getDomainWidth = require( './domain-width/get.js' );
6363
var setDomainWidth = require( './domain-width/set.js' );
6464

65+
var getFormat = require( './format/get.js' );
66+
var setFormat = require( './format/set.js' );
67+
6568
var getGrid = require( './grid/get.js' );
6669
var setGrid = require( './grid/set.js' );
6770
var getGridCap = require( './grid-cap/get.js' );
@@ -519,6 +522,25 @@ setReadWriteAccessor( Axis.prototype, 'domainDashOffset', getDomainDashOffset, s
519522
*/
520523
setReadWriteAccessor( Axis.prototype, 'domainOpacity', getDomainOpacity, setDomainOpacity );
521524

525+
/**
526+
* Format specifier for axis tick labels.
527+
*
528+
* @name format
529+
* @memberof Axis.prototype
530+
* @type {(void|string|Object)}
531+
*
532+
* @example
533+
* var axis = new Axis({
534+
* 'scale': 'xScale',
535+
* 'orient': 'bottom',
536+
* 'format': '%d'
537+
* });
538+
*
539+
* var v = axis.format;
540+
* // returns '%d'
541+
*/
542+
setReadWriteAccessor( Axis.prototype, 'format', getFormat, setFormat );
543+
522544
/**
523545
* Stroke width of an axis domain line.
524546
*

0 commit comments

Comments
 (0)