Skip to content

Commit f1c0e31

Browse files
committed
add early return for empty arrays to test category case and a bit of refactor
1 parent fb67c82 commit f1c0e31

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/plots/cartesian/axis_autotype.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ function moreDates(a, calendar) {
6969
// are the (x,y)-values in gd.data mostly text?
7070
// require twice as many DISTINCT categories as distinct numbers
7171
function category(a) {
72+
var len = a.length;
73+
if(!len) return false;
74+
7275
// test at most 1000 points
73-
var inc = Math.max(1, (a.length - 1) / 1000);
76+
var inc = Math.max(1, (len - 1) / 1000);
7477
var curvenums = 0;
7578
var curvecats = 0;
7679
var seen = {};
7780

78-
for(var i = 0; i < a.length; i += inc) {
79-
var ai = a[Math.round(i)];
81+
for(var f = 0; f < len; f += inc) {
82+
var i = Math.round(f);
83+
var ai = a[i];
8084
var stri = String(ai);
8185
if(seen[stri]) continue;
8286
seen[stri] = 1;

0 commit comments

Comments
 (0)