Skip to content

Commit 1af058a

Browse files
committed
allow all info_arrays to be pruned and command args to be optional
1 parent 46962af commit 1af058a

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

Diff for: src/lib/nested_property.js

+9-16
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,23 @@ function npGet(cont, parts) {
114114
};
115115
}
116116

117-
/*
118-
* Check known non-data-array arrays (containers). Data arrays only contain scalars,
119-
* so parts[end] values, such as -1 or n, indicate we are not dealing with a dataArray.
120-
* The ONLY case we are looking for is where the entire array is selected, parts[end] === 'x'
121-
* AND the replacement value is an array.
122-
*/
123-
// function isNotAContainer(key) {
124-
// var containers = ['annotations', 'shapes', 'range', 'domain', 'buttons'];
125-
126-
// return containers.indexOf(key) === -1;
127-
// }
128-
129117
/*
130118
* Can this value be deleted? We can delete any empty object (null, undefined, [], {})
131-
* EXCEPT empty data arrays. If it's not a data array, it's a container array,
132-
* ie containing objects like annotations, buttons, etc
119+
* EXCEPT empty data arrays. Info arrays can be safely deleted, but not deleting them
120+
* has no ill effects other than leaving a trace or layout object with some cruft in it.
121+
* But deleting data arrays can change the meaning of the object, as `[]` means there is
122+
* data for this attribute, it's just empty right now while `undefined` means the data
123+
* should be filled in with defaults to match other data arrays. So we do some simple
124+
* tests here to find known non-data arrays but don't worry too much about not deleting
125+
* some arrays that would actually be safe to delete.
133126
*/
134-
var DOMAIN_RANGE = /(^|.)(domain|range)$/;
127+
var INFO_PATTERNS = /(^|.)((domain|range)(\.[xy])?|args|parallels)$/;
135128
function isDeletable(val, propStr) {
136129
if(!emptyObj(val)) return false;
137130
if(!isArray(val)) return true;
138131

139132
// domain and range are special - they show up in lots of places so hard code here.
140-
if(propStr.match(DOMAIN_RANGE)) return true;
133+
if(propStr.match(INFO_PATTERNS)) return true;
141134

142135
var match = containerArrayMatch(propStr);
143136
// if propStr matches the container array itself, index is an empty string

Diff for: src/plots/command.js

+8
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ exports.hasSimpleAPICommandBindings = function(gd, commandList, bindingsByValue)
156156
var method = command.method;
157157
var args = command.args;
158158

159+
if(!Array.isArray(args)) args = [];
160+
159161
// If any command has no method, refuse to bind:
160162
if(!method) {
161163
return false;
@@ -263,6 +265,9 @@ exports.executeAPICommand = function(gd, method, args) {
263265
var apiMethod = Plotly[method];
264266

265267
var allArgs = [gd];
268+
269+
if(!Array.isArray(args)) args = [];
270+
266271
for(var i = 0; i < args.length; i++) {
267272
allArgs.push(args[i]);
268273
}
@@ -275,6 +280,9 @@ exports.executeAPICommand = function(gd, method, args) {
275280

276281
exports.computeAPICommandBindings = function(gd, method, args) {
277282
var bindings;
283+
284+
if(!Array.isArray(args)) args = [];
285+
278286
switch(method) {
279287
case 'restyle':
280288
bindings = computeDataBindings(gd, args);

Diff for: test/jasmine/tests/sliders_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ describe('sliders defaults', function() {
9797

9898
expect(layoutOut.sliders[0].steps.length).toEqual(3);
9999
expect(layoutOut.sliders[0].steps).toEqual([{
100-
method: 'relayout', args: [],
100+
method: 'relayout',
101101
label: 'Label #1',
102102
value: 'label-1'
103103
}, {
104-
method: 'update', args: [],
104+
method: 'update',
105105
label: 'Label #2',
106106
value: 'Label #2'
107107
}, {
108-
method: 'animate', args: [],
108+
method: 'animate',
109109
label: 'step-2',
110110
value: 'lacks-label'
111111
}]);

0 commit comments

Comments
 (0)