Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbb76a4

Browse files
committed
Merge branch 'master' into world-cals
2 parents dcddcee + 6b197a0 commit bbb76a4

File tree

15 files changed

+849
-694
lines changed

15 files changed

+849
-694
lines changed

src/plot_api/plot_api.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,11 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
23292329
var newFrame = trans._currentFrame = trans._frameQueue.shift();
23302330

23312331
if(newFrame) {
2332-
gd._fullLayout._currentFrame = newFrame.name;
2332+
// Since it's sometimes necessary to do deep digging into frame data,
2333+
// we'll consider it not 100% impossible for nulls or numbers to sneak through,
2334+
// so check when casting the name, just to be absolutely certain:
2335+
var stringName = newFrame.name ? newFrame.name.toString() : null;
2336+
gd._fullLayout._currentFrame = stringName;
23332337

23342338
trans._lastFrameAt = Date.now();
23352339
trans._timeToNext = newFrame.frameOpts.duration;
@@ -2351,7 +2355,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
23512355
});
23522356

23532357
gd.emit('plotly_animatingframe', {
2354-
name: newFrame.name,
2358+
name: stringName,
23552359
frame: newFrame.frame,
23562360
animation: {
23572361
frame: newFrame.frameOpts,
@@ -2418,18 +2422,18 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
24182422
type: 'object',
24192423
data: setTransitionConfig(Lib.extendFlat({}, frameOrGroupNameOrFrameList))
24202424
});
2421-
} else if(allFrames || typeof frameOrGroupNameOrFrameList === 'string') {
2425+
} else if(allFrames || ['string', 'number'].indexOf(typeof frameOrGroupNameOrFrameList) !== -1) {
24222426
// In this case, null or undefined has been passed so that we want to
24232427
// animate *all* currently defined frames
24242428
for(i = 0; i < trans._frames.length; i++) {
24252429
frame = trans._frames[i];
24262430

24272431
if(!frame) continue;
24282432

2429-
if(allFrames || frame.group === frameOrGroupNameOrFrameList) {
2433+
if(allFrames || String(frame.group) === String(frameOrGroupNameOrFrameList)) {
24302434
frameList.push({
24312435
type: 'byname',
2432-
name: frame.name,
2436+
name: String(frame.name),
24332437
data: setTransitionConfig({name: frame.name})
24342438
});
24352439
}
@@ -2530,6 +2534,8 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
25302534
Plotly.addFrames = function(gd, frameList, indices) {
25312535
gd = helpers.getGraphDiv(gd);
25322536

2537+
var numericNameWarningCount = 0;
2538+
25332539
if(frameList === null || frameList === undefined) {
25342540
return Promise.resolve();
25352541
}
@@ -2560,6 +2566,25 @@ Plotly.addFrames = function(gd, frameList, indices) {
25602566

25612567
var insertions = [];
25622568
for(i = frameList.length - 1; i >= 0; i--) {
2569+
var name = (_hash[frameList[i].name] || {}).name;
2570+
var newName = frameList[i].name;
2571+
2572+
if(name && newName && typeof newName === 'number' && _hash[name]) {
2573+
numericNameWarningCount++;
2574+
2575+
Lib.warn('addFrames: overwriting frame "' + _hash[name].name +
2576+
'" with a frame whose name of type "number" also equates to "' +
2577+
name + '". This is valid but may potentially lead to unexpected ' +
2578+
'behavior since all plotly.js frame names are stored internally ' +
2579+
'as strings.');
2580+
2581+
if(numericNameWarningCount > 5) {
2582+
Lib.warn('addFrames: This API call has yielded too many warnings. ' +
2583+
'For the rest of this call, further warnings about numeric frame ' +
2584+
'names will be suppressed.');
2585+
}
2586+
}
2587+
25632588
insertions.push({
25642589
frame: Plots.supplyFrameDefaults(frameList[i]),
25652590
index: (indices && indices[i] !== undefined && indices[i] !== null) ? indices[i] : bigIndex + i
@@ -2580,6 +2605,12 @@ Plotly.addFrames = function(gd, frameList, indices) {
25802605
for(i = insertions.length - 1; i >= 0; i--) {
25812606
frame = insertions[i].frame;
25822607

2608+
if(typeof frame.name === 'number') {
2609+
Lib.warn('Warning: addFrames accepts frames with numeric names, but the numbers are' +
2610+
'implicitly cast to strings');
2611+
2612+
}
2613+
25832614
if(!frame.name) {
25842615
// Repeatedly assign a default name, incrementing the counter each time until
25852616
// we get a name that's not in the hashed lookup table:

src/plots/command.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ exports.computeAPICommandBindings = function(gd, method, args) {
301301
function computeAnimateBindings(gd, args) {
302302
// We'll assume that the only relevant modification an animation
303303
// makes that's meaningfully tracked is the frame:
304-
if(Array.isArray(args[0]) && args[0].length === 1 && typeof args[0][0] === 'string') {
305-
return [{type: 'layout', prop: '_currentFrame', value: args[0][0]}];
304+
if(Array.isArray(args[0]) && args[0].length === 1 && ['string', 'number'].indexOf(typeof args[0][0]) !== -1) {
305+
return [{type: 'layout', prop: '_currentFrame', value: args[0][0].toString()}];
306306
} else {
307307
return [];
308308
}

src/plots/plots.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,17 @@ plots.computeFrame = function(gd, frameName) {
14811481
var frameLookup = gd._transitionData._frameHash;
14821482
var i, traceIndices, traceIndex, destIndex;
14831483

1484-
var framePtr = frameLookup[frameName];
1484+
// Null or undefined will fail on .toString(). We'll allow numbers since we
1485+
// make it clear frames must be given string names, but we'll allow numbers
1486+
// here since they're otherwise fine for looking up frames as long as they're
1487+
// properly cast to strings. We really just want to ensure here that this
1488+
// 1) doesn't fail, and
1489+
// 2) doens't give an incorrect answer (which String(frameName) would)
1490+
if(!frameName) {
1491+
throw new Error('computeFrame must be given a string frame name');
1492+
}
1493+
1494+
var framePtr = frameLookup[frameName.toString()];
14851495

14861496
// Return false if the name is invalid:
14871497
if(!framePtr) {
@@ -1492,7 +1502,7 @@ plots.computeFrame = function(gd, frameName) {
14921502
var frameNameStack = [framePtr.name];
14931503

14941504
// Follow frame pointers:
1495-
while((framePtr = frameLookup[framePtr.baseframe])) {
1505+
while(framePtr.baseframe && (framePtr = frameLookup[framePtr.baseframe.toString()])) {
14961506
// Avoid infinite loops:
14971507
if(frameNameStack.indexOf(framePtr.name) !== -1) break;
14981508

src/traces/contour/constants.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
// some constants to help with marching squares algorithm
12+
// where does the path start for each index?
13+
module.exports.BOTTOMSTART = [1, 9, 13, 104, 713];
14+
module.exports.TOPSTART = [4, 6, 7, 104, 713];
15+
module.exports.LEFTSTART = [8, 12, 14, 208, 1114];
16+
module.exports.RIGHTSTART = [2, 3, 11, 208, 1114];
17+
18+
// which way [dx,dy] do we leave a given index?
19+
// saddles are already disambiguated
20+
module.exports.NEWDELTA = [
21+
null, [-1, 0], [0, -1], [-1, 0],
22+
[1, 0], null, [0, -1], [-1, 0],
23+
[0, 1], [0, 1], null, [0, 1],
24+
[1, 0], [1, 0], [0, -1]
25+
];
26+
27+
// for each saddle, the first index here is used
28+
// for dx||dy<0, the second for dx||dy>0
29+
module.exports.CHOOSESADDLE = {
30+
104: [4, 1],
31+
208: [2, 8],
32+
713: [7, 13],
33+
1114: [11, 14]
34+
};
35+
36+
// after one index has been used for a saddle, which do we
37+
// substitute to be used up later?
38+
module.exports.SADDLEREMAINDER = {1: 4, 2: 8, 4: 1, 7: 13, 8: 2, 11: 14, 13: 7, 14: 11};

0 commit comments

Comments
 (0)