Skip to content

Commit f32c7ea

Browse files
authored
Merge pull request #6628 from plotly/patterns-4-items-more
Fix rendering of pie legends when arrays e.g. `pattern` or `line.width` having 4 items or more
2 parents be34e0f + b07359e commit f32c7ea

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
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), [#6627](https://github.com/plotly/plotly.js/pull/6627)],
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) [#6628](https://github.com/plotly/plotly.js/pull/6628)],
22
with thanks to @thierryVergult for the contribution!

Diff for: src/components/legend/style.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,11 @@ module.exports = function style(s, gd, legend) {
503503
pts.exit().remove();
504504

505505
if(pts.size()) {
506-
var cont = (trace.marker || {}).line;
507-
var lw = boundLineWidth(pieCastOption(cont.width, d0.pts), cont, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);
506+
var cont = trace.marker || {};
507+
var lw = boundLineWidth(pieCastOption(cont.line.width, d0.pts), cont.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);
508508

509-
var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}});
510-
// since minExtend do not slice more than 3 items we need to patch line.color here
511-
tMod.marker.line.color = cont.color;
512-
513-
var d0Mod = Lib.minExtend(d0, {trace: tMod});
509+
var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}}, true);
510+
var d0Mod = Lib.minExtend(d0, {trace: tMod}, true);
514511

515512
stylePie(pts, d0Mod, tMod, gd);
516513
}

Diff for: src/lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,10 @@ lib.getTargetArray = function(trace, transformOpts) {
698698
* because extend-like algorithms are hella slow
699699
* obj2 is assumed to already be clean of these things (including no arrays)
700700
*/
701-
lib.minExtend = function(obj1, obj2) {
701+
lib.minExtend = function(obj1, obj2, isPie) {
702702
var objOut = {};
703703
if(typeof obj2 !== 'object') obj2 = {};
704-
var arrayLen = 3;
704+
var arrayLen = isPie = 3;
705705
var keys = Object.keys(obj1);
706706
var i, k, v;
707707

@@ -711,7 +711,7 @@ lib.minExtend = function(obj1, obj2) {
711711
if(k.charAt(0) === '_' || typeof v === 'function') continue;
712712
else if(k === 'module') objOut[k] = v;
713713
else if(Array.isArray(v)) {
714-
if(k === 'colorscale') {
714+
if(isPie || k === 'colorscale') {
715715
objOut[k] = v.slice();
716716
} else {
717717
objOut[k] = v.slice(0, arrayLen);

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

6.99 KB
Loading

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
"orange"
2323
],
2424
"line": {
25-
"width": 5,
25+
"width": [3, 4, 5, 6],
2626
"color": [
2727
"red",
2828
"green",
2929
"blue",
3030
"yellow"
3131
]
32+
},
33+
"pattern": {
34+
"shape": [".", "x", "+", "-"],
35+
"size": [3, 4, 5, 6]
3236
}
3337
}
3438
}

0 commit comments

Comments
 (0)