-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathclean_2d_array.js
53 lines (44 loc) · 1.51 KB
/
clean_2d_array.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var isNumeric = require('fast-isnumeric');
module.exports = function clean2dArray(zOld, transpose, trace, xa, ya) {
var rowlen, collen, getCollen, old2new, i, j;
function cleanZvalue(v) {
if(!isNumeric(v)) return undefined;
return +v;
}
if(transpose) {
rowlen = 0;
for(i = 0; i < zOld.length; i++) rowlen = Math.max(rowlen, zOld[i].length);
if(rowlen === 0) return false;
getCollen = function(zOld) { return zOld.length; };
old2new = function(zOld, i, j) { return zOld[j][i]; };
} else {
rowlen = zOld.length;
getCollen = function(zOld, i) { return zOld[i].length; };
old2new = function(zOld, i, j) { return zOld[i][j]; };
}
var xMap = function(i) {return i;};
var yMap = function(i) {return i;};
if(trace && trace.type === 'heatmap') {
if(ya && ya.type === 'category') {
yMap = function(i) {return trace._y[i];};
}
if(xa && xa.type === 'category') {
xMap = function(i) {return trace._x[i];};
}
}
var zNew = new Array(rowlen);
for(i = 0; i < rowlen; i++) {
collen = getCollen(zOld, i);
zNew[i] = new Array(collen);
for(j = 0; j < collen; j++) zNew[i][j] = cleanZvalue(old2new(zOld, yMap(i), xMap(j)));
}
return zNew;
};