Skip to content

Commit

Permalink
Merge pull request #6627 from plotly/fix-patterns-pie-sunburst
Browse files Browse the repository at this point in the history
Fix patterns coloring for pie, sunburst, funnelarea, icicle & treemap
  • Loading branch information
archmoj committed Jun 5, 2023
2 parents b5765c4 + fd93796 commit be34e0f
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion draftlogs/6601_add.md
Original file line number Diff line number Diff line change
@@ -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!
10 changes: 8 additions & 2 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
13 changes: 5 additions & 8 deletions src/traces/pie/fill_one.js
Original file line number Diff line number Diff line change
@@ -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);
};
9 changes: 0 additions & 9 deletions src/traces/pie/style_one.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/traces/sunburst/fill_one.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file modified test/image/baselines/pie_label0_dlabel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/treemap_packages_colorscale_allone.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion test/image/mocks/pie_label0_dlabel.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
],
"label0": 20,
"dlabel": 5,
"type": "pie"
"type": "pie",
"marker": {
"pattern": {
"fillmode": "replace",
"shape": ".",
"size": 3
}
}
}
],
"layout": {
Expand Down
5 changes: 5 additions & 0 deletions test/image/mocks/treemap_packages_colorscale_allone.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"line": {
"color": "#777"
},
"pattern": {
"fillmode": "replace",
"shape": ".",
"size": 3
},
"colorscale": [
[
0,
Expand Down

0 comments on commit be34e0f

Please sign in to comment.