Skip to content

Commit 00109fd

Browse files
committed
Add surface intensity parameter
1 parent dd15479 commit 00109fd

File tree

6 files changed

+294
-8
lines changed

6 files changed

+294
-8
lines changed

devtools/test_dashboard/test_gl3d.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ plots['scatter3d-colorscale'] = require('@mocks/gl3d_scatter3d-colorscale.json')
3636
plots['autocolorscale'] = require('@mocks/gl3d_autocolorscale.json');
3737
plots['nan-holes'] = require('@mocks/gl3d_nan-holes.json');
3838
plots['tetrahedra'] = require('@mocks/gl3d_tet.json');
39+
plots['surface-intensity'] = require('@mocks/gl3d_surface_intensity.json');
3940

4041
plotButtons(plots, figDir);

src/traces/surface/attributes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ module.exports = {
9595
valType: 'data_array',
9696
description: 'Sets the text elements associated with each z value.'
9797
},
98+
intensity: {
99+
valType: 'data_array',
100+
description: [
101+
'Sets the surface intensity values,',
102+
'used for setting a color scale independent of z'
103+
].join(' ')
104+
},
98105
zauto: colorscaleAttrs.zauto,
99106
zmin: colorscaleAttrs.zmin,
100107
zmax: colorscaleAttrs.zmax,

src/traces/surface/calc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ var colorscaleCalc = require('../../components/colorscale/calc');
1414

1515
// Compute auto-z and autocolorscale if applicable
1616
module.exports = function calc(gd, trace) {
17-
colorscaleCalc(trace, trace.z, '', 'z');
17+
if(trace.intensity) {
18+
colorscaleCalc(trace, trace.intensity, '', 'intensity');
19+
} else {
20+
colorscaleCalc(trace, trace.z, '', 'z');
21+
}
1822
};

src/traces/surface/convert.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var str2RgbaArray = require('../../lib/str2rgbarray');
2020

2121
var MIN_RESOLUTION = 128;
2222

23-
2423
function SurfaceTrace(scene, surface, uid) {
2524
this.scene = scene;
2625
this.uid = uid;
@@ -136,7 +135,7 @@ function refine(coords) {
136135
Math.floor((coords[0].shape[1]) * scaleF+1)|0 ];
137136
var nsize = nshape[0] * nshape[1];
138137

139-
for(var i = 0; i < 3; ++i) {
138+
for(var i = 0; i < coords.length; ++i) {
140139
var padImg = padField(coords[i]);
141140
var scaledImg = ndarray(new Float32Array(nsize), nshape);
142141
homography(scaledImg, padImg, [scaleF, 0, 0,
@@ -230,9 +229,6 @@ proto.update = function(data) {
230229
});
231230
}
232231

233-
//Refine if necessary
234-
this.dataScale = refine(coords);
235-
236232
var params = {
237233
colormap: colormap,
238234
levels: [[], [], []],
@@ -249,10 +245,30 @@ proto.update = function(data) {
249245
dynamicColor: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],
250246
dynamicWidth: [1, 1, 1],
251247
dynamicTint: [1, 1, 1],
252-
opacity: 1,
253-
colorBounds: [data.zmin * scaleFactor[2], data.zmax * scaleFactor[2]]
248+
opacity: 1
249+
// TODO: Need to think about how to calculate this
250+
/*
251+
intensityBounds: [
252+
data.zmin * scaleFactor[2],
253+
data.zmax * scaleFactor[2]]
254+
*/
254255
};
255256

257+
//Refine if necessary
258+
if('intensity' in data) {
259+
var intensity = ndarray(
260+
new Float32Array(xlen * ylen), [xlen, ylen]);
261+
fill(intensity, function(row, col) {
262+
return data.intensity[col][row];
263+
});
264+
coords.push(intensity);
265+
}
266+
267+
this.dataScale = refine(coords);
268+
269+
if('intensity' in data) {
270+
params.intensity = coords.pop();
271+
}
256272

257273
if('opacity' in data) {
258274
if(data.opacity < 1) {
@@ -300,6 +316,8 @@ proto.update = function(data) {
300316
}
301317

302318
params.coords = coords;
319+
320+
303321
surface.update(params);
304322

305323
surface.highlightEnable = highlightEnable;

src/traces/surface/defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5858
coerce('hidesurface');
5959
coerce('opacity');
6060

61+
coerce('intensity');
62+
6163
coerce('colorscale');
6264

6365
var dims = ['x', 'y', 'z'];
Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
{
2+
"data": [
3+
{
4+
"z": [
5+
[
6+
1,
7+
1,
8+
1,
9+
1,
10+
1,
11+
1,
12+
1,
13+
1,
14+
1,
15+
1
16+
],
17+
[
18+
0.955336489125606,
19+
0.955336489125606,
20+
0.955336489125606,
21+
0.955336489125606,
22+
0.955336489125606,
23+
0.955336489125606,
24+
0.955336489125606,
25+
0.955336489125606,
26+
0.955336489125606,
27+
0.955336489125606
28+
],
29+
[
30+
0.8253356149096783,
31+
0.8253356149096783,
32+
0.8253356149096783,
33+
0.8253356149096783,
34+
0.8253356149096783,
35+
0.8253356149096783,
36+
0.8253356149096783,
37+
0.8253356149096783,
38+
0.8253356149096783,
39+
0.8253356149096783
40+
],
41+
[
42+
0.6216099682706645,
43+
0.6216099682706645,
44+
0.6216099682706645,
45+
0.6216099682706645,
46+
0.6216099682706645,
47+
0.6216099682706645,
48+
0.6216099682706645,
49+
0.6216099682706645,
50+
0.6216099682706645,
51+
0.6216099682706645
52+
],
53+
[
54+
0.3623577544766736,
55+
0.3623577544766736,
56+
0.3623577544766736,
57+
0.3623577544766736,
58+
0.3623577544766736,
59+
0.3623577544766736,
60+
0.3623577544766736,
61+
0.3623577544766736,
62+
0.3623577544766736,
63+
0.3623577544766736
64+
],
65+
[
66+
0.0707372016677029,
67+
0.0707372016677029,
68+
0.0707372016677029,
69+
0.0707372016677029,
70+
0.0707372016677029,
71+
0.0707372016677029,
72+
0.0707372016677029,
73+
0.0707372016677029,
74+
0.0707372016677029,
75+
0.0707372016677029
76+
],
77+
[
78+
-0.2272020946930869,
79+
-0.2272020946930869,
80+
-0.2272020946930869,
81+
-0.2272020946930869,
82+
-0.2272020946930869,
83+
-0.2272020946930869,
84+
-0.2272020946930869,
85+
-0.2272020946930869,
86+
-0.2272020946930869,
87+
-0.2272020946930869
88+
],
89+
[
90+
-0.5048461045998576,
91+
-0.5048461045998576,
92+
-0.5048461045998576,
93+
-0.5048461045998576,
94+
-0.5048461045998576,
95+
-0.5048461045998576,
96+
-0.5048461045998576,
97+
-0.5048461045998576,
98+
-0.5048461045998576,
99+
-0.5048461045998576
100+
],
101+
[
102+
-0.7373937155412454,
103+
-0.7373937155412454,
104+
-0.7373937155412454,
105+
-0.7373937155412454,
106+
-0.7373937155412454,
107+
-0.7373937155412454,
108+
-0.7373937155412454,
109+
-0.7373937155412454,
110+
-0.7373937155412454,
111+
-0.7373937155412454
112+
],
113+
[
114+
-0.904072142017061,
115+
-0.904072142017061,
116+
-0.904072142017061,
117+
-0.904072142017061,
118+
-0.904072142017061,
119+
-0.904072142017061,
120+
-0.904072142017061,
121+
-0.904072142017061,
122+
-0.904072142017061,
123+
-0.904072142017061
124+
]
125+
],
126+
"intensity": [
127+
[
128+
10,
129+
9,
130+
8,
131+
7,
132+
6,
133+
5,
134+
6,
135+
7,
136+
8,
137+
9
138+
],
139+
[
140+
9,
141+
8,
142+
7,
143+
6,
144+
5,
145+
4,
146+
5,
147+
6,
148+
7,
149+
8
150+
],
151+
[
152+
8,
153+
7,
154+
6,
155+
5,
156+
4,
157+
3,
158+
4,
159+
5,
160+
6,
161+
7
162+
],
163+
[
164+
7,
165+
6,
166+
5,
167+
4,
168+
3,
169+
2,
170+
3,
171+
4,
172+
5,
173+
6
174+
],
175+
[
176+
6,
177+
5,
178+
4,
179+
3,
180+
2,
181+
1,
182+
2,
183+
3,
184+
4,
185+
5
186+
],
187+
[
188+
5,
189+
4,
190+
3,
191+
2,
192+
1,
193+
0,
194+
1,
195+
2,
196+
3,
197+
4
198+
],
199+
[
200+
6,
201+
5,
202+
4,
203+
3,
204+
2,
205+
1,
206+
2,
207+
3,
208+
4,
209+
5
210+
],
211+
[
212+
7,
213+
6,
214+
5,
215+
4,
216+
3,
217+
2,
218+
3,
219+
4,
220+
5,
221+
6
222+
],
223+
[
224+
8,
225+
7,
226+
6,
227+
5,
228+
4,
229+
3,
230+
4,
231+
5,
232+
6,
233+
7
234+
],
235+
[
236+
9,
237+
8,
238+
7,
239+
6,
240+
5,
241+
4,
242+
5,
243+
6,
244+
7,
245+
8
246+
]
247+
],
248+
"type": "surface"
249+
}
250+
],
251+
"layout": {
252+
"title": "Surface intensity test"
253+
}
254+
}

0 commit comments

Comments
 (0)