Skip to content

Commit 92c0379

Browse files
committed
isosurface > bar3d
1 parent 58a1a1c commit 92c0379

File tree

5 files changed

+1463
-0
lines changed

5 files changed

+1463
-0
lines changed

src/traces/bar3d/attributes.js

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
'use strict';
2+
3+
var colorScaleAttrs = require('../../components/colorscale/attributes');
4+
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat;
5+
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
6+
var meshAttrs = require('../mesh3d/attributes');
7+
var baseAttrs = require('../../plots/attributes');
8+
9+
var extendFlat = require('../../lib/extend').extendFlat;
10+
var overrideAll = require('../../plot_api/edit_types').overrideAll;
11+
12+
function makeSliceAttr(axLetter) {
13+
return {
14+
show: {
15+
valType: 'boolean',
16+
dflt: false,
17+
description: [
18+
'Determines whether or not slice planes about the', axLetter,
19+
'dimension are drawn.'
20+
].join(' ')
21+
},
22+
locations: {
23+
valType: 'data_array',
24+
dflt: [],
25+
description: [
26+
'Specifies the location(s) of slices on the axis.',
27+
'When not specified slices would be created for',
28+
'all points of the axis', axLetter, 'except start and end.'
29+
].join(' ')
30+
},
31+
fill: {
32+
valType: 'number',
33+
min: 0,
34+
max: 1,
35+
dflt: 1,
36+
description: [
37+
'Sets the fill ratio of the `slices`. The default fill value of the',
38+
'`slices` is 1 meaning that they are entirely shaded. On the other hand',
39+
'Applying a `fill` ratio less than one would allow the creation of',
40+
'openings parallel to the edges.'
41+
].join(' ')
42+
}
43+
};
44+
}
45+
46+
function makeCapAttr(axLetter) {
47+
return {
48+
show: {
49+
valType: 'boolean',
50+
dflt: true,
51+
description: [
52+
'Sets the fill ratio of the `slices`. The default fill value of the', axLetter,
53+
'`slices` is 1 meaning that they are entirely shaded. On the other hand',
54+
'Applying a `fill` ratio less than one would allow the creation of',
55+
'openings parallel to the edges.'
56+
].join(' ')
57+
},
58+
fill: {
59+
valType: 'number',
60+
min: 0,
61+
max: 1,
62+
dflt: 1,
63+
description: [
64+
'Sets the fill ratio of the `caps`. The default fill value of the',
65+
'`caps` is 1 meaning that they are entirely shaded. On the other hand',
66+
'Applying a `fill` ratio less than one would allow the creation of',
67+
'openings parallel to the edges.'
68+
].join(' ')
69+
}
70+
};
71+
}
72+
73+
var attrs = module.exports = overrideAll(extendFlat({
74+
x: {
75+
valType: 'data_array',
76+
description: [
77+
'Sets the X coordinates of the vertices on X axis.'
78+
].join(' ')
79+
},
80+
y: {
81+
valType: 'data_array',
82+
description: [
83+
'Sets the Y coordinates of the vertices on Y axis.'
84+
].join(' ')
85+
},
86+
z: {
87+
valType: 'data_array',
88+
description: [
89+
'Sets the Z coordinates of the vertices on Z axis.'
90+
].join(' ')
91+
},
92+
value: {
93+
valType: 'data_array',
94+
description: [
95+
'Sets the 4th dimension (value) of the vertices.'
96+
].join(' ')
97+
},
98+
isomin: {
99+
valType: 'number',
100+
description: [
101+
'Sets the minimum boundary for iso-surface plot.'
102+
].join(' ')
103+
},
104+
isomax: {
105+
valType: 'number',
106+
description: [
107+
'Sets the maximum boundary for iso-surface plot.'
108+
].join(' ')
109+
},
110+
111+
surface: {
112+
show: {
113+
valType: 'boolean',
114+
dflt: true,
115+
description: [
116+
'Hides/displays surfaces between minimum and maximum iso-values.'
117+
].join(' ')
118+
},
119+
count: {
120+
valType: 'integer',
121+
dflt: 2,
122+
min: 1,
123+
description: [
124+
'Sets the number of iso-surfaces between minimum and maximum iso-values.',
125+
'By default this value is 2 meaning that only minimum and maximum surfaces',
126+
'would be drawn.'
127+
].join(' ')
128+
},
129+
fill: {
130+
valType: 'number',
131+
min: 0,
132+
max: 1,
133+
dflt: 1,
134+
description: [
135+
'Sets the fill ratio of the iso-surface. The default fill value of the',
136+
'surface is 1 meaning that they are entirely shaded. On the other hand',
137+
'Applying a `fill` ratio less than one would allow the creation of',
138+
'openings parallel to the edges.'
139+
].join(' ')
140+
},
141+
pattern: {
142+
valType: 'flaglist',
143+
flags: ['A', 'B', 'C', 'D', 'E'],
144+
extras: ['all', 'odd', 'even'],
145+
dflt: 'all',
146+
description: [
147+
'Sets the surface pattern of the iso-surface 3-D sections. The default pattern of',
148+
'the surface is `all` meaning that the rest of surface elements would be shaded.',
149+
'The check options (either 1 or 2) could be used to draw half of the squares',
150+
'on the surface. Using various combinations of capital `A`, `B`, `C`, `D` and `E`',
151+
'may also be used to reduce the number of triangles on the iso-surfaces and',
152+
'creating other patterns of interest.'
153+
].join(' ')
154+
}
155+
},
156+
157+
spaceframe: {
158+
show: {
159+
valType: 'boolean',
160+
dflt: false,
161+
description: [
162+
'Displays/hides tetrahedron shapes between minimum and',
163+
'maximum iso-values. Often useful when either caps or',
164+
'surfaces are disabled or filled with values less than 1.'
165+
].join(' ')
166+
},
167+
fill: {
168+
valType: 'number',
169+
min: 0,
170+
max: 1,
171+
dflt: 0.15,
172+
description: [
173+
'Sets the fill ratio of the `spaceframe` elements. The default fill value',
174+
'is 0.15 meaning that only 15% of the area of every faces of tetras would be',
175+
'shaded. Applying a greater `fill` ratio would allow the creation of stronger',
176+
'elements or could be sued to have entirely closed areas (in case of using 1).'
177+
].join(' ')
178+
}
179+
},
180+
181+
slices: {
182+
x: makeSliceAttr('x'),
183+
y: makeSliceAttr('y'),
184+
z: makeSliceAttr('z')
185+
},
186+
187+
caps: {
188+
x: makeCapAttr('x'),
189+
y: makeCapAttr('y'),
190+
z: makeCapAttr('z')
191+
},
192+
193+
text: {
194+
valType: 'string',
195+
dflt: '',
196+
arrayOk: true,
197+
description: [
198+
'Sets the text elements associated with the vertices.',
199+
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
200+
'these elements will be seen in the hover labels.'
201+
].join(' ')
202+
},
203+
hovertext: {
204+
valType: 'string',
205+
dflt: '',
206+
arrayOk: true,
207+
description: 'Same as `text`.'
208+
},
209+
hovertemplate: hovertemplateAttrs(),
210+
xhoverformat: axisHoverFormat('x'),
211+
yhoverformat: axisHoverFormat('y'),
212+
zhoverformat: axisHoverFormat('z'),
213+
valuehoverformat: axisHoverFormat('value', 1),
214+
215+
showlegend: extendFlat({}, baseAttrs.showlegend, {dflt: false})
216+
},
217+
218+
colorScaleAttrs('', {
219+
colorAttr: '`value`',
220+
showScaleDflt: true,
221+
editTypeOverride: 'calc'
222+
}), {
223+
opacity: meshAttrs.opacity,
224+
lightposition: meshAttrs.lightposition,
225+
lighting: meshAttrs.lighting,
226+
flatshading: meshAttrs.flatshading,
227+
contour: meshAttrs.contour,
228+
229+
hoverinfo: extendFlat({}, baseAttrs.hoverinfo)
230+
}), 'calc', 'nested');
231+
232+
// required defaults to speed up surface normal calculations
233+
attrs.flatshading.dflt = true; attrs.lighting.facenormalsepsilon.dflt = 0;
234+
235+
attrs.x.editType = attrs.y.editType = attrs.z.editType = attrs.value.editType = 'calc+clearAxisTypes';
236+
attrs.transforms = undefined;

src/traces/bar3d/calc.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
var colorscaleCalc = require('../../components/colorscale/calc');
4+
var processGrid = require('../streamtube/calc').processGrid;
5+
var filter = require('../streamtube/calc').filter;
6+
7+
module.exports = function calc(gd, trace) {
8+
trace._len = Math.min(
9+
trace.x.length,
10+
trace.y.length,
11+
trace.z.length,
12+
trace.value.length
13+
);
14+
15+
trace._x = filter(trace.x, trace._len);
16+
trace._y = filter(trace.y, trace._len);
17+
trace._z = filter(trace.z, trace._len);
18+
trace._value = filter(trace.value, trace._len);
19+
20+
var grid = processGrid(trace);
21+
trace._gridFill = grid.fill;
22+
trace._Xs = grid.Xs;
23+
trace._Ys = grid.Ys;
24+
trace._Zs = grid.Zs;
25+
trace._len = grid.len;
26+
27+
var min = Infinity;
28+
var max = -Infinity;
29+
for(var i = 0; i < trace._len; i++) {
30+
var v = trace._value[i];
31+
min = Math.min(min, v);
32+
max = Math.max(max, v);
33+
}
34+
35+
trace._minValues = min;
36+
trace._maxValues = max;
37+
trace._vMin = (trace.isomin === undefined || trace.isomin === null) ? min : trace.isomin;
38+
trace._vMax = (trace.isomax === undefined || trace.isomin === null) ? max : trace.isomax;
39+
40+
colorscaleCalc(gd, trace, {
41+
vals: [trace._vMin, trace._vMax],
42+
containerStr: '',
43+
cLetter: 'c'
44+
});
45+
};

0 commit comments

Comments
 (0)