Skip to content

Commit c0e2f73

Browse files
committed
a few more Array.isArray -> Lib.isArrayOrTypedArray
1 parent d98dcc0 commit c0e2f73

File tree

9 files changed

+27
-28
lines changed

9 files changed

+27
-28
lines changed

src/components/colorscale/has_colorscale.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var isNumeric = require('fast-isnumeric');
13-
1412
var Lib = require('../../lib');
15-
1613
var isValidScale = require('./is_valid_scale');
1714

18-
1915
module.exports = function hasColorscale(trace, containerStr) {
2016
var container = containerStr ?
2117
Lib.nestedProperty(trace, containerStr).get() || {} :
2218
trace,
2319
color = container.color,
2420
isArrayWithOneNumber = false;
2521

26-
if(Array.isArray(color)) {
22+
if(Lib.isTypedArray(color)) {
23+
isArrayWithOneNumber = true;
24+
} else if(Array.isArray(color)) {
2725
for(var i = 0; i < color.length; i++) {
2826
if(isNumeric(color[i])) {
2927
isArrayWithOneNumber = true;

src/components/drawing/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerL
316316

317317
if('mlc' in d) lineColor = d.mlcc = lineScale(d.mlc);
318318
// weird case: array wasn't long enough to apply to every point
319-
else if(Array.isArray(markerLine.color)) lineColor = Color.defaultLine;
319+
else if(Lib.isArrayOrTypedArray(markerLine.color)) lineColor = Color.defaultLine;
320320
else lineColor = markerLine.color;
321321

322-
if(Array.isArray(marker.color)) {
322+
if(Lib.isArrayOrTypedArray(marker.color)) {
323323
fillColor = Color.defaultLine;
324324
perPointGradient = true;
325325
}
@@ -542,7 +542,7 @@ drawing.tryColorscale = function(marker, prefix) {
542542
scl = cont.colorscale,
543543
colorArray = cont.color;
544544

545-
if(scl && Array.isArray(colorArray)) {
545+
if(scl && Lib.isArrayOrTypedArray(colorArray)) {
546546
return Colorscale.makeColorScaleFunc(
547547
Colorscale.extractScale(scl, cont.cmin, cont.cmax)
548548
);

src/lib/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ lib.castOption = function(trace, ptNumber, astr, fn) {
433433
var val = lib.nestedProperty(trace, astr).get();
434434

435435
if(lib.isArrayOrTypedArray(val)) {
436-
// TODO what to do with 2d arrays?
437-
if(Array.isArray(ptNumber) && Array.isArray(val[ptNumber[0]])) {
436+
if(Array.isArray(ptNumber) && lib.isArrayOrTypedArray(val[ptNumber[0]])) {
438437
return fn(val[ptNumber[0]][ptNumber[1]]);
439438
} else {
440439
return fn(val[ptNumber]);

src/lib/stats.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'use strict';
1111

1212
var isNumeric = require('fast-isnumeric');
13-
13+
var isArrayOrTypedArray = require('./is_array').isArrayOrTypedArray;
1414

1515
/**
1616
* aggNums() returns the result of an aggregate function applied to an array of
@@ -30,7 +30,7 @@ exports.aggNums = function(f, v, a, len) {
3030
b;
3131
if(!len) len = a.length;
3232
if(!isNumeric(v)) v = false;
33-
if(Array.isArray(a[0])) {
33+
if(isArrayOrTypedArray(a[0])) {
3434
b = new Array(len);
3535
for(i = 0; i < len; i++) b[i] = exports.aggNums(f, v, a[i]);
3636
a = b;

src/traces/heatmap/has_columns.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

11+
var Lib = require('../../lib');
12+
1213
module.exports = function(trace) {
13-
return !Array.isArray(trace.z[0]);
14+
return !Lib.isArrayOrTypedArray(trace.z[0]);
1415
};

src/traces/heatmap/make_bound_array.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
'use strict';
1010

11+
var Lib = require('../../lib');
1112
var Registry = require('../../registry');
1213

1314
module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) {
@@ -19,7 +20,7 @@ module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks,
1920
dv,
2021
i;
2122

22-
var isArrayOfTwoItemsOrMore = Array.isArray(arrayIn) && arrayIn.length > 1;
23+
var isArrayOfTwoItemsOrMore = Lib.isArrayOrTypedArray(arrayIn) && arrayIn.length > 1;
2324

2425
if(isArrayOfTwoItemsOrMore && !isHist && (ax.type !== 'category')) {
2526
var len = arrayIn.length;
@@ -67,7 +68,7 @@ module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks,
6768
var calendar = trace[ax._id.charAt(0) + 'calendar'];
6869

6970
if(isHist || ax.type === 'category') v0 = ax.r2c(v0In, 0, calendar) || 0;
70-
else if(Array.isArray(arrayIn) && arrayIn.length === 1) v0 = arrayIn[0];
71+
else if(Lib.isArrayOrTypedArray(arrayIn) && arrayIn.length === 1) v0 = arrayIn[0];
7172
else if(v0In === undefined) v0 = 0;
7273
else v0 = ax.d2c(v0In, 0, calendar);
7374

src/traces/heatmap/xyz_defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
var isNumeric = require('fast-isnumeric');
1313

14+
var Lib = require('../../lib');
1415
var Registry = require('../../registry');
1516
var hasColumns = require('./has_columns');
1617

17-
1818
module.exports = function handleXYZDefaults(traceIn, traceOut, coerce, layout, xName, yName) {
1919
var z = coerce('z');
2020
xName = xName || 'x';
@@ -76,7 +76,7 @@ function isValidZ(z) {
7676

7777
for(var i = 0; i < z.length; i++) {
7878
zi = z[i];
79-
if(!Array.isArray(zi)) {
79+
if(!Lib.isArrayOrTypedArray(zi)) {
8080
allRowsAreArrays = false;
8181
break;
8282
}

src/traces/surface/convert.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var fill = require('ndarray-fill');
1616
var ops = require('ndarray-ops');
1717
var tinycolor = require('tinycolor2');
1818

19+
var Lib = require('../../lib');
1920
var str2RgbaArray = require('../../lib/str2rgbarray');
2021

2122
var MIN_RESOLUTION = 128;
@@ -45,17 +46,17 @@ proto.handlePick = function(selection) {
4546
];
4647
var traceCoordinate = [0, 0, 0];
4748

48-
if(!Array.isArray(this.data.x)) {
49+
if(!Lib.isArrayOrTypedArray(this.data.x)) {
4950
traceCoordinate[0] = selectIndex[0];
50-
} else if(Array.isArray(this.data.x[0])) {
51+
} else if(Lib.isArrayOrTypedArray(this.data.x[0])) {
5152
traceCoordinate[0] = this.data.x[selectIndex[1]][selectIndex[0]];
5253
} else {
5354
traceCoordinate[0] = this.data.x[selectIndex[0]];
5455
}
5556

56-
if(!Array.isArray(this.data.y)) {
57+
if(!Lib.isArrayOrTypedArray(this.data.y)) {
5758
traceCoordinate[1] = selectIndex[1];
58-
} else if(Array.isArray(this.data.y[0])) {
59+
} else if(Lib.isArrayOrTypedArray(this.data.y[0])) {
5960
traceCoordinate[1] = this.data.y[selectIndex[1]][selectIndex[0]];
6061
} else {
6162
traceCoordinate[1] = this.data.y[selectIndex[1]];
@@ -231,11 +232,11 @@ proto.update = function(data) {
231232
});
232233

233234
// coords x
234-
if(!Array.isArray(x)) {
235+
if(!Lib.isArrayOrTypedArray(x)) {
235236
fill(xc, function(row) {
236237
return xaxis.d2l(row, 0, xcalendar) * scaleFactor[0];
237238
});
238-
} else if(Array.isArray(x[0])) {
239+
} else if(Lib.isArrayOrTypedArray(x[0])) {
239240
fill(xc, function(row, col) {
240241
return xaxis.d2l(x[col][row], 0, xcalendar) * scaleFactor[0];
241242
});
@@ -247,11 +248,11 @@ proto.update = function(data) {
247248
}
248249

249250
// coords y
250-
if(!Array.isArray(x)) {
251+
if(!Lib.isArrayOrTypedArray(x)) {
251252
fill(yc, function(row, col) {
252253
return yaxis.d2l(col, 0, xcalendar) * scaleFactor[1];
253254
});
254-
} else if(Array.isArray(y[0])) {
255+
} else if(Lib.isArrayOrTypedArray(y[0])) {
255256
fill(yc, function(row, col) {
256257
return yaxis.d2l(y[col][row], 0, ycalendar) * scaleFactor[1];
257258
});

src/traces/surface/defaults.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3232
var x = coerce('x');
3333
coerce('y');
3434

35-
// TODO
36-
traceOut._xlength = (Array.isArray(x) && Array.isArray(x[0])) ? z.length : z[0].length;
35+
traceOut._xlength = (Array.isArray(x) && Lib.isArrayOrTypedArray(x[0])) ? z.length : z[0].length;
3736
traceOut._ylength = z.length;
3837

3938
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');

0 commit comments

Comments
 (0)