diff --git a/draftlogs/6601_add.md b/draftlogs/6601_add.md index 6a58a619fb1..bff1139c0a8 100644 --- a/draftlogs/6601_add.md +++ b/draftlogs/6601_add.md @@ -1,2 +1,2 @@ -- add pattern to pie, funnelarea, sunburst, icicle and treemap traces [[#6601](https://github.com/plotly/plotly.js/pull/6601), [#6619](https://github.com/plotly/plotly.js/pull/6619), [#6622](https://github.com/plotly/plotly.js/pull/6622), [#6626](https://github.com/plotly/plotly.js/pull/6626)], +- add pattern to pie, funnelarea, sunburst, icicle and treemap traces [[#6601](https://github.com/plotly/plotly.js/pull/6601), [#6619](https://github.com/plotly/plotly.js/pull/6619), [#6622](https://github.com/plotly/plotly.js/pull/6622), [#6626](https://github.com/plotly/plotly.js/pull/6626), [#6627](https://github.com/plotly/plotly.js/pull/6627)], with thanks to @thierryVergult for the contribution! diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index 93dac647cb3..7e4e81142e6 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -747,12 +747,18 @@ drawing.singlePointStyle = function(d, sel, trace, fns, gd, pt) { drawing.gradient(sel, gd, gradientID, gradientType, [[0, gradientColor], [1, fillColor]], 'fill'); } else if(patternShape) { + var perPointPattern = false; + var fgcolor = markerPattern.fgcolor; + if(!fgcolor && pt && pt.color) { + fgcolor = pt.color; + perPointPattern = true; + } + var patternFGColor = drawing.getPatternAttr(fgcolor, d.i, null); var patternBGColor = drawing.getPatternAttr(markerPattern.bgcolor, d.i, null); - var patternFGColor = drawing.getPatternAttr(markerPattern.fgcolor, d.i, null); var patternFGOpacity = markerPattern.fgopacity; var patternSize = drawing.getPatternAttr(markerPattern.size, d.i, 8); var patternSolidity = drawing.getPatternAttr(markerPattern.solidity, d.i, 0.3); - var perPointPattern = d.mcc || + perPointPattern = perPointPattern || d.mcc || Lib.isArrayOrTypedArray(markerPattern.shape) || Lib.isArrayOrTypedArray(markerPattern.bgcolor) || Lib.isArrayOrTypedArray(markerPattern.fgcolor) || diff --git a/src/traces/pie/fill_one.js b/src/traces/pie/fill_one.js index 8b2b664f19e..377e6934426 100644 --- a/src/traces/pie/fill_one.js +++ b/src/traces/pie/fill_one.js @@ -1,16 +1,13 @@ 'use strict'; var Drawing = require('../../components/drawing'); +var Color = require('../../components/color'); module.exports = function fillOne(s, pt, trace, gd) { - // enforce the point color, when colors (with s) & the pattern shape are missing. - // 'abuse' the color attribute, used in the Drawing component for bar trace type. - var marker = trace.marker; - if(marker.pattern) { - if(!marker.colors || !marker.pattern.shape) marker.color = pt.color; + var pattern = trace.marker.pattern; + if(pattern && pattern.shape) { + Drawing.pointStyle(s, trace, gd, pt); } else { - marker.color = pt.color; + Color.fill(s, pt.color); } - - Drawing.pointStyle(s, trace, gd, pt); }; diff --git a/src/traces/pie/style_one.js b/src/traces/pie/style_one.js index 03f19a95cae..1193f7a455d 100644 --- a/src/traces/pie/style_one.js +++ b/src/traces/pie/style_one.js @@ -9,15 +9,6 @@ module.exports = function styleOne(s, pt, trace, gd) { var lineColor = castOption(line.color, pt.pts) || Color.defaultLine; var lineWidth = castOption(line.width, pt.pts) || 0; - // enforce the point color, when colors (with s) & the pattern shape are missing. - // 'abuse' the color attribute, used in the Drawing component for bar trace type. - var marker = trace.marker; - if(marker.pattern) { - if(!marker.colors || !marker.pattern.shape) marker.color = pt.color; - } else { - marker.color = pt.color; - } - s.call(fillOne, pt, trace, gd) .style('stroke-width', lineWidth) .call(Color.stroke, lineColor); diff --git a/src/traces/sunburst/fill_one.js b/src/traces/sunburst/fill_one.js index 70a18362770..dee0cd009a9 100644 --- a/src/traces/sunburst/fill_one.js +++ b/src/traces/sunburst/fill_one.js @@ -9,14 +9,18 @@ module.exports = function fillOne(s, pt, trace, gd, fadedColor) { var color = fadedColor || cdi.color; - if(gd && ptNumber >= 0) { + if(ptNumber >= 0) { pt.i = cdi.i; var marker = trace.marker; if(marker.pattern) { - if(!marker.colors || !marker.pattern.shape) marker.color = color; + if(!marker.colors || !marker.pattern.shape) { + marker.color = color; + pt.color = color; + } } else { marker.color = color; + pt.color = color; } Drawing.pointStyle(s, trace, gd, pt); diff --git a/test/image/baselines/pie_label0_dlabel.png b/test/image/baselines/pie_label0_dlabel.png index 226a72a4be5..7e8b6ab5168 100644 Binary files a/test/image/baselines/pie_label0_dlabel.png and b/test/image/baselines/pie_label0_dlabel.png differ diff --git a/test/image/baselines/treemap_packages_colorscale_allone.png b/test/image/baselines/treemap_packages_colorscale_allone.png index 0ab8cb2df15..3921086370e 100644 Binary files a/test/image/baselines/treemap_packages_colorscale_allone.png and b/test/image/baselines/treemap_packages_colorscale_allone.png differ diff --git a/test/image/mocks/pie_label0_dlabel.json b/test/image/mocks/pie_label0_dlabel.json index 4dc62c75393..8b05129fa1e 100644 --- a/test/image/mocks/pie_label0_dlabel.json +++ b/test/image/mocks/pie_label0_dlabel.json @@ -10,7 +10,14 @@ ], "label0": 20, "dlabel": 5, - "type": "pie" + "type": "pie", + "marker": { + "pattern": { + "fillmode": "replace", + "shape": ".", + "size": 3 + } + } } ], "layout": { diff --git a/test/image/mocks/treemap_packages_colorscale_allone.json b/test/image/mocks/treemap_packages_colorscale_allone.json index e8187fb9661..132e8805dea 100644 --- a/test/image/mocks/treemap_packages_colorscale_allone.json +++ b/test/image/mocks/treemap_packages_colorscale_allone.json @@ -16,6 +16,11 @@ "line": { "color": "#777" }, + "pattern": { + "fillmode": "replace", + "shape": ".", + "size": 3 + }, "colorscale": [ [ 0,