Skip to content

Commit 61ecd42

Browse files
committed
generalise plot schema handling of component attributes
- replace layoutNodes list with _module.schema object which allow multiple distinct attribute (e.g. with different description) for each nodes
1 parent 05b2f96 commit 61ecd42

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/components/rangeselector/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ module.exports = {
1212
moduleType: 'component',
1313
name: 'rangeselector',
1414

15-
layoutNodes: ['xaxis.'],
15+
schema: {
16+
layout: {
17+
'xaxis.rangeselector': require('./attributes')
18+
}
19+
},
20+
1621
layoutAttributes: require('./attributes'),
1722
handleDefaults: require('./defaults'),
1823

src/components/rangeslider/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ module.exports = {
1212
moduleType: 'component',
1313
name: 'rangeslider',
1414

15-
layoutNodes: ['xaxis.'],
15+
schema: {
16+
layout: {
17+
'xaxis.rangeslider': require('./attributes')
18+
}
19+
},
20+
1621
layoutAttributes: require('./attributes'),
1722
handleDefaults: require('./defaults'),
1823

src/plot_api/plot_schema.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,19 @@ function getLayoutAttributes() {
257257
// polar layout attributes
258258
layoutAttributes = assignPolarLayoutAttrs(layoutAttributes);
259259

260-
// add registered components layout attribute
260+
// add registered components layout attributes
261261
Object.keys(Registry.componentsRegistry).forEach(function(k) {
262262
var _module = Registry.componentsRegistry[k];
263263

264264
if(!_module.layoutAttributes) return;
265265

266-
if(Array.isArray(_module.layoutNodes)) {
267-
_module.layoutNodes.forEach(function(v) {
268-
handleRegisteredComponent(layoutAttributes, _module, v + _module.name);
266+
if(_module.schema && _module.schema.layout) {
267+
Object.keys(_module.schema.layout).forEach(function(v) {
268+
insertAttrs(layoutAttributes, _module.schema.layout[v], v);
269269
});
270270
}
271271
else {
272-
handleRegisteredComponent(layoutAttributes, _module, _module.name);
272+
insertAttrs(layoutAttributes, _module.layoutAttributes, _module.name);
273273
}
274274
});
275275

@@ -366,9 +366,8 @@ function handleBasePlotModule(layoutAttributes, _module, astr) {
366366
np.set(attrs);
367367
}
368368

369-
function handleRegisteredComponent(layoutAttributes, _module, astr) {
370-
var np = Lib.nestedProperty(layoutAttributes, astr),
371-
attrs = extendDeep(np.get() || {}, _module.layoutAttributes);
369+
function insertAttrs(baseAttrs, newAttrs, astr) {
370+
var np = Lib.nestedProperty(baseAttrs, astr);
372371

373-
np.set(attrs);
372+
np.set(extendDeep(np.get() || {}, newAttrs));
374373
}

0 commit comments

Comments
 (0)