diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index 383f434a52a..35be62a2b7e 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -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]); diff --git a/src/traces/cone/convert.js b/src/traces/cone/convert.js index 8ef950d6bd1..ee74707a413 100644 --- a/src/traces/cone/convert.js +++ b/src/traces/cone/convert.js @@ -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]; diff --git a/src/traces/mesh3d/convert.js b/src/traces/mesh3d/convert.js index 9b2c926f738..250c480b44e 100644 --- a/src/traces/mesh3d/convert.js +++ b/src/traces/mesh3d/convert.js @@ -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); diff --git a/src/traces/streamtube/convert.js b/src/traces/streamtube/convert.js index 52488c1ea44..d663c262fb5 100644 --- a/src/traces/streamtube/convert.js +++ b/src/traces/streamtube/convert.js @@ -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; diff --git a/src/traces/surface/convert.js b/src/traces/surface/convert.js index a5f4147462e..74397d78ae5 100644 --- a/src/traces/surface/convert.js +++ b/src/traces/surface/convert.js @@ -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; diff --git a/src/traces/surface/defaults.js b/src/traces/surface/defaults.js index 9bdad26a812..54c0ffc5033 100644 --- a/src/traces/surface/defaults.js +++ b/src/traces/surface/defaults.js @@ -6,7 +6,6 @@ * LICENSE file in the root directory of this source tree. */ - 'use strict'; var Registry = require('../../registry'); @@ -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; @@ -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) { diff --git a/test/image/baselines/gl3d_reversescale.png b/test/image/baselines/gl3d_reversescale.png new file mode 100644 index 00000000000..9cfb4378f6b Binary files /dev/null and b/test/image/baselines/gl3d_reversescale.png differ diff --git a/test/image/mocks/gl3d_reversescale.json b/test/image/mocks/gl3d_reversescale.json new file mode 100644 index 00000000000..95e0ff09274 --- /dev/null +++ b/test/image/mocks/gl3d_reversescale.json @@ -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} + } + } + } +}