@@ -42,6 +42,8 @@ var enforceAxisConstraints = axisConstraints.enforce;
42
42
var cleanAxisConstraints = axisConstraints . clean ;
43
43
var axisIds = require ( '../plots/cartesian/axis_ids' ) ;
44
44
45
+ var numericNameWarningCount = 0 ;
46
+ var numericNameWarningCountLimit = 5 ;
45
47
46
48
/**
47
49
* Main plot-creation function
@@ -2592,16 +2594,14 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
2592
2594
* - traces {array} trace indices
2593
2595
* - baseframe {string} name of frame from which this frame gets defaults
2594
2596
*
2595
- * @param {array of integers) indices
2597
+ * @param {array of integers } indices
2596
2598
* an array of integer indices matching the respective frames in `frameList`. If not
2597
2599
* provided, an index will be provided in serial order. If already used, the frame
2598
2600
* will be overwritten.
2599
2601
*/
2600
2602
Plotly . addFrames = function ( gd , frameList , indices ) {
2601
2603
gd = Lib . getGraphDiv ( gd ) ;
2602
2604
2603
- var numericNameWarningCount = 0 ;
2604
-
2605
2605
if ( frameList === null || frameList === undefined ) {
2606
2606
return Promise . resolve ( ) ;
2607
2607
}
@@ -2616,7 +2616,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
2616
2616
2617
2617
var i , frame , j , idx ;
2618
2618
var _frames = gd . _transitionData . _frames ;
2619
- var _hash = gd . _transitionData . _frameHash ;
2619
+ var _frameHash = gd . _transitionData . _frameHash ;
2620
2620
2621
2621
2622
2622
if ( ! Array . isArray ( frameList ) ) {
@@ -2631,28 +2631,35 @@ Plotly.addFrames = function(gd, frameList, indices) {
2631
2631
var bigIndex = _frames . length + frameList . length * 2 ;
2632
2632
2633
2633
var insertions = [ ] ;
2634
+ var _frameHashLocal = { } ;
2634
2635
for ( i = frameList . length - 1 ; i >= 0 ; i -- ) {
2635
2636
if ( ! Lib . isPlainObject ( frameList [ i ] ) ) continue ;
2636
2637
2637
- var name = ( _hash [ frameList [ i ] . name ] || { } ) . name ;
2638
+ // The entire logic for checking for this type of name collision can be removed once we migrate to ES6 and
2639
+ // use a Map instead of an Object instance, as Map keys aren't converted to strings.
2640
+ var lookupName = frameList [ i ] . name ;
2641
+ var name = ( _frameHash [ lookupName ] || _frameHashLocal [ lookupName ] || { } ) . name ;
2638
2642
var newName = frameList [ i ] . name ;
2643
+ var collisionPresent = _frameHash [ name ] || _frameHashLocal [ name ] ;
2639
2644
2640
- if ( name && newName && typeof newName === 'number' && _hash [ name ] ) {
2645
+ if ( name && newName && typeof newName === 'number' && collisionPresent && numericNameWarningCount < numericNameWarningCountLimit ) {
2641
2646
numericNameWarningCount ++ ;
2642
2647
2643
- Lib . warn ( 'addFrames: overwriting frame "' + _hash [ name ] . name +
2648
+ Lib . warn ( 'addFrames: overwriting frame "' + ( _frameHash [ name ] || _frameHashLocal [ name ] ) . name +
2644
2649
'" with a frame whose name of type "number" also equates to "' +
2645
2650
name + '". This is valid but may potentially lead to unexpected ' +
2646
2651
'behavior since all plotly.js frame names are stored internally ' +
2647
2652
'as strings.' ) ;
2648
2653
2649
- if ( numericNameWarningCount > 5 ) {
2650
- Lib . warn ( 'addFrames: This API call has yielded too many warnings. ' +
2654
+ if ( numericNameWarningCount === numericNameWarningCountLimit ) {
2655
+ Lib . warn ( 'addFrames: This API call has yielded too many of these warnings. ' +
2651
2656
'For the rest of this call, further warnings about numeric frame ' +
2652
2657
'names will be suppressed.' ) ;
2653
2658
}
2654
2659
}
2655
2660
2661
+ _frameHashLocal [ lookupName ] = { name : lookupName } ;
2662
+
2656
2663
insertions . push ( {
2657
2664
frame : Plots . supplyFrameDefaults ( frameList [ i ] ) ,
2658
2665
index : ( indices && indices [ i ] !== undefined && indices [ i ] !== null ) ? indices [ i ] : bigIndex + i
@@ -2682,10 +2689,10 @@ Plotly.addFrames = function(gd, frameList, indices) {
2682
2689
if ( ! frame . name ) {
2683
2690
// Repeatedly assign a default name, incrementing the counter each time until
2684
2691
// we get a name that's not in the hashed lookup table:
2685
- while ( _hash [ ( frame . name = 'frame ' + gd . _transitionData . _counter ++ ) ] ) ;
2692
+ while ( _frameHash [ ( frame . name = 'frame ' + gd . _transitionData . _counter ++ ) ] ) ;
2686
2693
}
2687
2694
2688
- if ( _hash [ frame . name ] ) {
2695
+ if ( _frameHash [ frame . name ] ) {
2689
2696
// If frame is present, overwrite its definition:
2690
2697
for ( j = 0 ; j < _frames . length ; j ++ ) {
2691
2698
if ( ( _frames [ j ] || { } ) . name === frame . name ) break ;
0 commit comments