Skip to content

Commit 52a1f9b

Browse files
committed
Fix non-square DataTexture
DataTexture seems to insist on column-major data. As arrays are always row-major (C-order) when serialized, we switch width/height on JS side. Some examples also need updating in order to highlight this, and to stay intuitive with respect to variable names. Also regenerates modified example.
1 parent 210329a commit 52a1f9b

File tree

3 files changed

+39
-53
lines changed

3 files changed

+39
-53
lines changed

examples/Examples.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"# Generate surface data:\n",
8282
"view_width = 600\n",
8383
"view_height = 400\n",
84-
"nx, ny = (20, 20)\n",
84+
"nx, ny = (24, 20)\n",
8585
"xmax=1\n",
8686
"x = np.linspace(-xmax, xmax, nx)\n",
8787
"y = np.linspace(-xmax, xmax, ny)\n",
@@ -91,14 +91,14 @@
9191
"\n",
9292
"\n",
9393
"# Generate scene objects from data:\n",
94-
"surf_g = SurfaceGeometry(z=list(z[::-1].flat), \n",
94+
"surf_g = SurfaceGeometry(z=list(z.flat), \n",
9595
" width=2 * xmax,\n",
9696
" height=2 * xmax,\n",
9797
" width_segments=nx - 1,\n",
9898
" height_segments=ny - 1)\n",
9999
"\n",
100100
"surf = Mesh(geometry=surf_g,\n",
101-
" material=MeshLambertMaterial(map=height_texture(z[::-1], 'YlGnBu_r')))\n",
101+
" material=MeshLambertMaterial(map=height_texture(z, 'YlGnBu_r')))\n",
102102
"\n",
103103
"surfgrid = SurfaceGrid(geometry=surf_g, material=LineBasicMaterial(color='black'),\n",
104104
" position=[0, 0, 1e-2]) # Avoid overlap by lifting grid slightly\n",
@@ -155,8 +155,8 @@
155155
"metadata": {},
156156
"outputs": [],
157157
"source": [
158-
"surf_g.z = list((-z[::-1]).flat)\n",
159-
"surf.material.map = height_texture(-z[::-1])"
158+
"surf_g.z = list((-z).flat)\n",
159+
"surf.material.map = height_texture(-z)"
160160
]
161161
},
162162
{

examples/Textures.ipynb

+29-45
Large diffs are not rendered by default.

js/src/textures/DataTexture.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ var DataTextureModel = DataTextureBase.extend({
2222
}
2323
var data = this.convertArrayBufferModelToThree(rawData, 'data');
2424

25+
// ipydatawidgets uses row-major storage, so "flip" axes dims here:
2526
return {
2627
data: data,
27-
width: rawData.shape[0],
28-
height: rawData.shape[1],
28+
width: rawData.shape[1],
29+
height: rawData.shape[0],
2930
};
3031
},
3132

@@ -75,9 +76,10 @@ var DataTextureModel = DataTextureBase.extend({
7576
var rawData = dataserializers.getArray(modelNDArray);
7677
rawData.data.set(imageRecord.data);
7778
} else {
79+
// ipydatawidgets uses row-major storage, so "flip" axes dims here:
7880
this.set('data', ndarray(
7981
imageRecord.data,
80-
[imageRecord.width, imageRecord.height]
82+
[imageRecord.height, imageRecord.width]
8183
));
8284
}
8385
},

0 commit comments

Comments
 (0)