diff --git a/src/traces/contour/colorbar.js b/src/traces/contour/colorbar.js index 46514b90a78..db2f1a3c64f 100644 --- a/src/traces/contour/colorbar.js +++ b/src/traces/contour/colorbar.js @@ -8,7 +8,7 @@ 'use strict'; -var extractOpts = require('../../components/colorscale').extractOpts; +var Colorscale = require('../../components/colorscale'); var makeColorMap = require('./make_color_map'); var endPlus = require('./end_plus'); @@ -20,8 +20,10 @@ function calc(gd, trace, opts) { var colorMap = makeColorMap(trace, {isColorbar: true}); if(coloring === 'heatmap') { - var cOpts = extractOpts(trace); - opts._fillgradient = trace.colorscale; + var cOpts = Colorscale.extractOpts(trace); + opts._fillgradient = cOpts.reversescale ? + Colorscale.flipScale(cOpts.colorscale) : + cOpts.colorscale; opts._zrange = [cOpts.min, cOpts.max]; } else if(coloring === 'fill') { opts._fillcolor = colorMap; diff --git a/test/image/baselines/contour_heatmap_coloring_reversescale.png b/test/image/baselines/contour_heatmap_coloring_reversescale.png new file mode 100644 index 00000000000..c6d5794d2cf Binary files /dev/null and b/test/image/baselines/contour_heatmap_coloring_reversescale.png differ diff --git a/test/image/mocks/contour_heatmap_coloring_reversescale.json b/test/image/mocks/contour_heatmap_coloring_reversescale.json new file mode 100644 index 00000000000..1237412277b --- /dev/null +++ b/test/image/mocks/contour_heatmap_coloring_reversescale.json @@ -0,0 +1,59 @@ +{ + "data": [ + { + "z": [ + [ 10, 10.625, 12.5, 15.625, 20 ], + [ 5.625, 6.25, 8.125, 11.25, 15.625 ], + [ 2.5, 3.125, 5, 8.125, 12.5 ], + [ 0.625, 1.25, 3.125, 6.25, 10.625 ], + [ 0, 0.625, 2.5, 5.625, 10 ] + ], + "x": [ -9, -6, -5, -3, -1 ], + "y": [ 0, 1, 4, 5, 7 ], + "type": "contour", + "contours": { + "coloring": "heatmap" + }, + "reversescale": true, + "colorbar": { + "len": 0.5, + "y": 1, + "yanchor": "top", + "title": {"text": "trace colorscale", "side": "right"} + } + }, + { + "z": [ + [ 10, 10.625, 12.5, 15.625, 20 ], + [ 5.625, 6.25, 8.125, 11.25, 15.625 ], + [ 2.5, 3.125, 5, 8.125, 12.5 ], + [ 0.625, 1.25, 3.125, 6.25, 10.625 ], + [ 0, 0.625, 2.5, 5.625, 10 ] + ], + "x": [ -9, -6, -5, -3, -1 ], + "y": [ 0, 1, 4, 5, 7 ], + "type": "contour", + "contours": { + "coloring": "heatmap" + }, + "coloraxis": "coloraxis", + "xaxis": "x2", + "yaxis": "y2" + } + ], + "layout": { + "grid": {"rows": 2, "columns": 1, "pattern": "independent"}, + "title": { + "text": "Setting the X and Y Coordinates in a Contour Plot + reverse scale" + }, + "coloraxis": { + "reversescale": true, + "colorbar": { + "len": 0.5, + "y": 0, + "yanchor": "bottom", + "title": {"text": "coloraxis colorscale", "side": "right"} + } + } + } +}