Skip to content

Isosurface traces #2752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Plotly.register([
require('./mesh3d'),
require('./cone'),
require('./streamtube'),
require('./isosurface'),

require('./scattergeo'),
require('./choropleth'),
Expand Down
11 changes: 11 additions & 0 deletions lib/isosurface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright 2012-2018, 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';

module.exports = require('../src/traces/isosurface');
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.1",
"font-atlas-sdf": "^1.3.3",
"gl-isosurface3d": "^0.5.0",
"gl-cone3d": "^1.1.0",
"gl-contour2d": "^1.1.4",
"gl-error3d": "^1.0.7",
Expand Down
165 changes: 165 additions & 0 deletions src/traces/isosurface/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* Copyright 2012-2018, 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 colorscaleAttrs = require('../../components/colorscale/attributes');
var colorbarAttrs = require('../../components/colorbar/attributes');
var mesh3dAttrs = require('../mesh3d/attributes');
var baseAttrs = require('../../plots/attributes');

var extendFlat = require('../../lib/extend').extendFlat;

var attrs = {
x: {
valType: 'data_array',
role: 'info',
editType: 'calc+clearAxisTypes',
description: [
'Sets the x coordinates of the volume data'
].join(' ')
},
y: {
valType: 'data_array',
role: 'info',
editType: 'calc+clearAxisTypes',
description: [
'Sets the y coordinates of the volume data'
].join(' ')
},
z: {
valType: 'data_array',
role: 'info',
editType: 'calc+clearAxisTypes',
description: [
'Sets the z coordinates of the volume data'
].join(' ')
},

value: {
valType: 'data_array',
role: 'info',
editType: 'calc',
description: 'Sets the intensity values of the volume data.'
},

isomin: {
valType: 'number',
role: 'info',
editType: 'calc',
description: 'Sets the minimum intensity bound of the isosurface.'
},

isomax: {
valType: 'number',
role: 'info',
editType: 'calc',
description: 'Sets the maximum intensity bound of the isosurface.'
},

xmin: {
valType: 'number',
role: 'info',
editType: 'calc',
description: 'Sets the minimum x bound of the isosurface.'
},

xmax: {
valType: 'number',
role: 'info',
editType: 'calc',
description: 'Sets the maximum x bound of the isosurface.'
},

ymin: {
valType: 'number',
role: 'info',
editType: 'calc',
description: 'Sets the minimum y bound of the isosurface.'
},

ymax: {
valType: 'number',
role: 'info',
editType: 'calc',
description: 'Sets the maximum y bound of the isosurface.'
},

zmin: {
valType: 'number',
role: 'info',
editType: 'calc',
description: 'Sets the minimum z bound of the isosurface.'
},

zmax: {
valType: 'number',
role: 'info',
editType: 'calc',
description: 'Sets the maximum z bound of the isosurface.'
},

smoothnormals: {
valType: 'boolean',
role: 'info',
editType: 'calc',
description: 'Smooth normals of the isosurface. By default this is set to true.'
},

isocaps: {
valType: 'boolean',
role: 'info',
editType: 'calc',
description: 'Whether to generate isocaps for the isosurface. By default this is set to true.'
},

color: {
valType: 'color',
role: 'style',
editType: 'calc',
description: [
'Sets the color of the isosurface.',
'By default the isosurface color is computed from the colorscale.',
'Isocaps still use the colorscale colors even with this set.'
].join(' ')
},

text: {
valType: 'string',
role: 'info',
dflt: '',
arrayOk: true,
editType: 'calc',
description: [
'Sets the text elements associated with the isosurface points.',
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
'these elements will be seen in the hover labels.'
].join(' ')
}
};

extendFlat(attrs, colorscaleAttrs('', {
colorAttr: 'value',
showScaleDflt: true,
editTypeOverride: 'calc'
}), {
colorbar: colorbarAttrs
});

var fromMesh3d = ['opacity', 'lightposition', 'lighting'];
fromMesh3d.forEach(function(k) {
attrs[k] = mesh3dAttrs[k];
});

attrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {
editType: 'calc',
flags: ['x', 'y', 'z', 'value', 'text', 'name'],
dflt: 'x+y+z+value+text+name'
});

module.exports = attrs;
59 changes: 59 additions & 0 deletions src/traces/isosurface/calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright 2012-2018, 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 colorscaleCalc = require('../../components/colorscale/calc');

module.exports = function calc(gd, trace) {
var value = trace.value;
var len = value.length;
var vMax = -Infinity;
var vMin = Infinity;
var i = 0;

for(i = 0; i < len; i++) {
var v = value[i];
vMax = Math.max(vMax, v);
vMin = Math.min(vMin, v);
}

trace._vMax = vMax;

colorscaleCalc(trace, [vMin, vMax], '', 'c');

var x = trace.x;
var y = trace.y;
var z = trace.z;

var xMax = -Infinity;
var xMin = Infinity;
var yMax = -Infinity;
var yMin = Infinity;
var zMax = -Infinity;
var zMin = Infinity;

for(i = 0; i < len; i++) {
var xx = x[i];
xMax = Math.max(xMax, xx);
xMin = Math.min(xMin, xx);

var yy = y[i];
yMax = Math.max(yMax, yy);
yMin = Math.min(yMin, yy);

var zz = z[i];
zMax = Math.max(zMax, zz);
zMin = Math.min(zMin, zz);
}

trace._xbnds = [xMin, xMax];
trace._ybnds = [yMin, yMax];
trace._zbnds = [zMin, zMax];

};
Loading