Skip to content

Commit

Permalink
Merge pull request #3418 from plotly/gl3d-reversescale-fixup
Browse files Browse the repository at this point in the history
gl3d reversescale fixup
  • Loading branch information
etpinard authored Jan 8, 2019
2 parents 673b542 + 454eed8 commit 300de29
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/lib/gl_format_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ function formatColor(containerIn, opacityIn, len) {
return colorOut;
}

function parseColorScale(colorscale, alpha) {
function parseColorScale(cont, alpha) {
if(alpha === undefined) alpha = 1;

var colorscale = cont.reversescale ?
Colorscale.flipScale(cont.colorscale) :
cont.colorscale;

return colorscale.map(function(elem) {
var index = elem[0];
var color = tinycolor(elem[1]);
Expand Down
2 changes: 1 addition & 1 deletion src/traces/cone/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function convert(scene, trace) {
trace._len
);

coneOpts.colormap = parseColorScale(trace.colorscale);
coneOpts.colormap = parseColorScale(trace);
coneOpts.vertexIntensityBounds = [trace.cmin / trace._normMax, trace.cmax / trace._normMax];
coneOpts.coneOffset = anchor2coneOffset[trace.anchor];

Expand Down
2 changes: 1 addition & 1 deletion src/traces/mesh3d/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ proto.update = function(data) {
this.color = '#fff';
config.vertexIntensity = data.intensity;
config.vertexIntensityBounds = [data.cmin, data.cmax];
config.colormap = parseColorScale(data.colorscale);
config.colormap = parseColorScale(data);
} else if(data.vertexcolor) {
this.color = data.vertexcolor[0];
config.vertexColors = parseColorArray(data.vertexcolor);
Expand Down
2 changes: 1 addition & 1 deletion src/traces/streamtube/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function convert(scene, trace) {
tubeOpts.startingPositions = startingPositions;
}

tubeOpts.colormap = parseColorScale(trace.colorscale);
tubeOpts.colormap = parseColorScale(trace);
tubeOpts.tubeSize = trace.sizeref;
tubeOpts.maxLength = trace.maxdisplayed;

Expand Down
2 changes: 1 addition & 1 deletion src/traces/surface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ proto.update = function(data) {
var sceneLayout = scene.fullSceneLayout;
var surface = this.surface;
var alpha = data.opacity;
var colormap = parseColorScale(data.colorscale, alpha);
var colormap = parseColorScale(data, alpha);
var scaleFactor = scene.dataScale;
var xlen = data.z[0].length;
var ylen = data._ylength;
Expand Down
4 changes: 0 additions & 4 deletions src/traces/surface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

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


module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
var i, j;

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

var surfaceColor = coerce('surfacecolor');

coerce('colorscale');

var dims = ['x', 'y', 'z'];
for(i = 0; i < 3; ++i) {

Expand Down
Binary file added test/image/baselines/gl3d_reversescale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
148 changes: 148 additions & 0 deletions test/image/mocks/gl3d_reversescale.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"data": [{
"type": "surface",
"z": [
[8.41, 3, 4],
[1, 2, 3],
[2, 43, 1]
],
"reversescale": true,
"colorbar": {
"title": {"text": "surface"},
"x": -0.15,
"len": 0.3,
"y": 0.7
}
}, {
"type":"mesh3d",
"name": "colorscale + intensity",
"x":[0, 1, 2, 0],
"y":[0, 0, 1, 2],
"z":[0, 2, 0, 1],
"i":[0, 0, 0, 1],
"j":[1, 2, 3, 2],
"k":[2, 3, 1, 3],
"colorscale": [
[0, "rgb(0, 0, 0)"],
[0.33, "rgb(255, 0, 0)"],
[0.66, "rgb(0, 255, 0)"],
[1, "rgb(0, 0, 255)"]
],
"intensity": [0, 0.33, 0.66, 1],
"reversescale": true,
"colorbar": {
"title": {"text": "mesh3d"},
"x": -0.15,
"len": 0.3,
"y": 0.4
}
}, {
"type": "streamtube",
"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],
"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],
"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],
"u": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1.8414709848078965,
1.8414709848078965,
1.8414709848078965,
1.8414709848078965,
1.8414709848078965,
1.8414709848078965,
1.8414709848078965,
1.8414709848078965,
1.8414709848078965,
1.9092974268256817,
1.9092974268256817,
1.9092974268256817,
1.9092974268256817,
1.9092974268256817,
1.9092974268256817,
1.9092974268256817,
1.9092974268256817,
1.9092974268256817
],
"v": [
1,
1,
1,
0.5403023058681398,
0.5403023058681398,
0.5403023058681398,
-0.4161468365471424,
-0.4161468365471424,
-0.4161468365471424,
1,
1,
1,
0.5403023058681398,
0.5403023058681398,
0.5403023058681398,
-0.4161468365471424,
-0.4161468365471424,
-0.4161468365471424,
1,
1,
1,
0.5403023058681398,
0.5403023058681398,
0.5403023058681398,
-0.4161468365471424,
-0.4161468365471424,
-0.4161468365471424
],
"w": [
0,
0.08865606199840186,
0.1693927420185106,
0,
0.08865606199840186,
0.1693927420185106,
0,
0.08865606199840186,
0.1693927420185106,
0,
0.08865606199840186,
0.1693927420185106,
0,
0.08865606199840186,
0.1693927420185106,
0,
0.08865606199840186,
0.1693927420185106,
0,
0.08865606199840186,
0.1693927420185106,
0,
0.08865606199840186,
0.1693927420185106,
0,
0.08865606199840186,
0.1693927420185106
],
"reversescale": true,
"colorbar": {
"title": {"text": "streamtube"},
"x": -0.15,
"len": 0.3,
"y": 0,
"yanchor": "bottom"
}
}],
"layout": {
"title": {"text": "gl3d trace with reversescale:true"},
"scene": {
"camera": {
"eye": {"x": -2, "y": -0.35, "z": 0.34}
}
}
}
}

0 comments on commit 300de29

Please sign in to comment.