diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index 34e2572bc8d..d57350f61ef 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -276,9 +276,8 @@ drawing.singlePointStyle = function(d, sel, trace) { // allow array marker and marker line colors to be // scaled by given max and min to colorscales - var markerIn = (trace._input || {}).marker || {}, - markerScale = drawing.tryColorscale(marker, markerIn, ''), - lineScale = drawing.tryColorscale(marker, markerIn, 'line.'); + var markerScale = drawing.tryColorscale(marker, ''), + lineScale = drawing.tryColorscale(marker, 'line'); singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerLine); @@ -290,50 +289,22 @@ drawing.pointStyle = function(s, trace) { // allow array marker and marker line colors to be // scaled by given max and min to colorscales var marker = trace.marker; - var markerIn = (trace._input || {}).marker || {}, - markerScale = drawing.tryColorscale(marker, markerIn, ''), - lineScale = drawing.tryColorscale(marker, markerIn, 'line.'); + var markerScale = drawing.tryColorscale(marker, ''), + lineScale = drawing.tryColorscale(marker, 'line'); s.each(function(d) { drawing.singlePointStyle(d, d3.select(this), trace, markerScale, lineScale); }); }; -// for a given color attribute (ie m -> mc = marker.color) look to see if we -// have a colorscale for it (ie mscl, mcmin, mcmax) - if we do, translate -// all numeric color values according to that scale -drawing.tryColorscale = function(cont, contIn, prefix) { - var colorArray = Lib.nestedProperty(cont, prefix + 'color').get(), - scl = Lib.nestedProperty(cont, prefix + 'colorscale').get(), - auto = Lib.nestedProperty(cont, prefix + 'cauto').get(), - minProp = Lib.nestedProperty(cont, prefix + 'cmin'), - maxProp = Lib.nestedProperty(cont, prefix + 'cmax'), - min = minProp.get(), - max = maxProp.get(); - - // TODO handle this in Colorscale.calc - if(scl && Array.isArray(colorArray)) { - if(auto || !isNumeric(min) || !isNumeric(max)) { - min = Infinity; - max = -Infinity; - colorArray.forEach(function(color) { - if(isNumeric(color)) { - if(min > color) min = +color; - if(max < color) max = +color; - } - }); - if(min > max) { - min = 0; - max = 1; - } - minProp.set(min); - maxProp.set(max); - Lib.nestedProperty(contIn, prefix + 'cmin').set(min); - Lib.nestedProperty(contIn, prefix + 'cmax').set(max); - } +drawing.tryColorscale = function(marker, prefix) { + var cont = prefix ? Lib.nestedProperty(marker, prefix).get() : marker, + scl = cont.colorscale, + colorArray = cont.color; + if(scl && Array.isArray(colorArray)) { return Colorscale.makeColorScaleFunc( - Colorscale.extractScale(scl, min, max) + Colorscale.extractScale(scl, cont.cmin, cont.cmax) ); } else return Lib.identity; diff --git a/src/traces/bar/style.js b/src/traces/bar/style.js index a976340c3ae..49aa025324a 100644 --- a/src/traces/bar/style.js +++ b/src/traces/bar/style.js @@ -41,9 +41,8 @@ module.exports = function style(gd) { var trace = d[0].trace, marker = trace.marker, markerLine = marker.line, - markerIn = (trace._input || {}).marker || {}, - markerScale = Drawing.tryColorscale(marker, markerIn, ''), - lineScale = Drawing.tryColorscale(marker, markerIn, 'line.'); + markerScale = Drawing.tryColorscale(marker, ''), + lineScale = Drawing.tryColorscale(marker, 'line'); d3.select(this).selectAll('path').each(function(d) { // allow all marker and marker line colors to be scaled diff --git a/test/image/baselines/colorscale_constraint.png b/test/image/baselines/colorscale_constraint.png index c6edd7ea90c..6f197e8547f 100644 Binary files a/test/image/baselines/colorscale_constraint.png and b/test/image/baselines/colorscale_constraint.png differ diff --git a/test/image/mocks/colorscale_constraint.json b/test/image/mocks/colorscale_constraint.json index 17e29fe17a8..4443b177f39 100644 --- a/test/image/mocks/colorscale_constraint.json +++ b/test/image/mocks/colorscale_constraint.json @@ -6,7 +6,12 @@ "color": [1,2,3,4], "cmin": 2, "cmax": 3, - "showscale": true + "colorbar": { + "title": "trace 0", + "len": 0.3, + "y": 0, + "yanchor": "bottom" + } } }, { "x": [1,2,3,4,5], @@ -15,7 +20,26 @@ "color": [1,2,3,4], "cmin": 1, "cmax": 4, - "showscale": false + "colorbar": { + "title": "trace 1", + "len": 0.3, + "y": 0.3, + "yanchor": "bottom" + } + } + }, { + "x": [1,2,3,4], + "y": [2.5,2.5,2.5,2.5], + "mode": "markers", + "marker": { + "color": [0,0,0,0], + "size": 10, + "colorbar": { + "title": "trace 2", + "len": 0.3, + "y": 0.6, + "yanchor": "bottom" + } } }], "layout": {