@@ -2329,7 +2329,11 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
2329
2329
var newFrame = trans . _currentFrame = trans . _frameQueue . shift ( ) ;
2330
2330
2331
2331
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 ;
2333
2337
2334
2338
trans . _lastFrameAt = Date . now ( ) ;
2335
2339
trans . _timeToNext = newFrame . frameOpts . duration ;
@@ -2351,7 +2355,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
2351
2355
} ) ;
2352
2356
2353
2357
gd . emit ( 'plotly_animatingframe' , {
2354
- name : newFrame . name ,
2358
+ name : stringName ,
2355
2359
frame : newFrame . frame ,
2356
2360
animation : {
2357
2361
frame : newFrame . frameOpts ,
@@ -2418,18 +2422,18 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
2418
2422
type : 'object' ,
2419
2423
data : setTransitionConfig ( Lib . extendFlat ( { } , frameOrGroupNameOrFrameList ) )
2420
2424
} ) ;
2421
- } else if ( allFrames || typeof frameOrGroupNameOrFrameList === 'string' ) {
2425
+ } else if ( allFrames || [ 'string' , 'number' ] . indexOf ( typeof frameOrGroupNameOrFrameList ) !== - 1 ) {
2422
2426
// In this case, null or undefined has been passed so that we want to
2423
2427
// animate *all* currently defined frames
2424
2428
for ( i = 0 ; i < trans . _frames . length ; i ++ ) {
2425
2429
frame = trans . _frames [ i ] ;
2426
2430
2427
2431
if ( ! frame ) continue ;
2428
2432
2429
- if ( allFrames || frame . group === frameOrGroupNameOrFrameList ) {
2433
+ if ( allFrames || String ( frame . group ) === String ( frameOrGroupNameOrFrameList ) ) {
2430
2434
frameList . push ( {
2431
2435
type : 'byname' ,
2432
- name : frame . name ,
2436
+ name : String ( frame . name ) ,
2433
2437
data : setTransitionConfig ( { name : frame . name } )
2434
2438
} ) ;
2435
2439
}
@@ -2530,6 +2534,8 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
2530
2534
Plotly . addFrames = function ( gd , frameList , indices ) {
2531
2535
gd = helpers . getGraphDiv ( gd ) ;
2532
2536
2537
+ var numericNameWarningCount = 0 ;
2538
+
2533
2539
if ( frameList === null || frameList === undefined ) {
2534
2540
return Promise . resolve ( ) ;
2535
2541
}
@@ -2560,6 +2566,25 @@ Plotly.addFrames = function(gd, frameList, indices) {
2560
2566
2561
2567
var insertions = [ ] ;
2562
2568
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
+
2563
2588
insertions . push ( {
2564
2589
frame : Plots . supplyFrameDefaults ( frameList [ i ] ) ,
2565
2590
index : ( indices && indices [ i ] !== undefined && indices [ i ] !== null ) ? indices [ i ] : bigIndex + i
@@ -2580,6 +2605,12 @@ Plotly.addFrames = function(gd, frameList, indices) {
2580
2605
for ( i = insertions . length - 1 ; i >= 0 ; i -- ) {
2581
2606
frame = insertions [ i ] . frame ;
2582
2607
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
+
2583
2614
if ( ! frame . name ) {
2584
2615
// Repeatedly assign a default name, incrementing the counter each time until
2585
2616
// we get a name that's not in the hashed lookup table:
0 commit comments