Skip to content

Commit a256141

Browse files
gururaj1512kgryte
andauthored
feat: add support for various axis title properties
PR-URL: #9457 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 0c4220e commit a256141

10 files changed

Lines changed: 487 additions & 0 deletions

File tree

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ var getTitleOpacity = require( './title-opacity/get.js' );
197197
var setTitleOpacity = require( './title-opacity/set.js' );
198198
var getTitlePadding = require( './title-padding/get.js' );
199199
var setTitlePadding = require( './title-padding/set.js' );
200+
var getTitleX = require( './title-x/get.js' );
201+
var setTitleX = require( './title-x/set.js' );
202+
var getTitleY = require( './title-y/get.js' );
203+
var setTitleY = require( './title-y/set.js' );
204+
205+
var getTranslate = require( './translate/get.js' );
206+
var setTranslate = require( './translate/set.js' );
200207

201208
var getZIndex = require( './zindex/get.js' );
202209
var setZIndex = require( './zindex/set.js' );
@@ -1800,6 +1807,63 @@ setReadWriteAccessor( Axis.prototype, 'titleOpacity', getTitleOpacity, setTitleO
18001807
*/
18011808
setReadWriteAccessor( Axis.prototype, 'titlePadding', getTitlePadding, setTitlePadding );
18021809

1810+
/**
1811+
* Custom `x` position of the axis title relative to the axis group.
1812+
*
1813+
* @name titleX
1814+
* @memberof Axis.prototype
1815+
* @type {(void|number)}
1816+
*
1817+
* @example
1818+
* var axis = new Axis({
1819+
* 'scale': 'xScale',
1820+
* 'orient': 'bottom',
1821+
* 'titleX': 5
1822+
* });
1823+
*
1824+
* var v = axis.titleX;
1825+
* // returns 5
1826+
*/
1827+
setReadWriteAccessor( Axis.prototype, 'titleX', getTitleX, setTitleX );
1828+
1829+
/**
1830+
* Custom `y` position of the axis title relative to the axis group.
1831+
*
1832+
* @name titleY
1833+
* @memberof Axis.prototype
1834+
* @type {(void|number)}
1835+
*
1836+
* @example
1837+
* var axis = new Axis({
1838+
* 'scale': 'xScale',
1839+
* 'orient': 'bottom',
1840+
* 'titleY': 5
1841+
* });
1842+
*
1843+
* var v = axis.titleY;
1844+
* // returns 5
1845+
*/
1846+
setReadWriteAccessor( Axis.prototype, 'titleY', getTitleY, setTitleY );
1847+
1848+
/**
1849+
* Coordinate space translation offset for axis layout.
1850+
*
1851+
* @name translate
1852+
* @memberof Axis.prototype
1853+
* @type {number}
1854+
*
1855+
* @example
1856+
* var axis = new Axis({
1857+
* 'scale': 'xScale',
1858+
* 'orient': 'bottom',
1859+
* 'translate': 1
1860+
* });
1861+
*
1862+
* var v = axis.translate;
1863+
* // returns 1
1864+
*/
1865+
setReadWriteAccessor( Axis.prototype, 'translate', getTranslate, setTranslate );
1866+
18031867
/**
18041868
* Integer z-index indicating the layering of the title group relative to other axis, mark, and legend groups.
18051869
*
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 custom `x` position of the axis title relative to the axis group.
32+
*
33+
* @private
34+
* @returns {(void|number)} position
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( 'titleX' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
var changeEvent = require( './../change_event.js' );
30+
var prop = require( './properties.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var debug = logger( 'vega:axis:set:'+prop.name );
36+
37+
38+
// MAIN //
39+
40+
/**
41+
* Sets the custom `x` position of the axis title relative to the axis group.
42+
*
43+
* ## Notes
44+
*
45+
* - Providing `undefined` "unsets" the configured value.
46+
* - Setting the position overrides the standard layout.
47+
*
48+
* @private
49+
* @param {(number|void)} value - input value
50+
* @throws {TypeError} must be a number
51+
* @returns {void}
52+
*/
53+
function set( value ) {
54+
if ( !isNumber( value ) && !isUndefined( value ) ) {
55+
throw new TypeError( format( 'invalid assignment. `%s` must be a number. Value: `%s`.', prop.name, value ) );
56+
}
57+
if ( value !== this[ prop.private ] ) {
58+
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
59+
this[ prop.private ] = value;
60+
this.emit( 'change', changeEvent( prop.name ) );
61+
}
62+
}
63+
64+
65+
// EXPORTS //
66+
67+
module.exports = set;
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 custom `y` position of the axis title relative to the axis group.
32+
*
33+
* @private
34+
* @returns {(void|number)} position
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( 'titleY' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
var changeEvent = require( './../change_event.js' );
30+
var prop = require( './properties.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var debug = logger( 'vega:axis:set:'+prop.name );
36+
37+
38+
// MAIN //
39+
40+
/**
41+
* Sets the custom `y` position of the axis title relative to the axis group.
42+
*
43+
* ## Notes
44+
*
45+
* - Providing `undefined` "unsets" the configured value.
46+
* - Setting the position overrides the standard layout.
47+
*
48+
* @private
49+
* @param {(number|void)} value - input value
50+
* @throws {TypeError} must be a number
51+
* @returns {void}
52+
*/
53+
function set( value ) {
54+
if ( !isNumber( value ) && !isUndefined( value ) ) {
55+
throw new TypeError( format( 'invalid assignment. `%s` must be a number. Value: `%s`.', prop.name, value ) );
56+
}
57+
if ( value !== this[ prop.private ] ) {
58+
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
59+
this[ prop.private ] = value;
60+
this.emit( 'change', changeEvent( prop.name ) );
61+
}
62+
}
63+
64+
65+
// EXPORTS //
66+
67+
module.exports = set;

0 commit comments

Comments
 (0)