Skip to content

Commit cbdf795

Browse files
committed
no editType nesting - just docalc on editing full containers
1 parent e5a2f91 commit cbdf795

File tree

3 files changed

+18
-53
lines changed

3 files changed

+18
-53
lines changed

src/plot_api/edit_types.js

+5-29
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,14 @@ module.exports = {
4747

4848
/*
4949
* update `flags` with the `editType` values found in `attr`
50-
*
51-
* If `attr` itself contains an `editType`, we just use that.
52-
* If it doesn't, we recurse into any other objects contained
53-
* in `attr` and update with all `editType` values found in
54-
* *any* of them.
55-
*
56-
* So container objects may not need their own `editType`,
57-
* if they're content to delegate to their members, but they
58-
* may provide one either for performance or, in case of arrays,
59-
* if adding/removing entries requires different flags than
60-
* simply changing attributes of an existing entry.
6150
*/
6251
update: function(flags, attr) {
63-
function extend(attr1) {
64-
var editType = attr1.editType;
65-
if(editType === undefined) {
66-
// if there's no editType defined, recurse into
67-
Object.keys(attr1).forEach(function(attrName) {
68-
var attr2 = attr1[attrName];
69-
if(attrName.charAt(0) !== '_' && isPlainObject(attr2)) {
70-
extend(attr2);
71-
}
72-
});
73-
}
74-
else {
75-
var editTypeParts = editType.split('+');
76-
editTypeParts.forEach(function(part) {
77-
flags[part] = true;
78-
});
52+
var editType = attr.editType;
53+
if(editType) {
54+
var editTypeParts = editType.split('+');
55+
for(var i = 0; i < editTypeParts.length; i++) {
56+
flags[editTypeParts[i]] = true;
7957
}
8058
}
81-
82-
extend(attr);
8359
}
8460
};

src/plot_api/plot_api.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,14 @@ function _restyle(gd, aobj, _traces) {
16261626
else break;
16271627
}
16281628

1629-
// must redo calcdata when restyling array values of arrayOk attributes
1630-
if(valObject.arrayOk && (Array.isArray(newVal) || Array.isArray(oldVal))) {
1629+
/*
1630+
* must redo calcdata when restyling:
1631+
* 1) array values of arrayOk attributes
1632+
* 2) a container object (it would be hard to tell what
1633+
* pieces changed, whether any are arrays, so to be
1634+
* safe we need to recalc)
1635+
*/
1636+
if(!valObject.valType || (valObject.arrayOk && (Array.isArray(newVal) || Array.isArray(oldVal)))) {
16311637
flags.docalc = true;
16321638
}
16331639

test/jasmine/tests/plot_api_test.js

+5-22
Original file line numberDiff line numberDiff line change
@@ -1777,29 +1777,12 @@ describe('plot_api edit_types', function() {
17771777
var flags = {docalc: false, dolegend: true};
17781778

17791779
editTypes.update(flags, {
1780-
editType: 'docalc',
1781-
family: {valType: 'string', dflt: 'Comic sans', editType: 'doticks'},
1782-
size: {valType: 'number', dflt: 96, editType: 'doticks'},
1783-
color: {valType: 'color', dflt: 'red', editType: 'dolayoutstyle'}
1784-
});
1785-
1786-
expect(flags).toEqual({docalc: true, dolegend: true});
1787-
});
1788-
1789-
it('gets all updates from nested items if outer object has none', function() {
1790-
var flags = {docalc: false, dolegend: true};
1791-
1792-
editTypes.update(flags, {
1793-
family: {valType: 'string', dflt: 'Comic sans', editType: 'doticks'},
1794-
size: {valType: 'number', dflt: 96, editType: 'doticks'},
1795-
color: {valType: 'color', dflt: 'red', editType: 'dolayoutstyle'}
1780+
editType: 'docalc+dostyle',
1781+
valType: 'number',
1782+
dflt: 1,
1783+
role: 'style'
17961784
});
17971785

1798-
expect(flags).toEqual({
1799-
docalc: false,
1800-
dolegend: true,
1801-
doticks: true,
1802-
dolayoutstyle: true
1803-
});
1786+
expect(flags).toEqual({docalc: true, dolegend: true, dostyle: true});
18041787
});
18051788
});

0 commit comments

Comments
 (0)