Skip to content

Commit 300de29

Browse files
authoredJan 8, 2019
Merge pull request #3418 from plotly/gl3d-reversescale-fixup
gl3d reversescale fixup
2 parents 673b542 + 454eed8 commit 300de29

File tree

8 files changed

+157
-9
lines changed

8 files changed

+157
-9
lines changed
 

‎src/lib/gl_format_color.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ function formatColor(containerIn, opacityIn, len) {
8282
return colorOut;
8383
}
8484

85-
function parseColorScale(colorscale, alpha) {
85+
function parseColorScale(cont, alpha) {
8686
if(alpha === undefined) alpha = 1;
8787

88+
var colorscale = cont.reversescale ?
89+
Colorscale.flipScale(cont.colorscale) :
90+
cont.colorscale;
91+
8892
return colorscale.map(function(elem) {
8993
var index = elem[0];
9094
var color = tinycolor(elem[1]);

‎src/traces/cone/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function convert(scene, trace) {
8080
trace._len
8181
);
8282

83-
coneOpts.colormap = parseColorScale(trace.colorscale);
83+
coneOpts.colormap = parseColorScale(trace);
8484
coneOpts.vertexIntensityBounds = [trace.cmin / trace._normMax, trace.cmax / trace._normMax];
8585
coneOpts.coneOffset = anchor2coneOffset[trace.anchor];
8686

‎src/traces/mesh3d/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ proto.update = function(data) {
162162
this.color = '#fff';
163163
config.vertexIntensity = data.intensity;
164164
config.vertexIntensityBounds = [data.cmin, data.cmax];
165-
config.colormap = parseColorScale(data.colorscale);
165+
config.colormap = parseColorScale(data);
166166
} else if(data.vertexcolor) {
167167
this.color = data.vertexcolor[0];
168168
config.vertexColors = parseColorArray(data.vertexcolor);

‎src/traces/streamtube/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function convert(scene, trace) {
153153
tubeOpts.startingPositions = startingPositions;
154154
}
155155

156-
tubeOpts.colormap = parseColorScale(trace.colorscale);
156+
tubeOpts.colormap = parseColorScale(trace);
157157
tubeOpts.tubeSize = trace.sizeref;
158158
tubeOpts.maxLength = trace.maxdisplayed;
159159

‎src/traces/surface/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ proto.update = function(data) {
364364
var sceneLayout = scene.fullSceneLayout;
365365
var surface = this.surface;
366366
var alpha = data.opacity;
367-
var colormap = parseColorScale(data.colorscale, alpha);
367+
var colormap = parseColorScale(data, alpha);
368368
var scaleFactor = scene.dataScale;
369369
var xlen = data.z[0].length;
370370
var ylen = data._ylength;

‎src/traces/surface/defaults.js

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Registry = require('../../registry');
@@ -15,7 +14,6 @@ var Lib = require('../../lib');
1514
var colorscaleDefaults = require('../../components/colorscale/defaults');
1615
var attributes = require('./attributes');
1716

18-
1917
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
2018
var i, j;
2119

@@ -61,8 +59,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
6159

6260
var surfaceColor = coerce('surfacecolor');
6361

64-
coerce('colorscale');
65-
6662
var dims = ['x', 'y', 'z'];
6763
for(i = 0; i < 3; ++i) {
6864

52.3 KB
Loading
+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"data": [{
3+
"type": "surface",
4+
"z": [
5+
[8.41, 3, 4],
6+
[1, 2, 3],
7+
[2, 43, 1]
8+
],
9+
"reversescale": true,
10+
"colorbar": {
11+
"title": {"text": "surface"},
12+
"x": -0.15,
13+
"len": 0.3,
14+
"y": 0.7
15+
}
16+
}, {
17+
"type":"mesh3d",
18+
"name": "colorscale + intensity",
19+
"x":[0, 1, 2, 0],
20+
"y":[0, 0, 1, 2],
21+
"z":[0, 2, 0, 1],
22+
"i":[0, 0, 0, 1],
23+
"j":[1, 2, 3, 2],
24+
"k":[2, 3, 1, 3],
25+
"colorscale": [
26+
[0, "rgb(0, 0, 0)"],
27+
[0.33, "rgb(255, 0, 0)"],
28+
[0.66, "rgb(0, 255, 0)"],
29+
[1, "rgb(0, 0, 255)"]
30+
],
31+
"intensity": [0, 0.33, 0.66, 1],
32+
"reversescale": true,
33+
"colorbar": {
34+
"title": {"text": "mesh3d"},
35+
"x": -0.15,
36+
"len": 0.3,
37+
"y": 0.4
38+
}
39+
}, {
40+
"type": "streamtube",
41+
"x": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2],
42+
"y": [0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2],
43+
"z": [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2],
44+
"u": [
45+
1,
46+
1,
47+
1,
48+
1,
49+
1,
50+
1,
51+
1,
52+
1,
53+
1,
54+
1.8414709848078965,
55+
1.8414709848078965,
56+
1.8414709848078965,
57+
1.8414709848078965,
58+
1.8414709848078965,
59+
1.8414709848078965,
60+
1.8414709848078965,
61+
1.8414709848078965,
62+
1.8414709848078965,
63+
1.9092974268256817,
64+
1.9092974268256817,
65+
1.9092974268256817,
66+
1.9092974268256817,
67+
1.9092974268256817,
68+
1.9092974268256817,
69+
1.9092974268256817,
70+
1.9092974268256817,
71+
1.9092974268256817
72+
],
73+
"v": [
74+
1,
75+
1,
76+
1,
77+
0.5403023058681398,
78+
0.5403023058681398,
79+
0.5403023058681398,
80+
-0.4161468365471424,
81+
-0.4161468365471424,
82+
-0.4161468365471424,
83+
1,
84+
1,
85+
1,
86+
0.5403023058681398,
87+
0.5403023058681398,
88+
0.5403023058681398,
89+
-0.4161468365471424,
90+
-0.4161468365471424,
91+
-0.4161468365471424,
92+
1,
93+
1,
94+
1,
95+
0.5403023058681398,
96+
0.5403023058681398,
97+
0.5403023058681398,
98+
-0.4161468365471424,
99+
-0.4161468365471424,
100+
-0.4161468365471424
101+
],
102+
"w": [
103+
0,
104+
0.08865606199840186,
105+
0.1693927420185106,
106+
0,
107+
0.08865606199840186,
108+
0.1693927420185106,
109+
0,
110+
0.08865606199840186,
111+
0.1693927420185106,
112+
0,
113+
0.08865606199840186,
114+
0.1693927420185106,
115+
0,
116+
0.08865606199840186,
117+
0.1693927420185106,
118+
0,
119+
0.08865606199840186,
120+
0.1693927420185106,
121+
0,
122+
0.08865606199840186,
123+
0.1693927420185106,
124+
0,
125+
0.08865606199840186,
126+
0.1693927420185106,
127+
0,
128+
0.08865606199840186,
129+
0.1693927420185106
130+
],
131+
"reversescale": true,
132+
"colorbar": {
133+
"title": {"text": "streamtube"},
134+
"x": -0.15,
135+
"len": 0.3,
136+
"y": 0,
137+
"yanchor": "bottom"
138+
}
139+
}],
140+
"layout": {
141+
"title": {"text": "gl3d trace with reversescale:true"},
142+
"scene": {
143+
"camera": {
144+
"eye": {"x": -2, "y": -0.35, "z": 0.34}
145+
}
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)
Please sign in to comment.