Skip to content

Commit 6c9596f

Browse files
Merge remote-tracking branch 'origin/master' into UtilizeRootInActions
2 parents 045f3ed + 8ebc3bf commit 6c9596f

File tree

1 file changed

+43
-3
lines changed
  • shelly/plotlyjs/static/plotlyjs/src

1 file changed

+43
-3
lines changed

shelly/plotlyjs/static/plotlyjs/src/queue.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
'use strict';
22

3-
var clone = require('clone');
3+
/**
4+
* Copy arg array *without* removing `undefined` values from objects.
5+
*
6+
* `$.extend(true, *, *)` ignores `undefined` object properties, which we
7+
* depend on in relayout and restyle. This function exists *purely* to
8+
* conserve these undefined properties.
9+
*
10+
* Note, it doesn't bother with undefined properties inside an object in
11+
* an array. We don't have a use-case for this, so it doesn't matter.
12+
*
13+
* @param gd
14+
* @param args
15+
* @returns {Array}
16+
*/
17+
function copyArgArray (gd, args) {
18+
var copy = [],
19+
i,
20+
arg,
21+
ai;
22+
for (i = 0; i < args.length; i++) {
23+
arg = args[i];
24+
if (arg === gd) {
25+
copy[i] = arg;
26+
} else if (typeof arg === 'object') {
27+
if (Array.isArray(arg)) {
28+
copy[i] = $.extend(true, [], arg);
29+
} else {
30+
copy[i] = {};
31+
32+
// this is the important line! `undefined` things are kept!
33+
for(ai in arg) copy[i][ai] = arg[ai];
34+
}
35+
} else {
36+
copy[i] = arg;
37+
}
38+
}
39+
return copy;
40+
}
441

542

643
// -----------------------------------------------------
@@ -162,8 +199,11 @@ queue.redo = function redo (gd) {
162199
queue.plotDo = function (gd, func, args) {
163200
gd.autoplay = true;
164201

165-
// call the supplied function with a cloned args
166-
func.apply(null, clone(args));
202+
// this *won't* copy gd and it preserves `undefined` properties!
203+
args = copyArgArray(gd, args);
204+
205+
// call the supplied function
206+
func.apply(null, args);
167207
};
168208

169209
module.exports = queue;

0 commit comments

Comments
 (0)