Skip to content

Commit e5b8c71

Browse files
authored
Merge pull request #3488 from plotly/volume4d
Volume - new gl3d trace
2 parents 3c952bf + 4a9987d commit e5b8c71

25 files changed

+8695
-30
lines changed

lib/index-gl3d.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Plotly.register([
1414
require('./scatter3d'),
1515
require('./surface'),
1616
require('./mesh3d'),
17+
require('./isosurface'),
18+
require('./volume'),
1719
require('./cone'),
1820
require('./streamtube')
1921
]);

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Plotly.register([
2929
require('./scatter3d'),
3030
require('./surface'),
3131
require('./isosurface'),
32+
require('./volume'),
3233
require('./mesh3d'),
3334
require('./cone'),
3435
require('./streamtube'),

lib/volume.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = require('../src/traces/volume');

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"gl-heatmap2d": "^1.0.5",
7979
"gl-line3d": "^1.1.11",
8080
"gl-mat4": "^1.2.0",
81-
"gl-mesh3d": "^2.0.10",
81+
"gl-mesh3d": "^2.1.0",
8282
"gl-plot2d": "^1.4.2",
8383
"gl-plot3d": "^2.2.1",
8484
"gl-pointcloud2d": "^1.0.2",

src/lib/coerce.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var isNumeric = require('fast-isnumeric');
1212
var tinycolor = require('tinycolor2');
1313

1414
var baseTraceAttrs = require('../plots/attributes');
15-
var scales = require('../components/colorscale/scales');
15+
var colorscales = require('../components/colorscale/scales');
1616
var DESELECTDIM = require('../constants/interactions').DESELECTDIM;
1717

1818
var nestedProperty = require('./nested_property');
@@ -164,7 +164,7 @@ exports.valObjectMeta = {
164164
colorscale: {
165165
description: [
166166
'A Plotly colorscale either picked by a name:',
167-
'(any of', Object.keys(scales.scales).join(', '), ')',
167+
'(any of', Object.keys(colorscales.scales).join(', '), ')',
168168
'customized as an {array} of 2-element {arrays} where',
169169
'the first element is the normalized color level value',
170170
'(starting at *0* and ending at *1*),',
@@ -173,7 +173,7 @@ exports.valObjectMeta = {
173173
requiredOpts: [],
174174
otherOpts: ['dflt'],
175175
coerceFunction: function(v, propOut, dflt) {
176-
propOut.set(scales.get(v, dflt));
176+
propOut.set(colorscales.get(v, dflt));
177177
}
178178
},
179179
angle: {

src/plots/gl3d/scene.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function render(scene) {
123123
vectorTx.push(selection.textLabel);
124124
}
125125
tx = vectorTx.join('<br>');
126-
} else if(trace.type === 'isosurface') {
126+
} else if(trace.type === 'isosurface' || trace.type === 'volume') {
127127
labels.valueLabel = Axes.tickText(scene.mockAxis, scene.mockAxis.d2l(selection.traceCoordinate[3]), 'hover').text;
128128
vectorTx.push('value: ' + labels.valueLabel);
129129
if(selection.textLabel) {

src/traces/isosurface/convert.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,7 @@ function distinctVals(col) {
2020
return Lib.distinctVals(col).vals;
2121
}
2222

23-
function IsosurfaceTrace(scene, mesh, uid) {
24-
this.scene = scene;
25-
this.uid = uid;
26-
this.mesh = mesh;
27-
this.name = '';
28-
this.data = null;
29-
this.showContour = false;
30-
}
31-
32-
var proto = IsosurfaceTrace.prototype;
33-
34-
function findNearestOnAxis(w, arr) {
23+
var findNearestOnAxis = function(w, arr) {
3524
for(var q = arr.length - 1; q > 0; q--) {
3625
var min = Math.min(arr[q], arr[q - 1]);
3726
var max = Math.max(arr[q], arr[q - 1]);
@@ -46,8 +35,19 @@ function findNearestOnAxis(w, arr) {
4635
id: 0,
4736
distRatio: 0
4837
};
38+
};
39+
40+
function IsosurfaceTrace(scene, mesh, uid) {
41+
this.scene = scene;
42+
this.uid = uid;
43+
this.mesh = mesh;
44+
this.name = '';
45+
this.data = null;
46+
this.showContour = false;
4947
}
5048

49+
var proto = IsosurfaceTrace.prototype;
50+
5151
proto.handlePick = function(selection) {
5252
if(selection.object === this.mesh) {
5353
var rawId = selection.data.index;
@@ -87,7 +87,7 @@ proto.update = function(data) {
8787
var scene = this.scene;
8888
var layout = scene.fullSceneLayout;
8989

90-
this.data = generateIsosurfaceMesh(data);
90+
this.data = generateIsoMeshes(data);
9191

9292
// Unpack position data
9393
function toDataCoords(axis, coord, scale, calendar) {
@@ -134,7 +134,7 @@ proto.dispose = function() {
134134
this.mesh.dispose();
135135
};
136136

137-
function generateIsosurfaceMesh(data) {
137+
function generateIsoMeshes(data) {
138138
data._i = [];
139139
data._j = [];
140140
data._k = [];
@@ -1035,4 +1035,8 @@ function createIsosurfaceTrace(scene, data) {
10351035
return result;
10361036
}
10371037

1038-
module.exports = createIsosurfaceTrace;
1038+
module.exports = {
1039+
findNearestOnAxis: findNearestOnAxis,
1040+
generateIsoMeshes: generateIsoMeshes,
1041+
createIsosurfaceTrace: createIsosurfaceTrace,
1042+
};

src/traces/isosurface/defaults.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
'use strict';
1010

11-
var Registry = require('../../registry');
1211
var Lib = require('../../lib');
13-
var colorscaleDefaults = require('../../components/colorscale/defaults');
12+
var Registry = require('../../registry');
1413
var attributes = require('./attributes');
14+
var colorscaleDefaults = require('../../components/colorscale/defaults');
1515

16-
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
16+
function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
1717
function coerce(attr, dflt) {
1818
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
1919
}
2020

21+
supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce);
22+
}
23+
24+
function supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
2125
var isomin = coerce('isomin');
2226
var isomax = coerce('isomax');
2327

@@ -103,4 +107,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
103107

104108
// disable 1D transforms (for now)
105109
traceOut._length = null;
110+
}
111+
112+
module.exports = {
113+
supplyDefaults: supplyDefaults,
114+
supplyIsoDefaults: supplyIsoDefaults
106115
};

src/traces/isosurface/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
var Isosurface = {};
1313

1414
Isosurface.attributes = require('./attributes');
15-
Isosurface.supplyDefaults = require('./defaults');
15+
Isosurface.supplyDefaults = require('./defaults').supplyDefaults;
1616
Isosurface.calc = require('./calc');
1717
Isosurface.colorbar = {
1818
min: 'cmin',
1919
max: 'cmax'
2020
};
21-
Isosurface.plot = require('./convert');
21+
Isosurface.plot = require('./convert').createIsosurfaceTrace;
2222

2323
Isosurface.moduleType = 'trace';
2424
Isosurface.name = 'isosurface',

src/traces/volume/attributes.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var colorscaleAttrs = require('../../components/colorscale/attributes');
12+
var isosurfaceAttrs = require('../isosurface/attributes');
13+
var baseAttrs = require('../../plots/attributes');
14+
15+
var extendFlat = require('../../lib/extend').extendFlat;
16+
var overrideAll = require('../../plot_api/edit_types').overrideAll;
17+
18+
var attrs = module.exports = overrideAll(extendFlat({
19+
x: isosurfaceAttrs.x,
20+
y: isosurfaceAttrs.y,
21+
z: isosurfaceAttrs.z,
22+
value: isosurfaceAttrs.value,
23+
isomin: isosurfaceAttrs.isomin,
24+
isomax: isosurfaceAttrs.isomax,
25+
surface: isosurfaceAttrs.surface,
26+
spaceframe: {
27+
show: {
28+
valType: 'boolean',
29+
role: 'info',
30+
dflt: false,
31+
description: [
32+
'Displays/hides tetrahedron shapes between minimum and',
33+
'maximum iso-values. Often useful when either caps or',
34+
'surfaces are disabled or filled with values less than 1.'
35+
].join(' ')
36+
},
37+
fill: {
38+
valType: 'number',
39+
role: 'style',
40+
min: 0,
41+
max: 1,
42+
dflt: 1,
43+
description: [
44+
'Sets the fill ratio of the `spaceframe` elements. The default fill value',
45+
'is 1 meaning that they are entirely shaded. Applying a `fill` ratio less',
46+
'than one would allow the creation of openings parallel to the edges.'
47+
].join(' ')
48+
}
49+
},
50+
51+
slices: isosurfaceAttrs.slices,
52+
caps: isosurfaceAttrs.caps,
53+
text: isosurfaceAttrs.text,
54+
hovertext: isosurfaceAttrs.hovertext,
55+
hovertemplate: isosurfaceAttrs.hovertemplate
56+
},
57+
58+
colorscaleAttrs('', {
59+
colorAttr: '`value`',
60+
showScaleDflt: true,
61+
editTypeOverride: 'calc'
62+
}), {
63+
64+
colorbar: isosurfaceAttrs.colorbar,
65+
opacity: isosurfaceAttrs.opacity,
66+
opacityscale: {
67+
valType: 'any',
68+
role: 'style',
69+
editType: 'calc',
70+
description: [
71+
'Sets the opacityscale.',
72+
' The opacityscale must be an array containing',
73+
' arrays mapping a normalized value to an opacity value.',
74+
' At minimum, a mapping for the lowest (0) and highest (1)',
75+
' values are required. For example,',
76+
' `[[0, 1], [0.5, 0.2], [1, 1]]` means that higher/lower values would have',
77+
' higher opacity values and those in the middle would be more transparent',
78+
' Alternatively, `opacityscale` may be a palette name string',
79+
' of the following list: \'min\', \'max\', \'extremes\' and \'uniform\'.',
80+
' The default is \'uniform\'.'
81+
].join('')
82+
},
83+
84+
lightposition: isosurfaceAttrs.lightposition,
85+
lighting: isosurfaceAttrs.lighting,
86+
flatshading: isosurfaceAttrs.flatshading,
87+
contour: isosurfaceAttrs.contour,
88+
89+
hoverinfo: extendFlat({}, baseAttrs.hoverinfo)
90+
}), 'calc', 'nested');
91+
92+
attrs.x.editType = attrs.y.editType = attrs.z.editType = attrs.value.editType = 'calc+clearAxisTypes';
93+
attrs.transforms = undefined;

0 commit comments

Comments
 (0)