Skip to content

Commit 9b9dcc5

Browse files
gururaj1512kgryte
andauthored
feat: add route and menu support for axis tick properties
PR-URL: #12133 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
1 parent 8f0b8a2 commit 9b9dcc5

47 files changed

Lines changed: 2077 additions & 9 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/config/axis.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,25 @@ var PROPS = [
4141
'gridColor',
4242
'gridDashOffset',
4343
'gridOpacity',
44-
'gridWidth',
44+
'tickBand',
45+
'tickCap',
46+
'tickColor',
47+
'tickDashOffset',
48+
'tickMinStep',
49+
'tickOffset',
50+
'tickOpacity',
51+
'ticks',
52+
'tickSize',
53+
'tickWidth',
4554
'titleColor',
4655
'titleFont',
4756
'titleOpacity'
4857
];
4958
var ARRAY_PROPS = [
5059
'domainDash',
51-
'gridDash'
60+
'gridDash',
61+
'tickDash',
62+
'tickCount'
5263
];
5364
var SCHEMA_PROPS = [
5465
'gridScale'

lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/menus/axis.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,40 @@ function addMenu( parent, conf, schema, name ) {
106106
controller = folder.add( conf, k )
107107
.min( d.min );
108108
controller.name( format( '%s (%s)', k, d.units ) );
109+
} else if ( k === 'tickBand' ) {
110+
controller = folder.add( conf, k, EMPTY_STRING.concat( d.values ) );
111+
} else if ( k === 'tickCap' ) {
112+
controller = folder.add( conf, k, EMPTY_STRING.concat( d.values ) );
113+
} else if ( k === 'tickColor' ) {
114+
controller = folder.addColor( conf, k );
115+
} else if ( k === 'tickCount' ) {
116+
controller = folder.add( conf, k );
117+
} else if ( k === 'tickDash' ) {
118+
controller = folder.add( conf, k );
119+
} else if ( k === 'tickDashOffset' ) {
120+
controller = folder.add( conf, k );
121+
controller.name( format( '%s (%s)', k, d.units ) );
122+
} else if ( k === 'tickMinStep' ) {
123+
controller = folder.add( conf, k )
124+
.min( d.min );
125+
} else if ( k === 'tickOffset' ) {
126+
controller = folder.add( conf, k )
127+
.min( d.min );
128+
controller.name( format( '%s (%s)', k, d.units ) );
129+
} else if ( k === 'tickOpacity' ) {
130+
controller = folder.add( conf, k )
131+
.min( d.min )
132+
.max( d.max );
133+
} else if ( k === 'ticks' ) {
134+
controller = folder.add( conf, k );
135+
} else if ( k === 'tickSize' ) {
136+
controller = folder.add( conf, k )
137+
.min( d.min );
138+
controller.name( format( '%s (%s)', k, d.units ) );
139+
} else if ( k === 'tickWidth' ) {
140+
controller = folder.add( conf, k )
141+
.min( d.min );
142+
controller.name( format( '%s (%s)', k, d.units ) );
109143
} else if ( k === 'title' ) {
110144
controller = folder.add( conf, k );
111145
} else if ( k === 'titleColor' ) {

lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/on_change.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
var parseJSON = require( '@stdlib/utils/parse-json' );
2626
var isJSON = require( '@stdlib/assert/is-json' );
27+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
28+
var trim = require( '@stdlib/string/base/trim' );
29+
var Number = require( '@stdlib/number/ctor' );
30+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2731
var join = require( '@stdlib/array/base/join' );
2832
var log = require( './../log.js' );
2933
var config = require( './../config.js' );
@@ -74,6 +78,7 @@ function onChange( event ) {
7478
var obj;
7579
var ns;
7680
var i;
81+
var n;
7782

7883
self = this;
7984
conf = this._config;
@@ -110,6 +115,22 @@ function onChange( event ) {
110115
if ( !( tmp instanceof Error ) ) {
111116
val = tmp;
112117
}
118+
} else if ( isString( val ) ) {
119+
tmp = trim( val );
120+
if ( prop === 'tickCount' ) {
121+
n = Number( tmp );
122+
if ( tmp === '' ) {
123+
val = void 0;
124+
} else if ( !isnan( n ) ) {
125+
val = n;
126+
} else if ( tmp.indexOf( ',' ) !== -1 ) {
127+
tmp = tmp.split( /\s*,\s*/ );
128+
val = {
129+
'interval': tmp[ 0 ],
130+
'step': parseInt( tmp[ 1 ], 10 )
131+
};
132+
}
133+
}
113134
}
114135

115136
log( 'Editor changed: %s/%s', path, prop );
@@ -123,7 +144,7 @@ function onChange( event ) {
123144

124145
log( 'Attempting to update configuration...' );
125146
url = URL_PREFIX+'/'+( ( path ) ? path+'/' : path )+prop;
126-
fetch( url, requestOptions( event.value.toString() ) )
147+
fetch( url, requestOptions( event.value.toString() ) ) // eslint-disable-line n/no-unsupported-features/node-builtins
127148
.then( onResponse )
128149
.catch( onError );
129150

lib/node_modules/@stdlib/plot/base/view/lib/browser/app/schema/transforms/axis.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ var PROPS = [
4343
'gridDashOffset',
4444
'gridOpacity',
4545
'gridWidth',
46+
'tickBand',
47+
'tickCap',
48+
'tickColor',
49+
'tickCount',
50+
'tickDash',
51+
'tickDashOffset',
52+
'tickMinStep',
53+
'tickOffset',
54+
'tickOpacity',
55+
'ticks',
56+
'tickSize',
57+
'tickWidth',
4658
'title',
4759
'titleColor',
4860
'titleFont',
@@ -67,6 +79,7 @@ var PROPS = [
6779
* @returns {Object} transformed schema
6880
*/
6981
function transform( schema, signals, defaults, prefix ) {
82+
var value;
7083
var name;
7184
var out;
7285
var k;
@@ -79,12 +92,21 @@ function transform( schema, signals, defaults, prefix ) {
7992
v = schema[ k ];
8093
if ( !isSignalReference( v ) ) {
8194
name = signalName( prefix+k );
82-
signals.push({
83-
'name': name,
84-
'value': ( isUndefined( v ) ) ? defaults[ k ].default : v
85-
});
95+
value = ( isUndefined( v ) ) ? defaults[ k ].default : v;
8696

87-
// FIXME: Vega does not currently support signal updates for structural properties like `domain` and `grid`. As a workaround, we keep them statically `true` and dynamically hide them by dropping their respective opacities to 0 when unchecked.
97+
if ( k === 'tickCount' ) {
98+
signals.push({
99+
'name': name,
100+
'value': ( value === '' ) ? void 0 : value
101+
});
102+
} else {
103+
signals.push({
104+
'name': name,
105+
'value': value
106+
});
107+
}
108+
109+
// FIXME: Vega does not currently support signal updates for structural properties like `domain`, `grid` & `ticks`. As a workaround, we keep them statically `true` and dynamically hide them by dropping their respective opacities to 0 when unchecked.
88110
if ( k === 'domain' ) {
89111
out[ k ] = true;
90112
} else if ( k === 'domainOpacity' ) {
@@ -97,6 +119,12 @@ function transform( schema, signals, defaults, prefix ) {
97119
out[ k ] = {
98120
'signal': signalName( prefix+'grid' ) + ' ? ' + name + ' : 0'
99121
};
122+
} else if ( k === 'ticks' ) {
123+
out[ k ] = true;
124+
} else if ( k === 'tickOpacity' ) {
125+
out[ k ] = {
126+
'signal': signalName( prefix+'ticks' ) + ' ? ' + name + ' : 0'
127+
};
100128
} else {
101129
out[ k ] = {
102130
'signal': name

lib/node_modules/@stdlib/plot/base/view/lib/browser/routes/app/bundle.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
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) 2026 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 schema = require( './schema.json' );
24+
var handler = require( './main.js' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Defines a route handler for receiving updating a plot configuration.
31+
*
32+
* @private
33+
* @returns {Object} route declaration
34+
*/
35+
function route() {
36+
schema.handler = handler;
37+
return schema;
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = route;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 middleware = require( './../../../../middleware_sequence.js' );
24+
var allowCredentials = require( './../../../../middleware/allow-credentials' );
25+
var tryAssign = require( './../../../../middleware/plot-try-assign' );
26+
var body = require( './../../../../middleware/body' );
27+
var ok = require( './../../../../middleware/ok' );
28+
var onError = require( './../../../../middleware/error' );
29+
30+
31+
// VARIABLES //
32+
33+
var steps = [
34+
allowCredentials,
35+
body,
36+
tryAssign( [ 'config', 'axes', ':axis' ], 'tickBand' ),
37+
ok
38+
];
39+
40+
41+
// MAIN //
42+
43+
/**
44+
* Request handler for updating a plot configuration.
45+
*
46+
* @private
47+
* @name handler
48+
* @type {Function}
49+
* @param {Object} request - request object
50+
* @param {Object} response - response object
51+
*/
52+
var handler = middleware( steps, onError );
53+
54+
55+
// EXPORTS //
56+
57+
module.exports = handler;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"method": "POST",
3+
"url": "/config/axes/:axis/tickBand",
4+
"schema": {
5+
"response": {
6+
"200": {
7+
"type": "string"
8+
},
9+
"400": {
10+
"type": "object",
11+
"properties": {
12+
"statusCode": {
13+
"type": "integer"
14+
},
15+
"error": {
16+
"type": "string"
17+
},
18+
"message": {
19+
"type": "string"
20+
}
21+
}
22+
},
23+
"413": {
24+
"type": "object",
25+
"properties": {
26+
"statusCode": {
27+
"type": "integer"
28+
},
29+
"error": {
30+
"type": "string"
31+
},
32+
"message": {
33+
"type": "string"
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"handler": null
40+
}
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) 2026 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 schema = require( './schema.json' );
24+
var handler = require( './main.js' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Defines a route handler for receiving updating a plot configuration.
31+
*
32+
* @private
33+
* @returns {Object} route declaration
34+
*/
35+
function route() {
36+
schema.handler = handler;
37+
return schema;
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = route;

0 commit comments

Comments
 (0)