Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var isArray = require( '@stdlib/assert/is-array' );
var defaults = require( './../defaults.js' );

Check warning on line 24 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/config/legend.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

only the `legend` property of the required module is used; require the property directly
var resolveValue = require( './resolve_value.js' );
var resolveTextValue = require( './resolve_text_value.js' );
var resolveSchemaValue = require( './resolve_schema_value.js' );


// VARIABLES //

var PROPS = [
'direction',
'orient',
'type'
];
var ARRAY_PROPS = [
];
var SCHEMA_PROPS = [
];
var TEXT_PROPS = [
];


// MAIN //

/**
* Synchronizes an legend editor configuration with a provided schema.
*
* @private
* @param {Object} conf - legend configuration object
* @param {Object} schema - legend schema
* @returns {Object} mutated configuration object
*/
function config( conf, schema ) {
var def;
var i;

def = defaults.legend;

for ( i = 0; i < TEXT_PROPS.length; i++ ) {
resolveTextValue( schema, def, conf, TEXT_PROPS[ i ] );
}
for ( i = 0; i < ARRAY_PROPS.length; i++ ) {
resolveValue( schema, def, conf, ARRAY_PROPS[ i ] );
if ( isArray( conf[ ARRAY_PROPS[ i ] ] ) ) {
conf[ ARRAY_PROPS[ i ] ] = conf[ ARRAY_PROPS[ i ] ].join( ', ' );
}
}
for ( i = 0; i < PROPS.length; i++ ) {
resolveValue( schema, def, conf, PROPS[ i ] );
}
for ( i = 0; i < SCHEMA_PROPS.length; i++ ) {
resolveSchemaValue( schema, def, conf, SCHEMA_PROPS[ i ] );
}
return conf;
}


// EXPORTS //

module.exports = config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var legend = require( './legend.js' );


// MAIN //

/**
* Synchronizes a list of legend editor configurations with a provided schema.
*
* @private
* @param {Array<Object>} conf - list of legend configuration objects
* @param {Object} schema - visualization schema
* @returns {Array<Object>} mutated configuration objects
*/
function config( conf, schema ) {
var list;
var M;
var N;
var i;

list = schema.legends;
if ( !list ) {
return [];
}
M = list.length;
N = conf.length;
if ( N > M ) {
// WARNING: discarding extra configurations means that legend configuration objects become orphaned; thus, any editor controllers which still reference those objects will no longer sync with the greater editor configuration...

Check warning on line 49 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/config/legends.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'warning' comment: 'WARNING: discarding extra configurations...'
conf.length = M;
} else if ( N < M ) {
for ( i = N; i <= M; i++ ) {
conf.push( {} );
}
}
for ( i = 0; i < M; i++ ) {
conf[ i ] = legend( conf[ i ], list[ i ] );
}
return conf;
}


// EXPORTS //

module.exports = config;
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
var padding = require( './padding.js' );
var title = require( './title.js' );
var axes = require( './axes.js' );
var legends = require( './legends.js' );


// MAIN //
Expand All @@ -41,8 +42,9 @@
padding( conf.padding, schema );
title( conf.title, schema );
axes( conf.axes, schema );
legends( conf.legends, schema );

// TODO: sync marks, legends, projections, scales, etc
// TODO: sync marks, projections, scales, etc

Check warning on line 47 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/config/sync.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: sync marks, projections, scales,...'

return conf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
var EventEmitter = require( 'events' ).EventEmitter;
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
var inherit = require( '@stdlib/utils/inherit' );
var lil = require( './../globals/lil_gui.js' );

Check warning on line 28 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/index.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

only the `GUI` property of the required module is used; require the property directly
var config = require( './../config.js' );

Check warning on line 29 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/index.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

only the `editor` property of the required module is used; require the property directly
var log = require( './../log.js' );
var createGeneral = require( './menus/general.js' );
var createPadding = require( './menus/padding.js' );
var createTitle = require( './menus/title.js' );
var createAxes = require( './menus/axes.js' );
var createLegends = require( './menus/legends.js' );
var sync = require( './config/sync.js' );
var onChange = require( './on_change.js' );
var defaults = require( './defaults.js' );
Expand Down Expand Up @@ -155,6 +156,7 @@
this._tree.padding = createPadding( editor, conf.padding );
this._tree.title = createTitle( editor, conf.title );
this._tree.axes = createAxes( editor, conf.axes, this._state.schema.raw );
this._tree.legends = createLegends( editor, conf.legends, this._state.schema.raw );

Check warning on line 159 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/index.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 87. Maximum allowed is 80

editor.onFinishChange( onChange );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var objectKeys = require( '@stdlib/utils/keys' );
var defaults = require( './../defaults.js' );

Check warning on line 24 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/menus/legend.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

only the `legend` property of the required module is used; require the property directly


// VARIABLES //

var EMPTY_STRING = [ '' ];


// MAIN //

/**
* Adds an legend menu to a parent folder.
*
* @private
* @param {Editor} parent - parent folder instance
* @param {Object} conf - editor legend configuration
* @param {Object} schema - visualization schema
* @param {string} name - folder name
* @returns {(Object|null)} menu tree
*/
function addMenu( parent, conf, schema, name ) {
var controllers;
var controller;
var folder;
var keys;
var def;
var d;
var i;
var k;

keys = objectKeys( conf );
if ( keys.length === 0 ) {
return null;
}
folder = parent.addFolder( name );
folder.close();

def = defaults.legend;

controllers = {};
for ( i = 0; i < keys.length; i++ ) {
k = keys[ i ];
d = def[ k ];
if ( k === 'direction' ) {
controller = folder.add( conf, k, EMPTY_STRING.concat( d.values ) );
} else if ( k === 'orient' ) {
controller = folder.add( conf, k, EMPTY_STRING.concat( d.values ) );
} else if ( k === 'type' ) {
controller = folder.add( conf, k, EMPTY_STRING.concat( d.values ) );
} else {
console.log( 'Unrecognized property in editor configuration. Key: %s.', k );

Check warning on line 74 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/menus/legend.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected console statement
continue;
}
controllers[ k ] = controller;
}
return {
'folder': folder,
'controllers': controllers
};
}


// EXPORTS //

module.exports = addMenu;
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var format = require( '@stdlib/string/format' );
var legend = require( './legend.js' );


// MAIN //

/**
* Adds an legends menu to an editor.
*
* @private
* @param {Editor} editor - editor instance
* @param {Array<Object>} conf - list of editor legend configurations
* @param {Object} schema - visualization schema
* @returns {(Object|null)} menu tree
*/
function addMenu( editor, conf, schema ) {
var children;
var folder;
var o;
var i;

if ( conf.length === 0 ) {
return null;
}
folder = editor.addFolder( 'Legends' );
folder.close();

children = [];
for ( i = 0; i < conf.length; i++ ) {
o = legend( folder, conf[ i ], schema, format( 'Legend %d', i+1 ) );
if ( o ) {
children.push( o );
}
}
return {
'folder': folder,
'children': children
};
}


// EXPORTS //

module.exports = addMenu;
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var join = require( '@stdlib/array/base/join' );
var log = require( './../log.js' );
var config = require( './../config.js' );

Check warning on line 33 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/on_change.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

only the `routes` property of the required module is used; require the property directly


// VARIABLES //
Expand Down Expand Up @@ -83,7 +83,7 @@
self = this;
conf = this._config;

// FIXME: other properties/objects

Check warning on line 86 in lib/node_modules/@stdlib/plot/base/view/lib/browser/app/editor/on_change.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: other properties/objects'

obj = event.object;
if ( obj === conf.general ) {
Expand All @@ -98,6 +98,11 @@
ns = [ 'axes', i.toString() ];
}
}
for ( i = 0; i < conf.legends.length; i++ ) {
if ( obj === conf.legends[ i ] ) {
ns = [ 'legends', i.toString() ];
}
}
if ( ns === void 0 ) {
ns = [ '' ];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var isUndefined = require( '@stdlib/assert/is-undefined' );
var general = require( './transforms/general.js' );
var title = require( './transforms/title.js' );
var axes = require( './transforms/axes.js' );
var legends = require( './transforms/legends.js' );


// MAIN //
Expand Down Expand Up @@ -68,11 +69,13 @@ function transform( schema, defaults ) {
if ( schema.axes && schema.axes.length ) {
out.axes = axes( schema.axes, out.signals, defaults.axis );
}
if ( schema.legends && schema.legends.length ) {
out.legends = legends( schema.legends, out.signals, defaults.legend );
}

// FIXME: the following properties in order of priority
out.scales = schema.scales;
out.marks = schema.marks;
out.legends = schema.legends;
out.projections = schema.projections;

return out;
Expand Down
Loading
Loading