Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix patterns coloring for pie, sunburst, funnelarea, icicle & treemap #6627

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
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
Loading
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