Skip to content
1 change: 1 addition & 0 deletions devtools/test_dashboard/test_gl3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ plots['scatter3d-colorscale'] = require('@mocks/gl3d_scatter3d-colorscale.json')
plots['autocolorscale'] = require('@mocks/gl3d_autocolorscale.json');
plots['nan-holes'] = require('@mocks/gl3d_nan-holes.json');
plots['tetrahedra'] = require('@mocks/gl3d_tet.json');
plots['surface-intensity'] = require('@mocks/gl3d_surface_intensity.json');

plotButtons(plots, figDir);
7 changes: 7 additions & 0 deletions src/traces/surface/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ module.exports = {
valType: 'data_array',
description: 'Sets the text elements associated with each z value.'
},
intensity: {
valType: 'data_array',
description: [
'Sets the surface intensity values,',
'used for setting a color scale independent of z'
].join(' ')
},
zauto: colorscaleAttrs.zauto,
zmin: colorscaleAttrs.zmin,
zmax: colorscaleAttrs.zmax,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, a couple things will need to happen here:

  • rename intensity -> surfacecolor
  • add cauto, cmin and cmax (which will take up the role of zauto, zmin and zmax respectively)
  • move zauto, zmin and zmax to the bottom of the attribute object in a _deprecated block (see example here)
  • add a backward-compatible block in cleanData:
if(trace.type === 'surface') {
  if(trace.zauto) trace.cauto = trace.zauto; 
  delete trace.zauto

  /* and so on for 'zmin' and 'zmax'
}

Expand Down
6 changes: 5 additions & 1 deletion src/traces/surface/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ var colorscaleCalc = require('../../components/colorscale/calc');

// Compute auto-z and autocolorscale if applicable
module.exports = function calc(gd, trace) {
colorscaleCalc(trace, trace.z, '', 'z');
if(trace.intensity) {
colorscaleCalc(trace, trace.intensity, '', 'intensity');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be:

colorscaleCalc(trace, trace.surfacecolor, '', 'c');

} else {
colorscaleCalc(trace, trace.z, '', 'z');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this

colorscaleCalc(trace, trace.z, '', 'c');

}
};
32 changes: 25 additions & 7 deletions src/traces/surface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var str2RgbaArray = require('../../lib/str2rgbarray');

var MIN_RESOLUTION = 128;


function SurfaceTrace(scene, surface, uid) {
this.scene = scene;
this.uid = uid;
Expand Down Expand Up @@ -136,7 +135,7 @@ function refine(coords) {
Math.floor((coords[0].shape[1]) * scaleF+1)|0 ];
var nsize = nshape[0] * nshape[1];

for(var i = 0; i < 3; ++i) {
for(var i = 0; i < coords.length; ++i) {
var padImg = padField(coords[i]);
var scaledImg = ndarray(new Float32Array(nsize), nshape);
homography(scaledImg, padImg, [scaleF, 0, 0,
Expand Down Expand Up @@ -230,9 +229,6 @@ proto.update = function(data) {
});
}

//Refine if necessary
this.dataScale = refine(coords);

var params = {
colormap: colormap,
levels: [[], [], []],
Expand All @@ -249,10 +245,30 @@ proto.update = function(data) {
dynamicColor: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],
dynamicWidth: [1, 1, 1],
dynamicTint: [1, 1, 1],
opacity: 1,
colorBounds: [data.zmin * scaleFactor[2], data.zmax * scaleFactor[2]]
opacity: 1
// TODO: Need to think about how to calculate this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calcColorscale, which gets called before the convert step, will take care of this.

/*
intensityBounds: [
data.zmin * scaleFactor[2],
data.zmax * scaleFactor[2]]
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intensityBounds: [
  data.cmin * scaleFactor[2],
  data.cmax * scaleFactor[2]
];

should do the trick.

};

//Refine if necessary
if('intensity' in data) {
var intensity = ndarray(
new Float32Array(xlen * ylen), [xlen, ylen]);
fill(intensity, function(row, col) {
return data.intensity[col][row];
});
coords.push(intensity);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to preserve backward compatibility, we'll need to set the intensity field to data.z when data.surfacecolor is not set, before passing it to gl-surface3d.


this.dataScale = refine(coords);

if('intensity' in data) {
params.intensity = coords.pop();
}

if('opacity' in data) {
if(data.opacity < 1) {
Expand Down Expand Up @@ -300,6 +316,8 @@ proto.update = function(data) {
}

params.coords = coords;


surface.update(params);

surface.highlightEnable = highlightEnable;
Expand Down
2 changes: 2 additions & 0 deletions src/traces/surface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('hidesurface');
coerce('opacity');

coerce('intensity');

coerce('colorscale');

var dims = ['x', 'y', 'z'];
Expand Down
254 changes: 254 additions & 0 deletions test/image/mocks/gl3d_surface_intensity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
{
"data": [
{
"z": [
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
],
[
0.955336489125606,
0.955336489125606,
0.955336489125606,
0.955336489125606,
0.955336489125606,
0.955336489125606,
0.955336489125606,
0.955336489125606,
0.955336489125606,
0.955336489125606
],
[
0.8253356149096783,
0.8253356149096783,
0.8253356149096783,
0.8253356149096783,
0.8253356149096783,
0.8253356149096783,
0.8253356149096783,
0.8253356149096783,
0.8253356149096783,
0.8253356149096783
],
[
0.6216099682706645,
0.6216099682706645,
0.6216099682706645,
0.6216099682706645,
0.6216099682706645,
0.6216099682706645,
0.6216099682706645,
0.6216099682706645,
0.6216099682706645,
0.6216099682706645
],
[
0.3623577544766736,
0.3623577544766736,
0.3623577544766736,
0.3623577544766736,
0.3623577544766736,
0.3623577544766736,
0.3623577544766736,
0.3623577544766736,
0.3623577544766736,
0.3623577544766736
],
[
0.0707372016677029,
0.0707372016677029,
0.0707372016677029,
0.0707372016677029,
0.0707372016677029,
0.0707372016677029,
0.0707372016677029,
0.0707372016677029,
0.0707372016677029,
0.0707372016677029
],
[
-0.2272020946930869,
-0.2272020946930869,
-0.2272020946930869,
-0.2272020946930869,
-0.2272020946930869,
-0.2272020946930869,
-0.2272020946930869,
-0.2272020946930869,
-0.2272020946930869,
-0.2272020946930869
],
[
-0.5048461045998576,
-0.5048461045998576,
-0.5048461045998576,
-0.5048461045998576,
-0.5048461045998576,
-0.5048461045998576,
-0.5048461045998576,
-0.5048461045998576,
-0.5048461045998576,
-0.5048461045998576
],
[
-0.7373937155412454,
-0.7373937155412454,
-0.7373937155412454,
-0.7373937155412454,
-0.7373937155412454,
-0.7373937155412454,
-0.7373937155412454,
-0.7373937155412454,
-0.7373937155412454,
-0.7373937155412454
],
[
-0.904072142017061,
-0.904072142017061,
-0.904072142017061,
-0.904072142017061,
-0.904072142017061,
-0.904072142017061,
-0.904072142017061,
-0.904072142017061,
-0.904072142017061,
-0.904072142017061
]
],
"intensity": [
[
10,
9,
8,
7,
6,
5,
6,
7,
8,
9
],
[
9,
8,
7,
6,
5,
4,
5,
6,
7,
8
],
[
8,
7,
6,
5,
4,
3,
4,
5,
6,
7
],
[
7,
6,
5,
4,
3,
2,
3,
4,
5,
6
],
[
6,
5,
4,
3,
2,
1,
2,
3,
4,
5
],
[
5,
4,
3,
2,
1,
0,
1,
2,
3,
4
],
[
6,
5,
4,
3,
2,
1,
2,
3,
4,
5
],
[
7,
6,
5,
4,
3,
2,
3,
4,
5,
6
],
[
8,
7,
6,
5,
4,
3,
4,
5,
6,
7
],
[
9,
8,
7,
6,
5,
4,
5,
6,
7,
8
]
],
"type": "surface"
}
],
"layout": {
"title": "Surface intensity test"
}
}