Skip to content

Commit 09924a6

Browse files
committed
minor: stop emitting warnings after having reached a count
1 parent 18dac1f commit 09924a6

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
@@ -2592,7 +2592,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
25922592
* - traces {array} trace indices
25932593
* - baseframe {string} name of frame from which this frame gets defaults
25942594
*
2595-
* @param {array of integers) indices
2595+
* @param {array of integers} indices
25962596
* an array of integer indices matching the respective frames in `frameList`. If not
25972597
* provided, an index will be provided in serial order. If already used, the frame
25982598
* will be overwritten.
@@ -2601,6 +2601,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
26012601
gd = Lib.getGraphDiv(gd);
26022602

26032603
var numericNameWarningCount = 0;
2604+
var numericNameWarningCountLimit = 5;
26042605

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

26172618
var i, frame, j, idx;
26182619
var _frames = gd._transitionData._frames;
2619-
var _hash = gd._transitionData._frameHash;
2620+
var _frameHash = gd._transitionData._frameHash;
26202621

26212622

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

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

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

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

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

2688-
if(_hash[frame.name]) {
2689+
if(_frameHash[frame.name]) {
26892690
// If frame is present, overwrite its definition:
26902691
for(j = 0; j < _frames.length; j++) {
26912692
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)