Skip to content

Commit c280f8d

Browse files
committed
minor: stop emitting warnings after having reached a count
1 parent e341edd commit c280f8d

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/plot_api/plot_api.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -2593,7 +2593,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
25932593
* - traces {array} trace indices
25942594
* - baseframe {string} name of frame from which this frame gets defaults
25952595
*
2596-
* @param {array of integers) indices
2596+
* @param {array of integers} indices
25972597
* an array of integer indices matching the respective frames in `frameList`. If not
25982598
* provided, an index will be provided in serial order. If already used, the frame
25992599
* will be overwritten.
@@ -2602,6 +2602,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
26022602
gd = Lib.getGraphDiv(gd);
26032603

26042604
var numericNameWarningCount = 0;
2605+
var numericNameWarningCountLimit = 5;
26052606

26062607
if(frameList === null || frameList === undefined) {
26072608
return Promise.resolve();
@@ -2617,7 +2618,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
26172618

26182619
var i, frame, j, idx;
26192620
var _frames = gd._transitionData._frames;
2620-
var _hash = gd._transitionData._frameHash;
2621+
var _frameHash = gd._transitionData._frameHash;
26212622

26222623

26232624
if(!Array.isArray(frameList)) {
@@ -2635,20 +2636,20 @@ Plotly.addFrames = function(gd, frameList, indices) {
26352636
for(i = frameList.length - 1; i >= 0; i--) {
26362637
if(!Lib.isPlainObject(frameList[i])) continue;
26372638

2638-
var name = (_hash[frameList[i].name] || {}).name;
2639+
var name = (_frameHash[frameList[i].name] || {}).name;
26392640
var newName = frameList[i].name;
26402641

2641-
if(name && newName && typeof newName === 'number' && _hash[name]) {
2642+
if(name && newName && typeof newName === 'number' && _frameHash[name] && numericNameWarningCount < numericNameWarningCountLimit) {
26422643
numericNameWarningCount++;
26432644

2644-
Lib.warn('addFrames: overwriting frame "' + _hash[name].name +
2645+
Lib.warn('addFrames: overwriting frame "' + _frameHash[name].name +
26452646
'" with a frame whose name of type "number" also equates to "' +
26462647
name + '". This is valid but may potentially lead to unexpected ' +
26472648
'behavior since all plotly.js frame names are stored internally ' +
26482649
'as strings.');
26492650

2650-
if(numericNameWarningCount > 5) {
2651-
Lib.warn('addFrames: This API call has yielded too many warnings. ' +
2651+
if(numericNameWarningCount === numericNameWarningCountLimit) {
2652+
Lib.warn('addFrames: This API call has yielded too many of these warnings. ' +
26522653
'For the rest of this call, further warnings about numeric frame ' +
26532654
'names will be suppressed.');
26542655
}
@@ -2683,10 +2684,10 @@ Plotly.addFrames = function(gd, frameList, indices) {
26832684
if(!frame.name) {
26842685
// Repeatedly assign a default name, incrementing the counter each time until
26852686
// we get a name that's not in the hashed lookup table:
2686-
while(_hash[(frame.name = 'frame ' + gd._transitionData._counter++)]);
2687+
while(_frameHash[(frame.name = 'frame ' + gd._transitionData._counter++)]);
26872688
}
26882689

2689-
if(_hash[frame.name]) {
2690+
if(_frameHash[frame.name]) {
26902691
// If frame is present, overwrite its definition:
26912692
for(j = 0; j < _frames.length; j++) {
26922693
if((_frames[j] || {}).name === frame.name) break;

src/plots/plots.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
17791779
plots.modifyFrames = function(gd, operations) {
17801780
var i, op, frame;
17811781
var _frames = gd._transitionData._frames;
1782-
var _hash = gd._transitionData._frameHash;
1782+
var _frameHash = gd._transitionData._frameHash;
17831783

17841784
for(i = 0; i < operations.length; i++) {
17851785
op = operations[i];
@@ -1788,32 +1788,32 @@ plots.modifyFrames = function(gd, operations) {
17881788
// No reason this couldn't exist, but is currently unused/untested:
17891789
/* case 'rename':
17901790
frame = _frames[op.index];
1791-
delete _hash[frame.name];
1792-
_hash[op.name] = frame;
1791+
delete _frameHash[frame.name];
1792+
_frameHash[op.name] = frame;
17931793
frame.name = op.name;
17941794
break;*/
17951795
case 'replace':
17961796
frame = op.value;
17971797
var oldName = (_frames[op.index] || {}).name;
17981798
var newName = frame.name;
1799-
_frames[op.index] = _hash[newName] = frame;
1799+
_frames[op.index] = _frameHash[newName] = frame;
18001800

18011801
if(newName !== oldName) {
18021802
// If name has changed in addition to replacement, then update
18031803
// the lookup table:
1804-
delete _hash[oldName];
1805-
_hash[newName] = frame;
1804+
delete _frameHash[oldName];
1805+
_frameHash[newName] = frame;
18061806
}
18071807

18081808
break;
18091809
case 'insert':
18101810
frame = op.value;
1811-
_hash[frame.name] = frame;
1811+
_frameHash[frame.name] = frame;
18121812
_frames.splice(op.index, 0, frame);
18131813
break;
18141814
case 'delete':
18151815
frame = _frames[op.index];
1816-
delete _hash[frame.name];
1816+
delete _frameHash[frame.name];
18171817
_frames.splice(op.index, 1);
18181818
break;
18191819
}

0 commit comments

Comments
 (0)