Skip to content

Commit 77f7317

Browse files
committed
fixup volume default to coerce volume attributes and dflt - switch projection type to orthographic in one mock
1 parent 0aa25f0 commit 77f7317

9 files changed

+116
-100
lines changed

src/traces/isosurface/defaults.js

+2-87
Original file line numberDiff line numberDiff line change
@@ -8,99 +8,14 @@
88

99
'use strict';
1010

11-
var Registry = require('../../registry');
1211
var Lib = require('../../lib');
13-
var colorscaleDefaults = require('../../components/colorscale/defaults');
1412
var attributes = require('./attributes');
13+
var supplyIsoDefaults = require('./iso_defaults');
1514

1615
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
1716
function coerce(attr, dflt) {
1817
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
1918
}
2019

21-
var isomin = coerce('isomin');
22-
var isomax = coerce('isomax');
23-
24-
if(isomax !== undefined && isomax !== null &&
25-
isomin !== undefined && isomin !== null &&
26-
isomin > isomax) {
27-
// applying default values in this case:
28-
traceOut.isomin = null;
29-
traceOut.isomax = null;
30-
}
31-
32-
var x = coerce('x');
33-
var y = coerce('y');
34-
var z = coerce('z');
35-
var value = coerce('value');
36-
37-
if(
38-
!x || !x.length ||
39-
!y || !y.length ||
40-
!z || !z.length ||
41-
!value || !value.length
42-
) {
43-
traceOut.visible = false;
44-
return;
45-
}
46-
47-
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
48-
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);
49-
50-
['x', 'y', 'z'].forEach(function(dim) {
51-
var capDim = 'caps.' + dim;
52-
var showCap = coerce(capDim + '.show');
53-
if(showCap) {
54-
coerce(capDim + '.fill');
55-
}
56-
57-
var sliceDim = 'slices.' + dim;
58-
var showSlice = coerce(sliceDim + '.show');
59-
if(showSlice) {
60-
coerce(sliceDim + '.fill');
61-
coerce(sliceDim + '.locations');
62-
}
63-
});
64-
65-
var showSpaceframe = coerce('spaceframe.show');
66-
if(showSpaceframe) {
67-
coerce('spaceframe.fill');
68-
}
69-
70-
var showSurface = coerce('surface.show');
71-
if(showSurface) {
72-
coerce('surface.count');
73-
coerce('surface.fill');
74-
coerce('surface.pattern');
75-
}
76-
77-
var showContour = coerce('contour.show');
78-
if(showContour) {
79-
coerce('contour.color');
80-
coerce('contour.width');
81-
}
82-
83-
// Coerce remaining properties
84-
[
85-
'text',
86-
'hovertext',
87-
'hovertemplate',
88-
'lighting.ambient',
89-
'lighting.diffuse',
90-
'lighting.specular',
91-
'lighting.roughness',
92-
'lighting.fresnel',
93-
'lighting.vertexnormalsepsilon',
94-
'lighting.facenormalsepsilon',
95-
'lightposition.x',
96-
'lightposition.y',
97-
'lightposition.z',
98-
'flatshading',
99-
'opacity'
100-
].forEach(function(x) { coerce(x); });
101-
102-
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});
103-
104-
// disable 1D transforms (for now)
105-
traceOut._length = null;
20+
supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce);
10621
};

src/traces/isosurface/iso_defaults.js

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 Registry = require('../../registry');
12+
var colorscaleDefaults = require('../../components/colorscale/defaults');
13+
14+
module.exports = function supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
15+
var isomin = coerce('isomin');
16+
var isomax = coerce('isomax');
17+
18+
if(isomax !== undefined && isomax !== null &&
19+
isomin !== undefined && isomin !== null &&
20+
isomin > isomax) {
21+
// applying default values in this case:
22+
traceOut.isomin = null;
23+
traceOut.isomax = null;
24+
}
25+
26+
var x = coerce('x');
27+
var y = coerce('y');
28+
var z = coerce('z');
29+
var value = coerce('value');
30+
31+
if(
32+
!x || !x.length ||
33+
!y || !y.length ||
34+
!z || !z.length ||
35+
!value || !value.length
36+
) {
37+
traceOut.visible = false;
38+
return;
39+
}
40+
41+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
42+
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);
43+
44+
['x', 'y', 'z'].forEach(function(dim) {
45+
var capDim = 'caps.' + dim;
46+
var showCap = coerce(capDim + '.show');
47+
if(showCap) {
48+
coerce(capDim + '.fill');
49+
}
50+
51+
var sliceDim = 'slices.' + dim;
52+
var showSlice = coerce(sliceDim + '.show');
53+
if(showSlice) {
54+
coerce(sliceDim + '.fill');
55+
coerce(sliceDim + '.locations');
56+
}
57+
});
58+
59+
var showSpaceframe = coerce('spaceframe.show');
60+
if(showSpaceframe) {
61+
coerce('spaceframe.fill');
62+
}
63+
64+
var showSurface = coerce('surface.show');
65+
if(showSurface) {
66+
coerce('surface.count');
67+
coerce('surface.fill');
68+
coerce('surface.pattern');
69+
}
70+
71+
var showContour = coerce('contour.show');
72+
if(showContour) {
73+
coerce('contour.color');
74+
coerce('contour.width');
75+
}
76+
77+
// Coerce remaining properties
78+
[
79+
'text',
80+
'hovertext',
81+
'hovertemplate',
82+
'lighting.ambient',
83+
'lighting.diffuse',
84+
'lighting.specular',
85+
'lighting.roughness',
86+
'lighting.fresnel',
87+
'lighting.vertexnormalsepsilon',
88+
'lighting.facenormalsepsilon',
89+
'lightposition.x',
90+
'lightposition.y',
91+
'lightposition.z',
92+
'flatshading',
93+
'opacity'
94+
].forEach(function(x) { coerce(x); });
95+
96+
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});
97+
98+
// disable 1D transforms (for now)
99+
traceOut._length = null;
100+
};

src/traces/volume/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
'use strict';
1010

11-
var isosurfaceDefaults = require('../isosurface/defaults');
1211
var Lib = require('../../lib');
1312
var attributes = require('./attributes');
13+
var supplyIsoDefaults = require('../isosurface/iso_defaults');
1414

1515
var MIN = 0.1; // Note: often we don't want the data cube to be disappeared
1616

@@ -33,7 +33,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3333
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
3434
}
3535

36-
isosurfaceDefaults(traceIn, traceOut, defaultColor, layout);
36+
supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce);
3737

3838
var opacityscale = coerce('opacityscale');
3939
if(opacityscale === 'max') {
Loading

test/image/mocks/gl3d_volume_between-ranges.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"opacityscale": [[0, 0.2], [1, 1]],
1111
"opacity": 0.5,
1212
"surface": { "show": true, "fill": 1.0, "pattern": "all", "count": 33 },
13-
"spaceframe": { "show": true, "fill": 1.0 },
13+
"spaceframe": { "show": true },
1414
"slices": {
1515
"x": { "show": false },
1616
"y": { "show": false },

test/image/mocks/gl3d_volume_data-cube.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"opacityscale": "max",
1111
"opacity": 0.1,
1212
"surface": { "show": true, "fill": 1.0, "pattern": "all", "count": 64 },
13-
"spaceframe": { "show": true, "fill": 1.0 },
13+
"spaceframe": { "show": true },
1414
"slices": {
1515
"x": { "show": false },
1616
"y": { "show": false },

test/image/mocks/gl3d_volume_multiple-traces.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"colorscale": "Blackbody",
1212
"reversescale": true,
1313
"surface": { "show": true, "count": 64 },
14-
"spaceframe": { "show": true, "fill": 1 },
14+
"spaceframe": { "show": true },
1515
"slices": {
1616
"x": { "show": false },
1717
"y": { "show": false },
@@ -776,7 +776,7 @@
776776
"colorscale": "Blackbody",
777777
"reversescale": true,
778778
"surface": { "show": true, "count": 64 },
779-
"spaceframe": { "show": true, "fill": 1 },
779+
"spaceframe": { "show": true },
780780
"slices": {
781781
"x": { "show": false },
782782
"y": { "show": false },

test/image/mocks/gl3d_volume_multiple-traces_one-cube.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"yanchor": "bottom"
1818
},
1919
"surface": { "show": true, "fill": 1.0, "count": 32 },
20-
"spaceframe": { "show": true, "fill": 1.0 },
20+
"spaceframe": { "show": true },
2121
"slices": {
2222
"x": { "show": true },
2323
"y": { "show": true },
@@ -2862,7 +2862,7 @@
28622862
"yanchor": "bottom"
28632863
},
28642864
"surface": { "show": true, "fill": 1.0, "count": 32 },
2865-
"spaceframe": { "show": false, "fill": 1.0 },
2865+
"spaceframe": { "show": false },
28662866
"slices": {
28672867
"x": { "show": true },
28682868
"y": { "show": true },

test/image/mocks/gl3d_volume_opacityscale-iso.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"colorscale": [[ 0.0, "rgb(127,127,127)" ], [ 0.332, "rgb(127,127,127)" ], [ 0.333, "rgb(0,0,0)" ], [ 0.5, "rgb(255,0,0)" ], [ 0.666, "rgb(255,255,0)" ], [ 0.667, "rgb(127,127,127)" ], [ 1.0, "rgb(127,127,127)" ]],
99
"reversescale": false,
1010
"opacityscale": [[ 0.0, 0.0 ], [ 0.332, 0.0 ], [ 0.333, 1.0 ], [ 0.5, 1.0 ], [ 0.666, 1.0 ], [ 0.667, 0.0 ], [ 1.0, 0.0 ]],
11-
"opacity": 0.04,
11+
"opacity": 0.05,
1212
"surface": { "show": true, "fill": 1.0, "count": 16 },
1313
"spaceframe": { "show": true, "fill": 1.0 },
1414
"slices": {
@@ -2846,20 +2846,21 @@
28462846
}],
28472847
"layout": {
28482848
"title": {
2849-
"text": "Plotly volume trace on non-uniform y & z axes presented with opacityscale clips and scene with aspect ratio 2 on x axis"
2849+
"text": "Plotly volume trace on non-uniform y & z axes presented with opacityscale clips and<br>orthographic scene with double aspect ratio on the x axis"
28502850
},
28512851
"width": 1200,
28522852
"height": 900,
28532853
"scene": {
28542854
"aspectratio": {
2855-
"x": 2,
2856-
"y": 1,
2857-
"z": 1
2855+
"x": 2.4,
2856+
"y": 1.2,
2857+
"z": 1.2
28582858
},
28592859
"xaxis": {"nticks": 12},
28602860
"yaxis": {"nticks": 12},
28612861
"zaxis": {"nticks": 12},
28622862
"camera": {
2863+
"projection": { "type": "orthographic" },
28632864
"eye": {
28642865
"x": 0.6,
28652866
"y": 2.2,

0 commit comments

Comments
 (0)