Skip to content

Commit f7033e4

Browse files
committed
flatten z 2d array in column major
1 parent 931ac5a commit f7033e4

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/traces/contourgl/convert.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ proto.update = function(fullTrace, calcTrace) {
8383
this.hoverinfo = fullTrace.hoverinfo;
8484

8585
// convert z from 2D -> 1D
86-
var z = calcPt.z;
87-
this.contourOptions.z = this.heatmapOptions.z = new Float32Array([].concat.apply([], z));
88-
89-
var rowLen = z[0].length,
86+
var z = calcPt.z,
87+
rowLen = z[0].length,
9088
colLen = z.length;
89+
90+
this.contourOptions.z = this.heatmapOptions.z = flattenZ(z);
9191
this.contourOptions.shape = this.heatmapOptions.shape = [rowLen, colLen];
9292

9393
this.contourOptions.x = this.heatmapOptions.x = calcPt.x;
@@ -109,6 +109,22 @@ proto.dispose = function() {
109109
this.heatmap.dispose();
110110
};
111111

112+
function flattenZ(zIn) {
113+
var Nx = zIn.length,
114+
Ny = zIn[0].length;
115+
116+
var zOut = new Float32Array(Nx * Ny);
117+
var pt = 0;
118+
119+
for(var i = 0; i < Nx; i++) {
120+
for(var j = 0; j < Ny; j++) {
121+
zOut[pt++] = zIn[j][i];
122+
}
123+
}
124+
125+
return zOut;
126+
}
127+
112128
function convertColorscale(fullTrace) {
113129
var contours = fullTrace.contours,
114130
start = contours.start,

0 commit comments

Comments
 (0)