Skip to content

Commit 9927adb

Browse files
committed
fix rendering of pie legends with pattern & line color or sizes hving 4 or more items
- follow up of #3891
1 parent be34e0f commit 9927adb

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

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
}

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);
Loading

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)