Skip to content

Commit be34e0f

Browse files
authored
Merge pull request #6627 from plotly/fix-patterns-pie-sunburst
Fix patterns coloring for pie, sunburst, funnelarea, icicle & treemap
2 parents b5765c4 + fd93796 commit be34e0f

File tree

9 files changed

+33
-23
lines changed

9 files changed

+33
-23
lines changed

Diff for: draftlogs/6601_add.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
- 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)],
1+
- 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)],
22
with thanks to @thierryVergult for the contribution!

Diff for: src/components/drawing/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,18 @@ drawing.singlePointStyle = function(d, sel, trace, fns, gd, pt) {
747747
drawing.gradient(sel, gd, gradientID, gradientType,
748748
[[0, gradientColor], [1, fillColor]], 'fill');
749749
} else if(patternShape) {
750+
var perPointPattern = false;
751+
var fgcolor = markerPattern.fgcolor;
752+
if(!fgcolor && pt && pt.color) {
753+
fgcolor = pt.color;
754+
perPointPattern = true;
755+
}
756+
var patternFGColor = drawing.getPatternAttr(fgcolor, d.i, null);
750757
var patternBGColor = drawing.getPatternAttr(markerPattern.bgcolor, d.i, null);
751-
var patternFGColor = drawing.getPatternAttr(markerPattern.fgcolor, d.i, null);
752758
var patternFGOpacity = markerPattern.fgopacity;
753759
var patternSize = drawing.getPatternAttr(markerPattern.size, d.i, 8);
754760
var patternSolidity = drawing.getPatternAttr(markerPattern.solidity, d.i, 0.3);
755-
var perPointPattern = d.mcc ||
761+
perPointPattern = perPointPattern || d.mcc ||
756762
Lib.isArrayOrTypedArray(markerPattern.shape) ||
757763
Lib.isArrayOrTypedArray(markerPattern.bgcolor) ||
758764
Lib.isArrayOrTypedArray(markerPattern.fgcolor) ||

Diff for: src/traces/pie/fill_one.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
'use strict';
22

33
var Drawing = require('../../components/drawing');
4+
var Color = require('../../components/color');
45

56
module.exports = function fillOne(s, pt, trace, gd) {
6-
// enforce the point color, when colors (with s) & the pattern shape are missing.
7-
// 'abuse' the color attribute, used in the Drawing component for bar trace type.
8-
var marker = trace.marker;
9-
if(marker.pattern) {
10-
if(!marker.colors || !marker.pattern.shape) marker.color = pt.color;
7+
var pattern = trace.marker.pattern;
8+
if(pattern && pattern.shape) {
9+
Drawing.pointStyle(s, trace, gd, pt);
1110
} else {
12-
marker.color = pt.color;
11+
Color.fill(s, pt.color);
1312
}
14-
15-
Drawing.pointStyle(s, trace, gd, pt);
1613
};

Diff for: src/traces/pie/style_one.js

-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ module.exports = function styleOne(s, pt, trace, gd) {
99
var lineColor = castOption(line.color, pt.pts) || Color.defaultLine;
1010
var lineWidth = castOption(line.width, pt.pts) || 0;
1111

12-
// enforce the point color, when colors (with s) & the pattern shape are missing.
13-
// 'abuse' the color attribute, used in the Drawing component for bar trace type.
14-
var marker = trace.marker;
15-
if(marker.pattern) {
16-
if(!marker.colors || !marker.pattern.shape) marker.color = pt.color;
17-
} else {
18-
marker.color = pt.color;
19-
}
20-
2112
s.call(fillOne, pt, trace, gd)
2213
.style('stroke-width', lineWidth)
2314
.call(Color.stroke, lineColor);

Diff for: src/traces/sunburst/fill_one.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ module.exports = function fillOne(s, pt, trace, gd, fadedColor) {
99

1010
var color = fadedColor || cdi.color;
1111

12-
if(gd && ptNumber >= 0) {
12+
if(ptNumber >= 0) {
1313
pt.i = cdi.i;
1414

1515
var marker = trace.marker;
1616
if(marker.pattern) {
17-
if(!marker.colors || !marker.pattern.shape) marker.color = color;
17+
if(!marker.colors || !marker.pattern.shape) {
18+
marker.color = color;
19+
pt.color = color;
20+
}
1821
} else {
1922
marker.color = color;
23+
pt.color = color;
2024
}
2125

2226
Drawing.pointStyle(s, trace, gd, pt);

Diff for: test/image/baselines/pie_label0_dlabel.png

1.66 KB
Loading
27.7 KB
Loading

Diff for: test/image/mocks/pie_label0_dlabel.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
],
1111
"label0": 20,
1212
"dlabel": 5,
13-
"type": "pie"
13+
"type": "pie",
14+
"marker": {
15+
"pattern": {
16+
"fillmode": "replace",
17+
"shape": ".",
18+
"size": 3
19+
}
20+
}
1421
}
1522
],
1623
"layout": {

Diff for: test/image/mocks/treemap_packages_colorscale_allone.json

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"line": {
1717
"color": "#777"
1818
},
19+
"pattern": {
20+
"fillmode": "replace",
21+
"shape": ".",
22+
"size": 3
23+
},
1924
"colorscale": [
2025
[
2126
0,

0 commit comments

Comments
 (0)