From 6b1b9405637793cb44e63e91929ef2a96c3abc3d Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 20 Nov 2018 15:36:10 -0500 Subject: [PATCH 01/15] initial implementation of `layout.colorscale` --- src/components/colorscale/calc.js | 6 +-- src/components/colorscale/defaults.js | 9 +++- src/plots/layout_attributes.js | 23 +++++++++ src/plots/plots.js | 3 ++ test/jasmine/tests/colorscale_test.js | 73 +++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 5 deletions(-) diff --git a/src/components/colorscale/calc.js b/src/components/colorscale/calc.js index b609b38d5da..b2af670db47 100644 --- a/src/components/colorscale/calc.js +++ b/src/components/colorscale/calc.js @@ -84,9 +84,9 @@ module.exports = function calc(trace, vals, containerStr, cLetter) { doUpdate(autoAttr, (auto !== false || (min === undefined && max === undefined))); if(container.autocolorscale) { - if(min * max < 0) scl = scales.RdBu; - else if(min >= 0) scl = scales.Reds; - else scl = scales.Blues; + if(min * max < 0) scl = container.diverging || scales.RdBu; + else if(min >= 0) scl = container.sequential || scales.Reds; + else scl = container.sequentialminus || scales.Blues; // reversescale is handled at the containerOut level doUpdate('colorscale', scl, container.reversescale ? flipScale(scl) : scl); diff --git a/src/components/colorscale/defaults.js b/src/components/colorscale/defaults.js index 459fe1bb4dc..f66c22306c3 100644 --- a/src/components/colorscale/defaults.js +++ b/src/components/colorscale/defaults.js @@ -18,7 +18,6 @@ var colorbarDefaults = require('../colorbar/defaults'); var isValidScale = require('./is_valid_scale'); var flipScale = require('./flip_scale'); - module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce, opts) { var prefix = opts.prefix, cLetter = opts.cLetter, @@ -43,7 +42,13 @@ module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce, var autoColorscaleDflt; if(sclIn !== undefined) autoColorscaleDflt = !isValidScale(sclIn); coerce(prefix + 'autocolorscale', autoColorscaleDflt); - var sclOut = coerce(prefix + 'colorscale'); + + var layoutColorscale = layout.colorscale || {}; + containerOut.diverging = layoutColorscale.diverging; + containerOut.sequential = layoutColorscale.sequential; + containerOut.sequentialminus = layoutColorscale.sequentialminus; + var dfltScl = containerOut.diverging; + var sclOut = coerce(prefix + 'colorscale', dfltScl); // reversescale is handled at the containerOut level var reverseScale = coerce(prefix + 'reversescale'); diff --git a/src/plots/layout_attributes.js b/src/plots/layout_attributes.js index 103a0b234f7..9ad9d4aa3b5 100644 --- a/src/plots/layout_attributes.js +++ b/src/plots/layout_attributes.js @@ -188,6 +188,29 @@ module.exports = { editType: 'calc', description: 'Sets the default trace colors.' }, + colorscale: { + sequential: { + valType: 'colorscale', + dflt: false, + role: 'style', + editType: 'calc', + description: 'Sets the default sequential colorscale for positive values.' + }, + sequentialminus: { + valType: 'colorscale', + dflt: false, + role: 'style', + editType: 'calc', + description: 'Sets the default sequential colorscale for negative values.' + }, + diverging: { + valType: 'colorscale', + dflt: false, + role: 'style', + editType: 'calc', + description: 'Sets the default diverging colorscale.' + } + }, datarevision: { valType: 'any', role: 'info', diff --git a/src/plots/plots.js b/src/plots/plots.js index 7d8947ff6b9..e348af40881 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -1362,6 +1362,9 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) { coerce('hidesources'); coerce('colorway'); + coerce('colorscale.sequential'); + coerce('colorscale.sequentialminus'); + coerce('colorscale.diverging'); coerce('datarevision'); diff --git a/test/jasmine/tests/colorscale_test.js b/test/jasmine/tests/colorscale_test.js index 2bfa115a75a..154cb2f471d 100644 --- a/test/jasmine/tests/colorscale_test.js +++ b/test/jasmine/tests/colorscale_test.js @@ -296,6 +296,41 @@ describe('Test colorscale:', function() { handleDefaults(traceIn, traceOut, layout, coerce, opts); expect(traceOut.showscale).toBe(false); }); + + it('should use global colorscale.diverging if no colorscale is specified', function() { + traceIn = { + zmin: -10, + zmax: 10 + }; + var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + var layout2 = { + colorscale: { + diverging: divergingScale + }, + _dfltTitle: {colorbar: 'cb'} + }; + handleDefaults(traceIn, traceOut, layout2, coerce, opts); + expect(traceOut.colorscale).toBe(divergingScale); + }); + + it('should not use layout colorscale.diverging if colorscale is specified', function() { + var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + var traceColorscale = [[0, 'rgb(128,128,128)'], [1, 'rgb(255,255,255)']]; + traceIn = { + zmin: -10, + zmax: 10, + colorscale: traceColorscale + }; + + var layout2 = { + colorscale: { + diverging: divergingScale + }, + _dfltTitle: {colorbar: 'cb'} + }; + handleDefaults(traceIn, traceOut, layout2, coerce, opts); + expect(traceOut.colorscale).toBe(traceColorscale); + }); }); describe('handleDefaults (scatter-like version)', function() { @@ -348,6 +383,41 @@ describe('Test colorscale:', function() { handleDefaults(traceIn, traceOut, layout, coerce, opts); expect(traceOut.marker.showscale).toBe(true); }); + + it('should use layout colorscale.diverging if no colorscale is specified', function() { + traceIn = { + zmin: -10, + zmax: 10 + }; + var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + var layout2 = { + colorscale: { + diverging: divergingScale + }, + _dfltTitle: {colorbar: 'cb'} + }; + handleDefaults(traceIn, traceOut, layout2, coerce, opts); + expect(traceOut.marker.colorscale).toBe(divergingScale); + }); + + it('should not use layout colorscale.diverging if colorscale is specified', function() { + var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + var traceColorscale = [[0, 'rgb(128,128,128)'], [1, 'rgb(255,255,255)']]; + traceIn = { + marker: { + colorscale: traceColorscale + } + }; + + var layout2 = { + colorscale: { + diverging: divergingScale + }, + _dfltTitle: {colorbar: 'cb'} + }; + handleDefaults(traceIn, traceOut, layout2, coerce, opts); + expect(traceOut.marker.colorscale).toBe(traceColorscale); + }); }); describe('calc', function() { @@ -366,6 +436,7 @@ describe('Test colorscale:', function() { autocolorscale: true, _input: {autocolorscale: true} }; + z = [[0, -1.5], [-2, -10]]; calcColorscale(trace, z, '', 'z'); expect(trace.autocolorscale).toBe(true); @@ -376,6 +447,8 @@ describe('Test colorscale:', function() { trace = { type: 'heatmap', z: [[0, -1.5], [-2, -10]], + zmin: -10, + zmax: 0, autocolorscale: true, _input: {} }; From 0e98c5b0898b2ca4c8f7709be7512527da6c1246 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 20 Nov 2018 16:23:29 -0500 Subject: [PATCH 02/15] fix editType --- src/plots/layout_attributes.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plots/layout_attributes.js b/src/plots/layout_attributes.js index 9ad9d4aa3b5..3fff07b0e5c 100644 --- a/src/plots/layout_attributes.js +++ b/src/plots/layout_attributes.js @@ -189,6 +189,7 @@ module.exports = { description: 'Sets the default trace colors.' }, colorscale: { + editType: 'calc', sequential: { valType: 'colorscale', dflt: false, From 6e61f3bb52934c16b063619b67ca8ed183f02ec4 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 20 Nov 2018 16:32:37 -0500 Subject: [PATCH 03/15] fix parcoords, fix default colorscale --- src/components/colorscale/defaults.js | 4 +++- test/jasmine/tests/parcoords_test.js | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/colorscale/defaults.js b/src/components/colorscale/defaults.js index f66c22306c3..361ce48d56b 100644 --- a/src/components/colorscale/defaults.js +++ b/src/components/colorscale/defaults.js @@ -48,7 +48,9 @@ module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce, containerOut.sequential = layoutColorscale.sequential; containerOut.sequentialminus = layoutColorscale.sequentialminus; var dfltScl = containerOut.diverging; - var sclOut = coerce(prefix + 'colorscale', dfltScl); + var sclOut; + if(dfltScl) sclOut = coerce(prefix + 'colorscale', dfltScl); + else sclOut = coerce(prefix + 'colorscale'); // reversescale is handled at the containerOut level var reverseScale = coerce(prefix + 'reversescale'); diff --git a/test/jasmine/tests/parcoords_test.js b/test/jasmine/tests/parcoords_test.js index 3a8313c1d65..b568c9d2921 100644 --- a/test/jasmine/tests/parcoords_test.js +++ b/test/jasmine/tests/parcoords_test.js @@ -141,7 +141,10 @@ describe('parcoords initialization tests', function() { cauto: true, autocolorscale: false, reversescale: false, - showscale: false + showscale: false, + diverging: undefined, + sequential: undefined, + sequentialminus: undefined }); }); @@ -278,6 +281,9 @@ describe('parcoords initialization tests', function() { ] })); + delete(fullTrace.line.diverging); + delete(fullTrace.line.sequential); + delete(fullTrace.line.sequentialminus); expect(fullTrace.line).toEqual({ color: [35, 63, 21, 42], colorscale: attributes.line.colorscale.dflt, From f5bcb715fb489392d9af1609364baa7fc796d041 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 20 Nov 2018 17:12:13 -0500 Subject: [PATCH 04/15] do not coerce layout.colorscale if not specified --- src/plots/plots.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index e348af40881..593141879c8 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -1362,9 +1362,11 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) { coerce('hidesources'); coerce('colorway'); - coerce('colorscale.sequential'); - coerce('colorscale.sequentialminus'); - coerce('colorscale.diverging'); + if(layoutIn.colorscale) { + if(layoutIn.colorscale.sequential) coerce('colorscale.sequential'); + if(layoutIn.colorscale.sequentialminus) coerce('colorscale.sequentialminus'); + if(layoutIn.colorscale.diverging) coerce('colorscale.diverging'); + } coerce('datarevision'); From a299ce025c678a7eb80c6110fdb53bb321559d59 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 21 Nov 2018 12:52:43 -0500 Subject: [PATCH 05/15] move layout colorscale attributes into its own file --- src/components/colorscale/index.js | 2 + .../colorscale/layout_attributes.js | 37 +++++++++++++++++++ src/plots/layout_attributes.js | 26 +------------ 3 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 src/components/colorscale/layout_attributes.js diff --git a/src/components/colorscale/index.js b/src/components/colorscale/index.js index 33b0019df61..e974e488232 100644 --- a/src/components/colorscale/index.js +++ b/src/components/colorscale/index.js @@ -15,6 +15,8 @@ exports.defaultScale = require('./default_scale'); exports.attributes = require('./attributes'); +exports.layoutAttributes = require('./layout_attributes'); + exports.handleDefaults = require('./defaults'); exports.calc = require('./calc'); diff --git a/src/components/colorscale/layout_attributes.js b/src/components/colorscale/layout_attributes.js new file mode 100644 index 00000000000..45167ab7a37 --- /dev/null +++ b/src/components/colorscale/layout_attributes.js @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2018, Plotly, Inc. + * All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + +'use strict'; + +var scales = require('./scales'); + +module.exports = { + editType: 'calc', + sequential: { + valType: 'colorscale', + dflt: scales.Reds, + role: 'style', + editType: 'calc', + description: 'Sets the default sequential colorscale for positive values.' + }, + sequentialminus: { + valType: 'colorscale', + dflt: scales.Blues, + role: 'style', + editType: 'calc', + description: 'Sets the default sequential colorscale for negative values.' + }, + diverging: { + valType: 'colorscale', + dflt: scales.RdBu, + role: 'style', + editType: 'calc', + description: 'Sets the default diverging colorscale.' + } +}; diff --git a/src/plots/layout_attributes.js b/src/plots/layout_attributes.js index 3fff07b0e5c..d8428800dba 100644 --- a/src/plots/layout_attributes.js +++ b/src/plots/layout_attributes.js @@ -10,6 +10,7 @@ var fontAttrs = require('./font_attributes'); var colorAttrs = require('../components/color/attributes'); +var colorscaleAttrs = require('../components/colorscale/layout_attributes'); var globalFont = fontAttrs({ editType: 'calc', @@ -188,30 +189,7 @@ module.exports = { editType: 'calc', description: 'Sets the default trace colors.' }, - colorscale: { - editType: 'calc', - sequential: { - valType: 'colorscale', - dflt: false, - role: 'style', - editType: 'calc', - description: 'Sets the default sequential colorscale for positive values.' - }, - sequentialminus: { - valType: 'colorscale', - dflt: false, - role: 'style', - editType: 'calc', - description: 'Sets the default sequential colorscale for negative values.' - }, - diverging: { - valType: 'colorscale', - dflt: false, - role: 'style', - editType: 'calc', - description: 'Sets the default diverging colorscale.' - } - }, + colorscale: colorscaleAttrs, datarevision: { valType: 'any', role: 'info', From 2a20414d113c59d22ed992a3ffe1f018850ca9a2 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 21 Nov 2018 14:10:45 -0500 Subject: [PATCH 06/15] update description for layout.colorscale attributes --- .../colorscale/layout_attributes.js | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/colorscale/layout_attributes.js b/src/components/colorscale/layout_attributes.js index 45167ab7a37..96ce49a4682 100644 --- a/src/components/colorscale/layout_attributes.js +++ b/src/components/colorscale/layout_attributes.js @@ -11,27 +11,37 @@ var scales = require('./scales'); +var msg = 'Note that `autocolorscale` must be true for this attribute to work.'; module.exports = { editType: 'calc', sequential: { valType: 'colorscale', - dflt: scales.Reds, + dflt: 'Reds', role: 'style', editType: 'calc', - description: 'Sets the default sequential colorscale for positive values.' + description: [ + 'Sets the default sequential colorscale for positive values.', + msg + ].join(' ') }, sequentialminus: { valType: 'colorscale', - dflt: scales.Blues, + dflt: 'Blues', role: 'style', editType: 'calc', - description: 'Sets the default sequential colorscale for negative values.' + description: [ + 'Sets the default sequential colorscale for negative values.', + msg + ].join(' ') }, diverging: { valType: 'colorscale', - dflt: scales.RdBu, + dflt: 'RdBu', role: 'style', editType: 'calc', - description: 'Sets the default diverging colorscale.' + description: [ + 'Sets the default diverging colorscale.', + msg + ].join(' ') } }; From 2460fc3a83cc190c5530364dddb591c7c6e1397f Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 21 Nov 2018 14:20:30 -0500 Subject: [PATCH 07/15] fix lint --- src/components/colorscale/layout_attributes.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/colorscale/layout_attributes.js b/src/components/colorscale/layout_attributes.js index 96ce49a4682..726de053e3f 100644 --- a/src/components/colorscale/layout_attributes.js +++ b/src/components/colorscale/layout_attributes.js @@ -1,16 +1,13 @@ /** - * Copyright 2012-2018, Plotly, Inc. - * All rights reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - +* Copyright 2012-2018, Plotly, Inc. +* All rights reserved. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +*/ 'use strict'; -var scales = require('./scales'); - var msg = 'Note that `autocolorscale` must be true for this attribute to work.'; module.exports = { editType: 'calc', From 0c13592b65aed4e728efbbdcd763b17ea3a52b55 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 21 Nov 2018 15:39:23 -0500 Subject: [PATCH 08/15] change colorscaleCalc's signature, cleanup code --- src/components/colorscale/calc.js | 12 +++++---- src/components/colorscale/defaults.js | 11 ++------ src/components/colorscale/index.js | 6 +++++ .../colorscale/layout_attributes.js | 8 +++--- src/components/colorscale/layout_defaults.js | 26 +++++++++++++++++++ src/core.js | 3 ++- src/plots/plots.js | 5 ---- src/traces/bar/calc.js | 12 +++++++-- src/traces/barpolar/calc.js | 12 +++++++-- src/traces/choropleth/calc.js | 6 ++++- src/traces/cone/calc.js | 6 ++++- src/traces/contourcarpet/calc.js | 6 ++++- src/traces/heatmap/calc.js | 6 ++++- src/traces/mesh3d/calc.js | 6 ++++- src/traces/parcats/calc.js | 6 ++++- src/traces/parcoords/calc.js | 6 ++++- src/traces/scatter/calc.js | 2 +- src/traces/scatter/colorscale_calc.js | 20 +++++++++++--- src/traces/scatter3d/calc.js | 2 +- src/traces/scattercarpet/calc.js | 2 +- src/traces/scattergeo/calc.js | 2 +- src/traces/scattergl/index.js | 2 +- src/traces/scatterpolar/calc.js | 2 +- src/traces/scatterpolargl/index.js | 2 +- src/traces/scatterternary/calc.js | 2 +- src/traces/splom/index.js | 4 +-- src/traces/streamtube/calc.js | 6 ++++- src/traces/surface/calc.js | 12 +++++++-- 28 files changed, 144 insertions(+), 51 deletions(-) create mode 100644 src/components/colorscale/layout_defaults.js diff --git a/src/components/colorscale/calc.js b/src/components/colorscale/calc.js index b2af670db47..4232c8bc479 100644 --- a/src/components/colorscale/calc.js +++ b/src/components/colorscale/calc.js @@ -11,11 +11,13 @@ var Lib = require('../../lib'); -var scales = require('./scales'); var flipScale = require('./flip_scale'); -module.exports = function calc(trace, vals, containerStr, cLetter) { +module.exports = function calc(gd, trace, opts) { + var vals = opts.vals; + var containerStr = opts.containerStr; + var cLetter = opts.cLetter; var container = trace; var inputContainer = trace._input; var fullInputContainer = trace._fullInput; @@ -84,9 +86,9 @@ module.exports = function calc(trace, vals, containerStr, cLetter) { doUpdate(autoAttr, (auto !== false || (min === undefined && max === undefined))); if(container.autocolorscale) { - if(min * max < 0) scl = container.diverging || scales.RdBu; - else if(min >= 0) scl = container.sequential || scales.Reds; - else scl = container.sequentialminus || scales.Blues; + if(min * max < 0) scl = gd._fullLayout.colorscale.diverging; + else if(min >= 0) scl = gd._fullLayout.colorscale.sequential; + else scl = gd._fullLayout.colorscale.sequentialminus; // reversescale is handled at the containerOut level doUpdate('colorscale', scl, container.reversescale ? flipScale(scl) : scl); diff --git a/src/components/colorscale/defaults.js b/src/components/colorscale/defaults.js index 361ce48d56b..459fe1bb4dc 100644 --- a/src/components/colorscale/defaults.js +++ b/src/components/colorscale/defaults.js @@ -18,6 +18,7 @@ var colorbarDefaults = require('../colorbar/defaults'); var isValidScale = require('./is_valid_scale'); var flipScale = require('./flip_scale'); + module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce, opts) { var prefix = opts.prefix, cLetter = opts.cLetter, @@ -42,15 +43,7 @@ module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce, var autoColorscaleDflt; if(sclIn !== undefined) autoColorscaleDflt = !isValidScale(sclIn); coerce(prefix + 'autocolorscale', autoColorscaleDflt); - - var layoutColorscale = layout.colorscale || {}; - containerOut.diverging = layoutColorscale.diverging; - containerOut.sequential = layoutColorscale.sequential; - containerOut.sequentialminus = layoutColorscale.sequentialminus; - var dfltScl = containerOut.diverging; - var sclOut; - if(dfltScl) sclOut = coerce(prefix + 'colorscale', dfltScl); - else sclOut = coerce(prefix + 'colorscale'); + var sclOut = coerce(prefix + 'colorscale'); // reversescale is handled at the containerOut level var reverseScale = coerce(prefix + 'reversescale'); diff --git a/src/components/colorscale/index.js b/src/components/colorscale/index.js index e974e488232..d17e8f2305b 100644 --- a/src/components/colorscale/index.js +++ b/src/components/colorscale/index.js @@ -9,6 +9,10 @@ 'use strict'; +exports.moduleType = 'component'; + +exports.name = 'colorscale'; + exports.scales = require('./scales'); exports.defaultScale = require('./default_scale'); @@ -17,6 +21,8 @@ exports.attributes = require('./attributes'); exports.layoutAttributes = require('./layout_attributes'); +exports.supplyLayoutDefaults = require('./layout_defaults'); + exports.handleDefaults = require('./defaults'); exports.calc = require('./calc'); diff --git a/src/components/colorscale/layout_attributes.js b/src/components/colorscale/layout_attributes.js index 726de053e3f..9285951850d 100644 --- a/src/components/colorscale/layout_attributes.js +++ b/src/components/colorscale/layout_attributes.js @@ -8,12 +8,14 @@ 'use strict'; +var scales = require('./scales'); + var msg = 'Note that `autocolorscale` must be true for this attribute to work.'; module.exports = { editType: 'calc', sequential: { valType: 'colorscale', - dflt: 'Reds', + dflt: scales.Reds, role: 'style', editType: 'calc', description: [ @@ -23,7 +25,7 @@ module.exports = { }, sequentialminus: { valType: 'colorscale', - dflt: 'Blues', + dflt: scales.Blues, role: 'style', editType: 'calc', description: [ @@ -33,7 +35,7 @@ module.exports = { }, diverging: { valType: 'colorscale', - dflt: 'RdBu', + dflt: scales.RdBu, role: 'style', editType: 'calc', description: [ diff --git a/src/components/colorscale/layout_defaults.js b/src/components/colorscale/layout_defaults.js new file mode 100644 index 00000000000..bbc12580614 --- /dev/null +++ b/src/components/colorscale/layout_defaults.js @@ -0,0 +1,26 @@ +/** +* Copyright 2012-2018, Plotly, Inc. +* All rights reserved. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +*/ + + +'use strict'; + +var Lib = require('../../lib'); +var colorscaleAttrs = require('./layout_attributes'); +var Template = require('../../plot_api/plot_template'); + +module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) { + var colorscaleIn = layoutIn.colorscale; + var colorscaleOut = Template.newContainer(layoutOut, 'colorscale'); + function coerce(attr, dflt) { + return Lib.coerce(colorscaleIn, colorscaleOut, colorscaleAttrs, attr, dflt); + } + + coerce('sequential'); + coerce('sequentialminus'); + coerce('diverging'); +}; diff --git a/src/core.js b/src/core.js index 1025c37d4a7..6a8ad04bba7 100644 --- a/src/core.js +++ b/src/core.js @@ -53,7 +53,8 @@ register([ require('./components/rangeslider'), require('./components/rangeselector'), require('./components/grid'), - require('./components/errorbars') + require('./components/errorbars'), + require('./components/colorscale') ]); // locales en and en-US are required for default behavior diff --git a/src/plots/plots.js b/src/plots/plots.js index 593141879c8..7d8947ff6b9 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -1362,11 +1362,6 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) { coerce('hidesources'); coerce('colorway'); - if(layoutIn.colorscale) { - if(layoutIn.colorscale.sequential) coerce('colorscale.sequential'); - if(layoutIn.colorscale.sequentialminus) coerce('colorscale.sequentialminus'); - if(layoutIn.colorscale.diverging) coerce('colorscale.diverging'); - } coerce('datarevision'); diff --git a/src/traces/bar/calc.js b/src/traces/bar/calc.js index b3c5775d5e0..6c2ec1ecb19 100644 --- a/src/traces/bar/calc.js +++ b/src/traces/bar/calc.js @@ -42,10 +42,18 @@ module.exports = function calc(gd, trace) { // auto-z and autocolorscale if applicable if(hasColorscale(trace, 'marker')) { - colorscaleCalc(trace, trace.marker.color, 'marker', 'c'); + colorscaleCalc(gd, trace, { + vals: trace.marker.color, + containerStr: 'marker', + cLetter: 'c' + }); } if(hasColorscale(trace, 'marker.line')) { - colorscaleCalc(trace, trace.marker.line.color, 'marker.line', 'c'); + colorscaleCalc(gd, trace, { + vals: trace.marker.line.color, + containerStr: 'marker.line', + cLetter: 'c' + }); } arraysToCalcdata(cd, trace); diff --git a/src/traces/barpolar/calc.js b/src/traces/barpolar/calc.js index 4c9876ef5c2..7181fccca41 100644 --- a/src/traces/barpolar/calc.js +++ b/src/traces/barpolar/calc.js @@ -53,10 +53,18 @@ function calc(gd, trace) { } if(hasColorscale(trace, 'marker')) { - colorscaleCalc(trace, trace.marker.color, 'marker', 'c'); + colorscaleCalc(gd, trace, { + vals: trace.marker.color, + containerStr: 'marker', + cLetter: 'c' + }); } if(hasColorscale(trace, 'marker.line')) { - colorscaleCalc(trace, trace.marker.line.color, 'marker.line', 'c'); + colorscaleCalc(gd, trace, { + vals: trace.marker.line.color, + containerStr: 'marker.line', + cLetter: 'c' + }); } arraysToCalcdata(cd, trace); diff --git a/src/traces/choropleth/calc.js b/src/traces/choropleth/calc.js index b9a88430701..4f71dcb2886 100644 --- a/src/traces/choropleth/calc.js +++ b/src/traces/choropleth/calc.js @@ -30,7 +30,11 @@ module.exports = function calc(gd, trace) { } arraysToCalcdata(calcTrace, trace); - colorscaleCalc(trace, trace.z, '', 'z'); + colorscaleCalc(gd, trace, { + vals: trace.z, + containerStr: '', + cLetter: 'z' + }); calcSelection(calcTrace, trace); return calcTrace; diff --git a/src/traces/cone/calc.js b/src/traces/cone/calc.js index 2c0e5907326..64b36de9453 100644 --- a/src/traces/cone/calc.js +++ b/src/traces/cone/calc.js @@ -34,5 +34,9 @@ module.exports = function calc(gd, trace) { trace._len = len; trace._normMax = normMax; - colorscaleCalc(trace, [normMin, normMax], '', 'c'); + colorscaleCalc(gd, trace, { + vals: [normMin, normMax], + containerStr: '', + cLetter: 'c' + }); }; diff --git a/src/traces/contourcarpet/calc.js b/src/traces/contourcarpet/calc.js index 0e02e252ff9..1a645d5f261 100644 --- a/src/traces/contourcarpet/calc.js +++ b/src/traces/contourcarpet/calc.js @@ -101,7 +101,11 @@ function heatmappishCalc(gd, trace) { if(trace.contours.type === 'levels' && trace.contours.coloring !== 'none') { // auto-z and autocolorscale if applicable - colorscaleCalc(trace, z, '', 'z'); + colorscaleCalc(gd, trace, { + vals: z, + containerStr: '', + cLetter: 'z' + }); } return [cd0]; diff --git a/src/traces/heatmap/calc.js b/src/traces/heatmap/calc.js index 37477db0315..86ebf03aa83 100644 --- a/src/traces/heatmap/calc.js +++ b/src/traces/heatmap/calc.js @@ -146,7 +146,11 @@ module.exports = function calc(gd, trace) { // auto-z and autocolorscale if applicable if(!isContour || trace.contours.type !== 'constraint') { - colorscaleCalc(trace, z, '', 'z'); + colorscaleCalc(gd, trace, { + vals: z, + containerStr: '', + cLetter: 'z' + }); } if(isContour && trace.contours && trace.contours.coloring === 'heatmap') { diff --git a/src/traces/mesh3d/calc.js b/src/traces/mesh3d/calc.js index d5f133ee6b6..ffb18a71b38 100644 --- a/src/traces/mesh3d/calc.js +++ b/src/traces/mesh3d/calc.js @@ -12,6 +12,10 @@ var colorscaleCalc = require('../../components/colorscale/calc'); module.exports = function calc(gd, trace) { if(trace.intensity) { - colorscaleCalc(trace, trace.intensity, '', 'c'); + colorscaleCalc(gd, trace, { + vals: trace.intensity, + containerStr: '', + cLetter: 'c' + }); } }; diff --git a/src/traces/parcats/calc.js b/src/traces/parcats/calc.js index 70b8f8a277f..07ea14d3794 100644 --- a/src/traces/parcats/calc.js +++ b/src/traces/parcats/calc.js @@ -73,7 +73,11 @@ module.exports = function calc(gd, trace) { // Process colorscale if(line) { if(hasColorscale(trace, 'line')) { - colorscaleCalc(trace, trace.line.color, 'line', 'c'); + colorscaleCalc(gd, trace, { + vals: trace.line.color, + containerStr: 'line', + cLetter: 'c' + }); } markerColorscale = Drawing.tryColorscale(line); } else { diff --git a/src/traces/parcoords/calc.js b/src/traces/parcoords/calc.js index d584e66225d..c9ce1f7c7a0 100644 --- a/src/traces/parcoords/calc.js +++ b/src/traces/parcoords/calc.js @@ -19,7 +19,11 @@ module.exports = function calc(gd, trace) { var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]]; if(hasColorscale(trace, 'line')) { - calcColorscale(trace, color, 'line', 'c'); + calcColorscale(gd, trace, { + vals: color, + containerStr: 'line', + cLetter: 'c' + }); } return wrap({ diff --git a/src/traces/scatter/calc.js b/src/traces/scatter/calc.js index d04c62ca541..d745433dbca 100644 --- a/src/traces/scatter/calc.js +++ b/src/traces/scatter/calc.js @@ -87,7 +87,7 @@ function calc(gd, trace) { } arraysToCalcdata(cd, trace); - calcColorscale(trace); + calcColorscale(gd, trace); calcSelection(cd, trace); if(stackGroupOpts) { diff --git a/src/traces/scatter/colorscale_calc.js b/src/traces/scatter/colorscale_calc.js index 20c52101a83..69d225eb7ae 100644 --- a/src/traces/scatter/colorscale_calc.js +++ b/src/traces/scatter/colorscale_calc.js @@ -15,17 +15,29 @@ var calcColorscale = require('../../components/colorscale/calc'); var subTypes = require('./subtypes'); -module.exports = function calcMarkerColorscale(trace) { +module.exports = function calcMarkerColorscale(gd, trace) { if(subTypes.hasLines(trace) && hasColorscale(trace, 'line')) { - calcColorscale(trace, trace.line.color, 'line', 'c'); + calcColorscale(gd, trace, { + vals: trace.line.color, + containerStr: 'line', + cLetter: 'c' + }); } if(subTypes.hasMarkers(trace)) { if(hasColorscale(trace, 'marker')) { - calcColorscale(trace, trace.marker.color, 'marker', 'c'); + calcColorscale(gd, trace, { + vals: trace.marker.color, + containerStr: 'marker', + cLetter: 'c' + }); } if(hasColorscale(trace, 'marker.line')) { - calcColorscale(trace, trace.marker.line.color, 'marker.line', 'c'); + calcColorscale(gd, trace, { + vals: trace.marker.line.color, + containerStr: 'marker.line', + cLetter: 'c' + }); } } }; diff --git a/src/traces/scatter3d/calc.js b/src/traces/scatter3d/calc.js index e8235d82598..9f2fa358d49 100644 --- a/src/traces/scatter3d/calc.js +++ b/src/traces/scatter3d/calc.js @@ -21,7 +21,7 @@ module.exports = function calc(gd, trace) { var cd = [{x: false, y: false, trace: trace, t: {}}]; arraysToCalcdata(cd, trace); - calcColorscales(trace); + calcColorscales(gd, trace); return cd; }; diff --git a/src/traces/scattercarpet/calc.js b/src/traces/scattercarpet/calc.js index d3ea17ff846..48c1ae81691 100644 --- a/src/traces/scattercarpet/calc.js +++ b/src/traces/scattercarpet/calc.js @@ -50,7 +50,7 @@ module.exports = function calc(gd, trace) { cd[0].trace = trace; calcMarkerSize(trace, serieslen); - calcColorscale(trace); + calcColorscale(gd, trace); arraysToCalcdata(cd, trace); calcSelection(cd, trace); diff --git a/src/traces/scattergeo/calc.js b/src/traces/scattergeo/calc.js index af3af25236b..df31edbe330 100644 --- a/src/traces/scattergeo/calc.js +++ b/src/traces/scattergeo/calc.js @@ -39,7 +39,7 @@ module.exports = function calc(gd, trace) { } arraysToCalcdata(calcTrace, trace); - calcMarkerColorscale(trace); + calcMarkerColorscale(gd, trace); calcSelection(calcTrace, trace); if(len) { diff --git a/src/traces/scattergl/index.js b/src/traces/scattergl/index.js index f6c2ba9be1b..ae16aa7e7fb 100644 --- a/src/traces/scattergl/index.js +++ b/src/traces/scattergl/index.js @@ -84,7 +84,7 @@ function calc(gd, trace) { } // create scene options and scene - calcColorscales(trace); + calcColorscales(gd, trace); var opts = sceneOptions(gd, subplot, trace, positions, x, y); var scene = sceneUpdate(gd, subplot); diff --git a/src/traces/scatterpolar/calc.js b/src/traces/scatterpolar/calc.js index 69d1cd55600..14e70964bb4 100644 --- a/src/traces/scatterpolar/calc.js +++ b/src/traces/scatterpolar/calc.js @@ -45,7 +45,7 @@ module.exports = function calc(gd, trace) { var ppad = calcMarkerSize(trace, len); trace._extremes.x = Axes.findExtremes(radialAxis, rArray, {ppad: ppad}); - calcColorscale(trace); + calcColorscale(gd, trace); arraysToCalcdata(cd, trace); calcSelection(cd, trace); diff --git a/src/traces/scatterpolargl/index.js b/src/traces/scatterpolargl/index.js index 8118e3f2622..630904b668c 100644 --- a/src/traces/scatterpolargl/index.js +++ b/src/traces/scatterpolargl/index.js @@ -38,7 +38,7 @@ function calc(gd, trace) { stash.r = rArray; stash.theta = thetaArray; - calcColorscales(trace); + calcColorscales(gd, trace); // only compute 'style' options in calc, as position options // depend on the radial range and must be set in plot diff --git a/src/traces/scatterternary/calc.js b/src/traces/scatterternary/calc.js index e7a4be1b52e..f9316651016 100644 --- a/src/traces/scatterternary/calc.js +++ b/src/traces/scatterternary/calc.js @@ -72,7 +72,7 @@ module.exports = function calc(gd, trace) { } calcMarkerSize(trace, serieslen); - calcColorscale(trace); + calcColorscale(gd, trace); arraysToCalcdata(cd, trace); calcSelection(cd, trace); diff --git a/src/traces/splom/index.js b/src/traces/splom/index.js index ab74c2a3e79..a8c8cfbeb8d 100644 --- a/src/traces/splom/index.js +++ b/src/traces/splom/index.js @@ -80,7 +80,7 @@ function calc(gd, trace) { } } - calcColorscales(trace); + calcColorscales(gd, trace); Lib.extendFlat(opts, convertMarkerStyle(trace)); var visibleLength = cdata.length; @@ -310,7 +310,7 @@ function editStyle(gd, cd0) { var scene = gd._fullLayout._splomScenes[trace.uid]; if(scene) { - calcColorscales(trace); + calcColorscales(gd, trace); Lib.extendFlat(scene.matrixOptions, convertMarkerStyle(trace)); // TODO [un]selected styles? diff --git a/src/traces/streamtube/calc.js b/src/traces/streamtube/calc.js index 1ba591d3918..c5bc6a20bcf 100644 --- a/src/traces/streamtube/calc.js +++ b/src/traces/streamtube/calc.js @@ -43,7 +43,11 @@ module.exports = function calc(gd, trace) { normMin = Math.min(normMin, norm); } - colorscaleCalc(trace, [normMin, normMax], '', 'c'); + colorscaleCalc(gd, trace, { + vals: [normMin, normMax], + containerStr: '', + cLetter: 'c' + }); var xMax = -Infinity; var xMin = Infinity; diff --git a/src/traces/surface/calc.js b/src/traces/surface/calc.js index e838f898e6d..593cd05ddc6 100644 --- a/src/traces/surface/calc.js +++ b/src/traces/surface/calc.js @@ -15,8 +15,16 @@ var colorscaleCalc = require('../../components/colorscale/calc'); // Compute auto-z and autocolorscale if applicable module.exports = function calc(gd, trace) { if(trace.surfacecolor) { - colorscaleCalc(trace, trace.surfacecolor, '', 'c'); + colorscaleCalc(gd, trace, { + vals: trace.surfacecolor, + containerStr: '', + cLetter: 'c' + }); } else { - colorscaleCalc(trace, trace.z, '', 'c'); + colorscaleCalc(gd, trace, { + vals: trace.z, + containerStr: '', + cLetter: 'c' + }); } }; From 93ce241abdbc912022e1bed1f999701ea4b68cc0 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 21 Nov 2018 17:56:45 -0500 Subject: [PATCH 09/15] update colorscale tests to provide a layout object to calcColorscale --- test/jasmine/assets/supply_defaults.js | 4 + test/jasmine/tests/colorscale_test.js | 103 ++++++------------------- 2 files changed, 29 insertions(+), 78 deletions(-) diff --git a/test/jasmine/assets/supply_defaults.js b/test/jasmine/assets/supply_defaults.js index 249b85cecf1..6d42aca0aca 100644 --- a/test/jasmine/assets/supply_defaults.js +++ b/test/jasmine/assets/supply_defaults.js @@ -2,6 +2,10 @@ var Plots = require('@src/plots/plots'); +// The following is used to fill up the Registry module +/* eslint-ignore */ +var Plotly = require('@lib'); + /** * supplyDefaults that fills in necessary _context */ diff --git a/test/jasmine/tests/colorscale_test.js b/test/jasmine/tests/colorscale_test.js index 154cb2f471d..cedf8f1a0e4 100644 --- a/test/jasmine/tests/colorscale_test.js +++ b/test/jasmine/tests/colorscale_test.js @@ -4,6 +4,18 @@ var Plots = require('@src/plots/plots'); var Heatmap = require('@src/traces/heatmap'); var Scatter = require('@src/traces/scatter'); +var supplyAllDefaults = require('../assets/supply_defaults'); + +function _supply(trace, layout) { + var gd = { + data: [trace], + layout: layout || {} + }; + + supplyAllDefaults(gd); + + return gd; +} describe('Test colorscale:', function() { 'use strict'; @@ -296,41 +308,6 @@ describe('Test colorscale:', function() { handleDefaults(traceIn, traceOut, layout, coerce, opts); expect(traceOut.showscale).toBe(false); }); - - it('should use global colorscale.diverging if no colorscale is specified', function() { - traceIn = { - zmin: -10, - zmax: 10 - }; - var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; - var layout2 = { - colorscale: { - diverging: divergingScale - }, - _dfltTitle: {colorbar: 'cb'} - }; - handleDefaults(traceIn, traceOut, layout2, coerce, opts); - expect(traceOut.colorscale).toBe(divergingScale); - }); - - it('should not use layout colorscale.diverging if colorscale is specified', function() { - var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; - var traceColorscale = [[0, 'rgb(128,128,128)'], [1, 'rgb(255,255,255)']]; - traceIn = { - zmin: -10, - zmax: 10, - colorscale: traceColorscale - }; - - var layout2 = { - colorscale: { - diverging: divergingScale - }, - _dfltTitle: {colorbar: 'cb'} - }; - handleDefaults(traceIn, traceOut, layout2, coerce, opts); - expect(traceOut.colorscale).toBe(traceColorscale); - }); }); describe('handleDefaults (scatter-like version)', function() { @@ -384,61 +361,28 @@ describe('Test colorscale:', function() { expect(traceOut.marker.showscale).toBe(true); }); - it('should use layout colorscale.diverging if no colorscale is specified', function() { - traceIn = { - zmin: -10, - zmax: 10 - }; - var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; - var layout2 = { - colorscale: { - diverging: divergingScale - }, - _dfltTitle: {colorbar: 'cb'} - }; - handleDefaults(traceIn, traceOut, layout2, coerce, opts); - expect(traceOut.marker.colorscale).toBe(divergingScale); - }); - - it('should not use layout colorscale.diverging if colorscale is specified', function() { - var divergingScale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; - var traceColorscale = [[0, 'rgb(128,128,128)'], [1, 'rgb(255,255,255)']]; - traceIn = { - marker: { - colorscale: traceColorscale - } - }; - - var layout2 = { - colorscale: { - diverging: divergingScale - }, - _dfltTitle: {colorbar: 'cb'} - }; - handleDefaults(traceIn, traceOut, layout2, coerce, opts); - expect(traceOut.marker.colorscale).toBe(traceColorscale); - }); }); describe('calc', function() { var calcColorscale = Colorscale.calc; var trace, z; + var gd; beforeEach(function() { trace = {}; z = {}; + gd = {}; }); it('should be RdBuNeg when autocolorscale and z <= 0', function() { trace = { type: 'heatmap', - z: [[0, -1.5], [-2, -10]], + z: [[-0, -1.5], [-2, -10]], autocolorscale: true, _input: {autocolorscale: true} }; - - z = [[0, -1.5], [-2, -10]]; - calcColorscale(trace, z, '', 'z'); + gd = _supply(trace); + calcColorscale(gd, trace, {vals: trace.z, containerStr: '', cLetter: 'z'}); expect(trace.autocolorscale).toBe(true); expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']); }); @@ -452,8 +396,8 @@ describe('Test colorscale:', function() { autocolorscale: true, _input: {} }; - z = [[0, -1.5], [-2, -10]]; - calcColorscale(trace, z, '', 'z'); + gd = _supply(trace); + calcColorscale(gd, trace, {vals: trace.z, containerStr: '', cLetter: 'z'}); expect(trace.autocolorscale).toBe(false); expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']); }); @@ -466,7 +410,8 @@ describe('Test colorscale:', function() { _input: {autocolorscale: true} }; z = [[undefined, undefined], [-0.5, undefined]]; - calcColorscale(trace, z, '', 'z'); + gd = _supply(trace); + calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'}); expect(trace.autocolorscale).toBe(true); expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']); }); @@ -479,7 +424,8 @@ describe('Test colorscale:', function() { _input: {autocolorscale: true} }; z = [[undefined, undefined], [0.5, undefined]]; - calcColorscale(trace, z, '', 'z'); + gd = _supply(trace); + calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'}); expect(trace.autocolorscale).toBe(true); expect(trace.colorscale[0]).toEqual([0, 'rgb(220,220,220)']); }); @@ -493,7 +439,8 @@ describe('Test colorscale:', function() { _input: {autocolorscale: true} }; z = [[undefined, undefined], [0.5, undefined]]; - calcColorscale(trace, z, '', 'z'); + gd = _supply(trace); + calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'}); expect(trace.autocolorscale).toBe(true); expect(trace.colorscale[trace.colorscale.length - 1]) .toEqual([1, 'rgb(220,220,220)']); From d263a7f1d3c63bb77b4b8aab2a4fc67b6157b4ba Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 21 Nov 2018 18:05:20 -0500 Subject: [PATCH 10/15] fix lint --- test/jasmine/assets/supply_defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jasmine/assets/supply_defaults.js b/test/jasmine/assets/supply_defaults.js index 6d42aca0aca..28bba9b870f 100644 --- a/test/jasmine/assets/supply_defaults.js +++ b/test/jasmine/assets/supply_defaults.js @@ -3,7 +3,7 @@ var Plots = require('@src/plots/plots'); // The following is used to fill up the Registry module -/* eslint-ignore */ +/* eslint-disable-next-line */ var Plotly = require('@lib'); /** From 84f0ea87c6beaf5c2160eecfccea6b005798f148 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Wed, 21 Nov 2018 18:17:01 -0500 Subject: [PATCH 11/15] revert parcoords_tests.js to master --- test/jasmine/tests/parcoords_test.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/jasmine/tests/parcoords_test.js b/test/jasmine/tests/parcoords_test.js index b568c9d2921..3a8313c1d65 100644 --- a/test/jasmine/tests/parcoords_test.js +++ b/test/jasmine/tests/parcoords_test.js @@ -141,10 +141,7 @@ describe('parcoords initialization tests', function() { cauto: true, autocolorscale: false, reversescale: false, - showscale: false, - diverging: undefined, - sequential: undefined, - sequentialminus: undefined + showscale: false }); }); @@ -281,9 +278,6 @@ describe('parcoords initialization tests', function() { ] })); - delete(fullTrace.line.diverging); - delete(fullTrace.line.sequential); - delete(fullTrace.line.sequentialminus); expect(fullTrace.line).toEqual({ color: [35, 63, 21, 42], colorscale: attributes.line.colorscale.dflt, From ee222d50016211eca4dc1fc9dd8917daa91e049b Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Thu, 22 Nov 2018 12:49:52 -0500 Subject: [PATCH 12/15] test layout.colorscale inheritance --- test/jasmine/tests/colorscale_test.js | 101 ++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/test/jasmine/tests/colorscale_test.js b/test/jasmine/tests/colorscale_test.js index cedf8f1a0e4..2721f5710bf 100644 --- a/test/jasmine/tests/colorscale_test.js +++ b/test/jasmine/tests/colorscale_test.js @@ -387,6 +387,25 @@ describe('Test colorscale:', function() { expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']); }); + it('should be layout.colorscale.sequentialminus when autocolorscale and z <= 0', function() { + var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + trace = { + type: 'heatmap', + z: [[-0, -1.5], [-2, -10]], + autocolorscale: true, + _input: {autocolorscale: true} + }; + var layout = { + colorscale: { + sequentialminus: colorscale + } + }; + gd = _supply(trace, layout); + calcColorscale(gd, trace, {vals: trace.z, containerStr: '', cLetter: 'z'}); + expect(trace.autocolorscale).toBe(true); + expect(trace.colorscale).toEqual(colorscale); + }); + it('should set autocolorscale to false if it wasn\'t explicitly set true in input', function() { trace = { type: 'heatmap', @@ -416,6 +435,26 @@ describe('Test colorscale:', function() { expect(trace.colorscale[5]).toEqual([1, 'rgb(220,220,220)']); }); + it('should be layout.colorscale.sequentialminus when autocolorscale and the only numerical z <= -0.5', function() { + var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + trace = { + type: 'heatmap', + z: [['a', 'b'], [-0.5, 'd']], + autocolorscale: true, + _input: {autocolorscale: true} + }; + z = [[undefined, undefined], [-0.5, undefined]]; + var layout = { + colorscale: { + sequentialminus: colorscale + } + }; + gd = _supply(trace, layout); + calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'}); + expect(trace.autocolorscale).toBe(true); + expect(trace.colorscale).toEqual(colorscale); + }); + it('should be Reds when the only numerical z >= 0.5', function() { trace = { type: 'heatmap', @@ -430,6 +469,68 @@ describe('Test colorscale:', function() { expect(trace.colorscale[0]).toEqual([0, 'rgb(220,220,220)']); }); + it('should be layout.colorscale.sequential when autocolorscale and the only numerical z >= 0.5', function() { + var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + trace = { + type: 'heatmap', + z: [['a', 'b'], [0.5, 'd']], + autocolorscale: true, + _input: {autocolorscale: true} + }; + z = [[undefined, undefined], [0.5, undefined]]; + var layout = { + colorscale: { + sequential: colorscale + } + }; + gd = _supply(trace, layout); + calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'}); + expect(trace.autocolorscale).toBe(true); + expect(trace.colorscale).toEqual(colorscale); + }); + + it('should be layout.colorscale.diverging when autocolorscale and there are positive and negative values', function() { + var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + trace = { + type: 'heatmap', + z: [[-1.0, 'b'], [0.5, 'd']], + autocolorscale: true, + _input: {autocolorscale: true} + }; + z = [[-1.0, undefined], [0.5, undefined]]; + var layout = { + colorscale: { + diverging: colorscale + } + }; + gd = _supply(trace, layout); + calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'}); + expect(trace.autocolorscale).toBe(true); + expect(trace.colorscale).toEqual(colorscale); + }); + + it('should ignore layout.colorscale.diverging when colorscale is defined at trace-level', function() { + var colorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + var layoutColorscale = [[0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']]; + trace = { + type: 'heatmap', + z: [[-1.0, 'b'], [0.5, 'd']], + autocolorscale: true, + _input: {autocolorscale: true}, + colorscale: colorscale + }; + z = [[-1.0, undefined], [0.5, undefined]]; + var layout = { + colorscale: { + diverging: layoutColorscale + } + }; + gd = _supply(trace, layout); + calcColorscale(gd, trace, {vals: z, containerStr: '', cLetter: 'z'}); + expect(trace.autocolorscale).toBe(true); + expect(trace.colorscale).toEqual(colorscale); + }); + it('should be reverse the auto scale when reversescale is true', function() { trace = { type: 'heatmap', From 75e8910b4251564fd9d1f7edcc0150a15ebf64c8 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Thu, 22 Nov 2018 16:48:14 -0500 Subject: [PATCH 13/15] improve code readability --- src/components/colorscale/calc.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/colorscale/calc.js b/src/components/colorscale/calc.js index 4232c8bc479..e887b6820cd 100644 --- a/src/components/colorscale/calc.js +++ b/src/components/colorscale/calc.js @@ -15,6 +15,7 @@ var flipScale = require('./flip_scale'); module.exports = function calc(gd, trace, opts) { + var fullLayout = gd._fullLayout; var vals = opts.vals; var containerStr = opts.containerStr; var cLetter = opts.cLetter; @@ -86,8 +87,8 @@ module.exports = function calc(gd, trace, opts) { doUpdate(autoAttr, (auto !== false || (min === undefined && max === undefined))); if(container.autocolorscale) { - if(min * max < 0) scl = gd._fullLayout.colorscale.diverging; - else if(min >= 0) scl = gd._fullLayout.colorscale.sequential; + if(min * max < 0) scl = fullLayout.colorscale.diverging; + else if(min >= 0) scl = fullLayout.colorscale.sequential; else scl = gd._fullLayout.colorscale.sequentialminus; // reversescale is handled at the containerOut level From e50a6aa51b40e9686595d682858cf5803d6c2e80 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Thu, 22 Nov 2018 18:47:37 -0500 Subject: [PATCH 14/15] add a mock using template and layout.colorscale --- test/image/baselines/colorscale_template.png | Bin 0 -> 22275 bytes test/image/mocks/colorscale_template.json | 157 +++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 test/image/baselines/colorscale_template.png create mode 100644 test/image/mocks/colorscale_template.json diff --git a/test/image/baselines/colorscale_template.png b/test/image/baselines/colorscale_template.png new file mode 100644 index 0000000000000000000000000000000000000000..be36c46dba041cd0adee6647de179548b04d30a9 GIT binary patch literal 22275 zcmeIac|6qb_dhI2WQi;#YY9@53pwx}6h zRcB?4Q=!?gYj;>&8^`)h!fL14*VC0*t6P|;sH~&E5#nfdXWLl|{rwRe^-o6nzS!^K zKyLfM)_uaolmT+ZUUdn7GHB#g~dkfNC9`3KccW&E0-ZbZ9lB z7~3Q8)8GFvreQ%Hq+b4xuSy!d04@TB65hD@OUT!JNrfAi7J;94>QE8yOpHm&Q&wGE zCm>eo?^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}`9z3c!SgeQHOJY4LFf2sUp0slho9W$u%rLyA@0Wq+xQ#n2Gb|N&qgeF}2Kju-c)Dv1C>sQw{+iFZ@Bs$d2CRTo_>`k!i z0jSu>Mu6#vTh@00lsSkR<(Z3W9Er%^@*7%DxqI{Y>}qOiB4G5SVM`|*sSX<2=`aG} z1Szp`OUnhOXN?nqb({p~@)`3R3?{b}n*Z8Gf?ti@X7=q^pos`uoTODqzg=j^lQ&zH zLfXrnZA1rTwAmz~J|_}26J+*1QW#w(z#>Flz)1j3d9{N3Ns_{kD1)5!e}BF)xm4PAa?UaCk?PSTPe`Si%e$KRM(}C-?R+OjC~~Uub}e6!&7FRb}{oG^EY8P6?#*rW36U{ zlNhM=q0Sg{UY%hRHaU2(EjJOS?e|ISfBfPSXCAO{VqW!gov4uZ?caL$X-@L`Hp!WV zp{;b%*{(4A7B9Xv(RL(`S97~VkD*2o8nmFprP2$ZLjl;eJY_fLx)=%L%x^JvFD8O z4>I}o>K&fZ7j3$o=WS;y^jbM1<)~AKRqU}U@42z$W)je(d%e!p%r}1q8l^q2#|H^X znM)s1*dL{68Ph+0eCdp3(ZZKfbZMLU;qxCa?1O3@LR>SRJ=W+m#JX`7U1Mq5k`wA( zuG2W?^!lD}Wz#;MIigAySne1FTH zX;G#b)^zLN6DMrOq)fFB>&6+fq*keI^`BkNX{t3LSeiyI+=|My*%|9!pZ g|G(dO`qf9IIb%7 literal 0 HcmV?d00001 diff --git a/test/image/mocks/colorscale_template.json b/test/image/mocks/colorscale_template.json new file mode 100644 index 00000000000..a506fb9d1bd --- /dev/null +++ b/test/image/mocks/colorscale_template.json @@ -0,0 +1,157 @@ +{ + "data": [{ + "x": [ + 50076, + -42372, + -19260, + 3852, + 26964, + -65484, + -42372, + -19260, + 3852, + 26964, + -88596, + -65484, + -42372, + -19260, + 3852, + 26964, + 50076, + 73188, + -65484, + -42372, + -19260, + 3852, + 26964, + 50076, + -42372, + -19260, + 3852, + 26964, + -88596, + -65484, + -42372, + -19260, + 3852, + 26964, + 50076, + 73188, + -88596, + -65484, + -42372, + -19260, + 3852, + 26964, + 50076, + 73188 + ], + "y": [ + 51851.8, + 77841.4, + 77841.4, + 77841.4, + 77841.4, + 51851.8, + 51851.8, + 51851.8, + 51851.8, + 51851.8, + -26117, + -26117, + -26117, + -26117, + -26117, + -26117, + -26117, + -26117, + -52106.6, + -52106.6, + -52106.6, + -52106.6, + -52106.6, + -52106.6, + -78096.2, + -78096.2, + -78096.2, + -78096.2, + -127.4, + -127.4, + -127.4, + -127.4, + -127.4, + -127.4, + -127.4, + -127.4, + 25862.2, + 25862.2, + 25862.2, + 25862.2, + 25862.2, + 25862.2, + 25862.2, + 25862.2 + ], + "z": [ + 4.361856, + 4.234497, + 4.321701, + 4.450315, + 4.416136, + 4.210373, + 4.32009, + 4.246728, + 4.293992, + 4.316364, + 3.908434, + 4.433257, + 4.364234, + 4.308714, + 4.275516, + 4.126979, + 4.296483, + 4.320471, + 4.339848, + 4.39907, + 4.345006, + 4.315032, + 4.295618, + 4.262052, + 4.154291, + 4.404264, + 4.33847, + 4.270931, + 4.032226, + 4.381492, + 4.328922, + 4.24046, + 4.349151, + 4.202861, + 4.256402, + 4.28972, + 3.956225, + 4.337909, + 4.31226, + 4.259435, + 4.146854, + 4.235799, + 4.238752, + 4.299876 + ], + "type": "heatmap", + "autocolorscale": true + }], + "layout": { + "template": { + "layout": { + "title": "heatmap template", + "colorscale": { + "sequential": [ + [0, "rgb(0,0,0)"], + [1, "rgb(255,255,255)"] + ] + } + } + } + } +} From dca43502a49a70b576ca2748a094ded8b2edcb34 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Fri, 23 Nov 2018 12:02:28 -0500 Subject: [PATCH 15/15] set autocolorscale: true in template to properly test mock --- test/image/mocks/colorscale_template.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/image/mocks/colorscale_template.json b/test/image/mocks/colorscale_template.json index a506fb9d1bd..e3fa4e38505 100644 --- a/test/image/mocks/colorscale_template.json +++ b/test/image/mocks/colorscale_template.json @@ -138,11 +138,15 @@ 4.238752, 4.299876 ], - "type": "heatmap", - "autocolorscale": true + "type": "heatmap" }], "layout": { "template": { + "data": { + "heatmap": [{ + "autocolorscale": true + }] + }, "layout": { "title": "heatmap template", "colorscale": {