Skip to content

Commit 8f39ff8

Browse files
committed
feat: add initial support for editing axis properties
--- 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 caf1c44 commit 8f39ff8

File tree

19 files changed

+656
-108
lines changed

19 files changed

+656
-108
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function onEditorChange( event ) {
101101
function onRefresh( event ) {
102102
state.schema.raw = parseJSON( event.data );
103103
state.view.init();
104-
state.editor.refresh(); // FIXME: we may need to be more intelligent here, as the new schema could have new axes, marks, etc. Using `refresh` assumes that
104+
state.editor.refresh(); // FIXME: we may need to be more intelligent here, as the new schema could have new axes, marks, etc. Using `refresh` assumes that the general structure of the schema remains the same (i.e., we don't need to delete and/or remove folders, etc)
105105
}
106106

107107
/**
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var axis = require( './axis.js' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Synchronizes a list of axis editor configurations with a provided schema.
30+
*
31+
* @private
32+
* @param {Array<Object>} conf - list of axis configuration objects
33+
* @param {Object} schema - visualization schema
34+
* @returns {Array<Object>} mutated configuration objects
35+
*/
36+
function config( conf, schema ) {
37+
var list;
38+
var M;
39+
var N;
40+
var i;
41+
42+
list = schema.axes;
43+
if ( !list ) {
44+
return [];
45+
}
46+
M = list.length;
47+
N = conf.length;
48+
if ( N > M ) {
49+
// WARNING: discarding extra configurations means that axis configuration objects become orphaned; thus, any editor controllers which still reference those objects will no longer sync with the greater editor configuration...
50+
conf.length = M;
51+
} else if ( N < M ) {
52+
for ( i = N; i <= M; i++ ) {
53+
conf.push( {} );
54+
}
55+
}
56+
for ( i = 0; i < M; i++ ) {
57+
conf[ i ] = axis( conf[ i ], list[ i ] );
58+
}
59+
return conf;
60+
}
61+
62+
63+
// EXPORTS //
64+
65+
module.exports = config;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 defaults = require( './../defaults.js' );
24+
var resolveValue = require( './resolve_value.js' );
25+
var resolveTextValue = require( './resolve_text_value.js' );
26+
27+
28+
// VARIABLES //
29+
30+
var PROPS = [];
31+
var TEXT_PROPS = [
32+
'title'
33+
];
34+
35+
36+
// MAIN //
37+
38+
/**
39+
* Synchronizes an axis editor configuration with a provided schema.
40+
*
41+
* @private
42+
* @param {Object} conf - axis configuration object
43+
* @param {Object} schema - axis schema
44+
* @returns {Object} mutated configuration object
45+
*/
46+
function config( conf, schema ) {
47+
var def;
48+
var i;
49+
50+
def = defaults.axis;
51+
52+
// FIXME: remove this once we have proper defaults
53+
def = {
54+
'title': {
55+
'property': 'title',
56+
'default': '',
57+
'type': 'string'
58+
}
59+
};
60+
for ( i = 0; i < TEXT_PROPS.length; i++ ) {
61+
resolveTextValue( schema, def, conf, TEXT_PROPS[ i ] );
62+
}
63+
for ( i = 0; i < PROPS.length; i++ ) {
64+
resolveValue( schema, def, conf, PROPS[ i ] );
65+
}
66+
return conf;
67+
}
68+
69+
70+
// EXPORTS //
71+
72+
module.exports = config;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ var PROPS = [
3939
// MAIN //
4040

4141
/**
42-
* Synchronizes an editor configuration with a provided schema.
42+
* Synchronizes a padding editor configuration with a provided schema.
4343
*
4444
* @private
45-
* @param {Object} conf - configuration object
45+
* @param {Object} conf - padding configuration object
4646
* @param {Object} schema - visualization schema
4747
* @returns {Object} mutated configuration object
4848
*/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 isSignalReference = require( '@stdlib/plot/vega/base/assert/is-signal-reference' );
24+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
25+
var isUndefined = require( '@stdlib/assert/is-undefined' );
26+
var join = require( '@stdlib/array/base/join' );
27+
28+
29+
// MAIN //
30+
31+
/**
32+
* Resolves a text configuration value.
33+
*
34+
* @private
35+
* @param {Object} src - source object
36+
* @param {Object} defaults - defaults object
37+
* @param {Object} dest - destination object
38+
* @param {string} prop - property name
39+
*/
40+
function resolveTextValue( src, defaults, dest, prop ) {
41+
var v = src[ prop ];
42+
if ( !isSignalReference( v ) ) {
43+
if ( isUndefined( v ) ) {
44+
dest[ prop ] = defaults[ prop ].default;
45+
} else if ( isString( v ) ) {
46+
dest[ prop ] = v;
47+
} else {
48+
dest[ prop ] = join( v, '\n' );
49+
}
50+
}
51+
}
52+
53+
54+
// EXPORTS //
55+
56+
module.exports = resolveTextValue;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var general = require( './general.js' );
2424
var padding = require( './padding.js' );
2525
var title = require( './title.js' );
26+
var axes = require( './axes.js' );
2627

2728

2829
// MAIN //
@@ -39,8 +40,9 @@ function sync( conf, schema ) {
3940
general( conf.general, schema );
4041
padding( conf.padding, schema );
4142
title( conf.title, schema );
43+
axes( conf.axes, schema );
4244

43-
// TODO: sync each axis
45+
// TODO: sync marks, legends, projections, scales, etc
4446

4547
return conf;
4648
}

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

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@
2020

2121
// MODULES //
2222

23-
var isSignalReference = require( '@stdlib/plot/vega/base/assert/is-signal-reference' );
24-
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
25-
var isUndefined = require( '@stdlib/assert/is-undefined' );
26-
var join = require( '@stdlib/array/base/join' );
2723
var defaults = require( './../defaults.js' );
2824
var resolveValue = require( './resolve_value.js' );
25+
var resolveTextValue = require( './resolve_text_value.js' );
2926

3027

3128
// VARIABLES //
@@ -61,38 +58,13 @@ var TEXT_PROPS = [
6158
];
6259

6360

64-
// FUNCTIONS //
65-
66-
/**
67-
* Resolves a text configuration value.
68-
*
69-
* @private
70-
* @param {Object} src - source object
71-
* @param {Object} defaults - defaults object
72-
* @param {Object} dest - destination object
73-
* @param {string} prop - property name
74-
*/
75-
function resolveTextValue( src, defaults, dest, prop ) {
76-
var v = src[ prop ];
77-
if ( !isSignalReference( v ) ) {
78-
if ( isUndefined( v ) ) {
79-
dest[ prop ] = defaults[ prop ].default;
80-
} else if ( isString( v ) ) {
81-
dest[ prop ] = v;
82-
} else {
83-
dest[ prop ] = join( v, '\n' );
84-
}
85-
}
86-
}
87-
88-
8961
// MAIN //
9062

9163
/**
92-
* Synchronizes an editor configuration with a provided schema.
64+
* Synchronizes a title editor configuration with a provided schema.
9365
*
9466
* @private
95-
* @param {Object} conf - configuration object
67+
* @param {Object} conf - title configuration object
9668
* @param {Object} schema - visualization schema
9769
* @returns {Object} mutated configuration object
9870
*/

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var log = require( './../log.js' );
3131
var createGeneral = require( './menus/general.js' );
3232
var createPadding = require( './menus/padding.js' );
3333
var createTitle = require( './menus/title.js' );
34+
var createAxes = require( './menus/axes.js' );
3435
var sync = require( './config/sync.js' );
3536
var onChange = require( './on_change.js' );
3637
var defaults = require( './defaults.js' );
@@ -66,9 +67,7 @@ function Editor( state ) {
6667
'general': {
6768
'renderer': 'svg'
6869
},
69-
'autosize': {},
7070
'axes': [],
71-
'data': [],
7271
'legends': [],
7372
'marks': [],
7473
'padding': {},
@@ -77,8 +76,9 @@ function Editor( state ) {
7776
'title': {}
7877
};
7978

80-
// Menu folders:
81-
this._folders = {};
79+
// Editor tree:
80+
this._tree = null;
81+
this._initTree();
8282

8383
return this;
8484
}
@@ -99,6 +99,29 @@ inherit( Editor, EventEmitter );
9999
*/
100100
setReadOnly( Editor.prototype, '_onChange', onChange );
101101

102+
/**
103+
* Initializes an editor tree.
104+
*
105+
* @private
106+
* @name _initTree
107+
* @memberof Editor.prototype
108+
* @type {Function}
109+
* @returns {Editor} editor instance
110+
*/
111+
setReadOnly( Editor.prototype, '_initTree', function initTree() {
112+
this._tree = {
113+
'general': null,
114+
'axes': null,
115+
'legends': null,
116+
'marks': null,
117+
'padding': null,
118+
'projections': null,
119+
'scales': null,
120+
'title': null
121+
};
122+
return this;
123+
});
124+
102125
/**
103126
* Creates an editor.
104127
*
@@ -128,11 +151,10 @@ setReadOnly( Editor.prototype, 'create', function create() {
128151
editor.add( o, 'Toggle Menus' );
129152

130153
conf = this._config;
131-
createGeneral( editor, conf.general );
132-
createPadding( editor, conf.padding );
133-
createTitle( editor, conf.title );
134-
135-
// TODO: for axes menus, we need to loop over each spec axis and create a dedicated sub-folder; if there are no axes, no folder grouping to display
154+
this._tree.general = createGeneral( editor, conf.general );
155+
this._tree.padding = createPadding( editor, conf.padding );
156+
this._tree.title = createTitle( editor, conf.title );
157+
this._tree.axes = createAxes( editor, conf.axes );
136158

137159
editor.onFinishChange( onChange );
138160

@@ -237,6 +259,7 @@ setReadOnly( Editor.prototype, 'refreshControllers', function refreshControllers
237259
setReadOnly( Editor.prototype, 'remove', function remove() {
238260
log( 'Removing editor...' );
239261
this._editor.destroy();
262+
this._initTree();
240263
log( 'Editor removed.' );
241264
return this;
242265
});

0 commit comments

Comments
 (0)