Skip to content

Commit 26ac82c

Browse files
committed
feat: add support for formatType property
--- 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 fe08c2f commit 26ac82c

File tree

4 files changed

+177
-7
lines changed

4 files changed

+177
-7
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 prop = require( './properties.js' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns the type of format to use for axis scales which do not have a strict domain data type.
32+
*
33+
* @private
34+
* @returns {(string|void)} value
35+
*/
36+
function get() {
37+
return this[ prop.private ];
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
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( 'formatType' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 contains = require( '@stdlib/array/base/assert/contains' ).factory;
27+
var isUndefined = require( '@stdlib/assert/is-undefined' );
28+
var join = require( '@stdlib/array/base/join' );
29+
var format = require( '@stdlib/string/format' );
30+
var changeEvent = require( './../change_event.js' );
31+
var prop = require( './properties.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var debug = logger( 'vega:axis:set:'+prop.name );
37+
var FORMATS = [
38+
'number',
39+
'time',
40+
'utc'
41+
];
42+
var isFormat = contains( FORMATS );
43+
44+
45+
// MAIN //
46+
47+
/**
48+
* Sets the type of format to use for axis scales which do not have a strict domain data type.
49+
*
50+
* ## Notes
51+
*
52+
* - Providing `undefined` "unsets" the configured value.
53+
*
54+
* @private
55+
* @param {(string|void)} value - input value
56+
* @throws {TypeError} must be a supported format type
57+
* @returns {void}
58+
*/
59+
function set( value ) {
60+
if ( !isFormat( value ) && !isUndefined( value ) ) {
61+
throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( FORMATS, '", "' ), value ) );
62+
}
63+
if ( value !== this[ prop.private ] ) {
64+
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
65+
this[ prop.private ] = value;
66+
this.emit( 'change', changeEvent( prop.name ) );
67+
}
68+
}
69+
70+
71+
// EXPORTS //
72+
73+
module.exports = set;

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ var setDomainWidth = require( './domain-width/set.js' );
6464

6565
var getFormat = require( './format/get.js' );
6666
var setFormat = require( './format/set.js' );
67+
var getFormatType = require( './format-type/get.js' );
68+
var setFormatType = require( './format-type/set.js' );
6769

6870
var getGrid = require( './grid/get.js' );
6971
var setGrid = require( './grid/set.js' );
@@ -522,6 +524,25 @@ setReadWriteAccessor( Axis.prototype, 'domainDashOffset', getDomainDashOffset, s
522524
*/
523525
setReadWriteAccessor( Axis.prototype, 'domainOpacity', getDomainOpacity, setDomainOpacity );
524526

527+
/**
528+
* Stroke width of an axis domain line.
529+
*
530+
* @name domainWidth
531+
* @memberof Axis.prototype
532+
* @type {(void|NonNegativeNumber)}
533+
*
534+
* @example
535+
* var axis = new Axis({
536+
* 'scale': 'xScale',
537+
* 'orient': 'bottom',
538+
* 'domainWidth': 1
539+
* });
540+
*
541+
* var v = axis.domainWidth;
542+
* // returns 1
543+
*/
544+
setReadWriteAccessor( Axis.prototype, 'domainWidth', getDomainWidth, setDomainWidth );
545+
525546
/**
526547
* Format specifier for axis tick labels.
527548
*
@@ -542,23 +563,23 @@ setReadWriteAccessor( Axis.prototype, 'domainOpacity', getDomainOpacity, setDoma
542563
setReadWriteAccessor( Axis.prototype, 'format', getFormat, setFormat );
543564

544565
/**
545-
* Stroke width of an axis domain line.
566+
* Type of format to use for axis scales which do not have a strict domain data type.
546567
*
547-
* @name domainWidth
568+
* @name formatType
548569
* @memberof Axis.prototype
549-
* @type {(void|NonNegativeNumber)}
570+
* @type {(void|string)}
550571
*
551572
* @example
552573
* var axis = new Axis({
553574
* 'scale': 'xScale',
554575
* 'orient': 'bottom',
555-
* 'domainWidth': 1
576+
* 'formatType': 'number'
556577
* });
557578
*
558-
* var v = axis.domainWidth;
559-
* // returns 1
579+
* var v = axis.formatType;
580+
* // returns 'number'
560581
*/
561-
setReadWriteAccessor( Axis.prototype, 'domainWidth', getDomainWidth, setDomainWidth );
582+
setReadWriteAccessor( Axis.prototype, 'formatType', getFormatType, setFormatType );
562583

563584
/**
564585
* Boolean indicating whether grid lines should be included as part of an axis.

0 commit comments

Comments
 (0)