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 rendering of pie legends when arrays e.g. pattern or line.width having 4 items or more #6628

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.
Jump to
Jump to file
Failed to load files.
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), [#6627](https://github.com/plotly/plotly.js/pull/6627)],
- 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)],
with thanks to @thierryVergult for the contribution!
11 changes: 4 additions & 7 deletions src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,11 @@ module.exports = function style(s, gd, legend) {
pts.exit().remove();

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

var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}});
// since minExtend do not slice more than 3 items we need to patch line.color here
tMod.marker.line.color = cont.color;

var d0Mod = Lib.minExtend(d0, {trace: tMod});
var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}}, true);
var d0Mod = Lib.minExtend(d0, {trace: tMod}, true);

stylePie(pts, d0Mod, tMod, gd);
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,10 @@ lib.getTargetArray = function(trace, transformOpts) {
* because extend-like algorithms are hella slow
* obj2 is assumed to already be clean of these things (including no arrays)
*/
lib.minExtend = function(obj1, obj2) {
lib.minExtend = function(obj1, obj2, isPie) {
var objOut = {};
if(typeof obj2 !== 'object') obj2 = {};
var arrayLen = 3;
var arrayLen = isPie = 3;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what happened with my editor here!
This logic is not quite right as it changes the input argument. This may slow the process.
I'll fix it and release a patch shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by #6632.

var keys = Object.keys(obj1);
var i, k, v;

Expand All @@ -711,7 +711,7 @@ lib.minExtend = function(obj1, obj2) {
if(k.charAt(0) === '_' || typeof v === 'function') continue;
else if(k === 'module') objOut[k] = v;
else if(Array.isArray(v)) {
if(k === 'colorscale') {
if(isPie || k === 'colorscale') {
objOut[k] = v.slice();
} else {
objOut[k] = v.slice(0, arrayLen);
Expand Down
Binary file modified test/image/baselines/pie_legend_line_color_array.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion test/image/mocks/pie_legend_line_color_array.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
"orange"
],
"line": {
"width": 5,
"width": [3, 4, 5, 6],
"color": [
"red",
"green",
"blue",
"yellow"
]
},
"pattern": {
"shape": [".", "x", "+", "-"],
"size": [3, 4, 5, 6]
}
}
}
Expand Down