Skip to content

Commit bddd218

Browse files
committed
change Lib.randstr warning to a throw error
1 parent f4555cf commit bddd218

File tree

9 files changed

+12
-13
lines changed

9 files changed

+12
-13
lines changed

src/lib/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ lib.simpleMap = function(array, func, x1, x2, opts) {
274274
* @param {int} base
275275
* base of string representation, default 16. Should be a power of 2.
276276
*/
277-
lib.randstr = function randstr(gd, existing, bits, base, _recursion) {
277+
lib.randstr = function randstr(existing, bits, base, _recursion) {
278278
if(!base) base = 16;
279279
if(bits === undefined) bits = 24;
280280
if(bits <= 0) return '0';
@@ -304,10 +304,9 @@ lib.randstr = function randstr(gd, existing, bits, base, _recursion) {
304304
if((existing && existing[res]) ||
305305
(parsed !== Infinity && parsed >= Math.pow(2, bits))) {
306306
if(_recursion > 10) {
307-
lib.warn(gd, 'randstr failed uniqueness');
308-
return res;
307+
throw new Error('randstr failed uniqueness');
309308
}
310-
return randstr(gd, existing, bits, base, (_recursion || 0) + 1);
309+
return randstr(existing, bits, base, (_recursion || 0) + 1);
311310
} else return res;
312311
};
313312

src/lib/svg_text_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function texToSVG(gd, _texString, _config, _callback) {
191191
}
192192
},
193193
function() {
194-
var randomID = 'math-output-' + Lib.randstr(gd, {}, 64);
194+
var randomID = 'math-output-' + Lib.randstr({}, 64);
195195
tmpDiv = d3.select('body').append('div')
196196
.attr({id: randomID})
197197
.style({visibility: 'hidden', position: 'absolute'})

src/plot_api/plot_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3757,7 +3757,7 @@ function makePlotFramework(gd) {
37573757
d3.selectAll('defs').each(function() {
37583758
if(this.id) otherUids[this.id.split('-')[1]] = 1;
37593759
});
3760-
fullLayout._uid = Lib.randstr(gd, otherUids);
3760+
fullLayout._uid = Lib.randstr(otherUids);
37613761
}
37623762

37633763
fullLayout._paperdiv.selectAll('.main-svg')

src/plot_api/to_image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function toImage(gd, opts) {
200200
}
201201

202202
var canvas = document.createElement('canvas');
203-
canvas.id = Lib.randstr(gd);
203+
canvas.id = Lib.randstr();
204204

205205
svgToImg({
206206
format: format,

src/plots/plots.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ function getTraceUids(gd, oldFullData, newData) {
605605

606606
if(tryUid(newUid, i)) continue;
607607
if(i < oldLen && tryUid(oldFullInput[i].uid, i)) continue;
608-
setUid(Lib.randstr(gd, seenUids), i);
608+
setUid(Lib.randstr(seenUids), i);
609609
}
610610

611611
return out;

src/snapshot/toimage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function toImage(gd, opts) {
4242
var svg = toSVG(clonedGd);
4343

4444
var canvas = document.createElement('canvas');
45-
canvas.id = Lib.randstr(gd);
45+
canvas.id = Lib.randstr();
4646

4747
ev = svgToImg({
4848
format: opts.format,

src/traces/sankey/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function sankeyModel(gd, layout, d, traceIndex) {
261261
circular: circular,
262262
key: traceIndex,
263263
trace: trace,
264-
guid: Lib.randstr(gd),
264+
guid: Lib.randstr(),
265265
horizontal: horizontal,
266266
width: width,
267267
height: height,
@@ -477,7 +477,7 @@ function nodeModel(gd, d, n) {
477477
var key = 'node_' + n.pointNumber;
478478
// If it's a group, it's mutable and should be unique
479479
if(n.group) {
480-
key = Lib.randstr(gd);
480+
key = Lib.randstr();
481481
}
482482

483483
// for event data

src/traces/sunburst/calc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ exports.calc = function(gd, trace) {
114114
return Lib.warn(gd, 'Multiple implied roots, cannot build ' + trace.type + ' hierarchy.');
115115
}
116116
} else if(parent2children[''].length > 1) {
117-
var dummyId = Lib.randstr(gd);
117+
var dummyId = Lib.randstr();
118118

119119
// if multiple rows linked to the root node,
120120
// add dummy "root of roots" node to make d3 build the hierarchy successfully

test/jasmine/tests/transform_groupby_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function supplyDataDefaults(gd, dataIn, dataOut) {
1717
_modules: [],
1818
_visibleModules: [],
1919
_basePlotModules: [],
20-
_traceUids: dataIn.map(function() { return Lib.randstr(gd); })
20+
_traceUids: dataIn.map(function() { return Lib.randstr(); })
2121
});
2222
}
2323

0 commit comments

Comments
 (0)