GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pie legend and showlegend per slice by my-tien · Pull Request #7580 · plotly/plotly.js

Conversation

@my-tien

@my-tien my-tien commented Oct 13, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR makes it possible to pass arrays to the pie properties 'legend' and 'showlegend' so that legend assignment and visibility can be configured per slice.

Changes:

Previously, traces.pie.legend and traces.pie.showlegend only accepted one value that applied for all slices. With this PR, slice legend entries can be grouped and individual slices can be hidden in the legend:

{
 "data": [
  {
   "labels": [
     "BBBBBBBBBBBBBBBBBB",
     "AAAAAAAAAAAAAAAAAA",
     "222222222222222222",
     "111111111111111111",
     "unimportant"
    ],
   "values": [10, 15, 13, 19, 1],
   "type": "pie",
   "showlegend": [true, true, true, true, false],
   "legend": ["legend", "legend", "legend2", "legend2"]
  }
 ],
 "layout": {
  "width": 400,
  "height": 400,
  "legend": {
    "title": {
        "text": "Group 1"
    },
    "xanchor": "left",
    "yanchor": "top",
    "x": -0.2,
    "y": -0.1
  },
  "legend2": {
    "title": {
        "text": "Group 2"
    },
    "xanchor": "left",
    "yanchor": "top",
    "x": 0.6,
    "y": -0.1
  }
 }
}

Result

image

Old behavior

No possibility to group slices semantically or to hide a slice. Also takes up more vertical space.
image

Testing

For testing, I added 3 mocks:

  • zz-pie-slice-legend.json verifies that the array entries are associated to the pie slices in declaration order.
  • zz-pie-slice-legend2.json verifies that if the arrays have less entries than there are pie slices, the extra slices are assigned default values.
  • zz-pie-slice-legend3.json verifies that the arrays also work when label0 and dlabel are set instead of labels.

Note:

This feature is not expected to work when pie values are not set.

Disclaimer I am required to add that…

the software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
my-tien added 9 commits October 13, 2025 09:14
@my-tien
Make pie.showlegend accept a boolean array to configure individual sl…
4fc0e3b
…ice legend visibility.
@my-tien
Make pie.legend accept a boolean array to configure individual slice …
417ca2e
…legend assignment.
@my-tien
Mocks for testing pie.legend and pie.showlegend arrays.
449598d
@my-tien
Add draftlog for plotly#7580
178959e
@my-tien
Add missing plot-schema change
3f9143d
@my-tien
Baselines for tests zz-pie-slice-legend and zz-pie-slice-legend2
f9c65da
@my-tien
Fix defaults for legend when pie has no slices.
09bcc61
@my-tien
Change pie influence on default legend visibility only for non-empty …
dd73d5a
…pies with showlegend and/or legend as arrays
@my-tien
debugger statement…
71c01fb
@alexshoe alexshoe self-assigned this Oct 14, 2025
@gvwilson gvwilson added feature something new community community contribution P1 needed for current cycle labels Oct 28, 2025
@my-tien

my-tien commented Nov 12, 2025

Copy link
Copy Markdown
Contributor Author

@alexshoe Hi Alex! Do you possibly have an estimate when this PR could be tackled? Also, let me know if you have any questions :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexshoe

alexshoe commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

Hey @my-tien! Sorry, just working through a backlog of different PRs that I was assigned. I'll start reviewing this tomorrow.

my-tien reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@my-tien
Merge remote-tracking branch 'origin-plotly/master' into pie-legend-v…
177dca3
…isibility

# Conflicts:
#	test/plot-schema.json
@my-tien

my-tien commented Nov 25, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@alexshoe Hi Alex, I saw that my branch got out of date and conflicted with the current test/plot-schema.json .
I merged master into my branch, reran npm run schema and saw below output. Is this output currently expected and does it still generate a correct plot-schema.json since the last statement is still »ok plot-schema.json« (I installed dependencies via npm run i -d and I have canvas in my node_modules folder)?

EDIT: After wiping node_modules and re-installing with npm i the errors went away.

[email protected] schema
node tasks/schema.mjs

build\plotly.js 11.0mb

Done in 7872ms
Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
at module.exports (...\plotly.js\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)
at HTMLCanvasElementImpl.getContext (...\plotly.js\node_modules\jsdom\lib\jsdom\living\nodes\HTMLCanvasElement-impl.js:42:5)
at HTMLCanvasElement.getContext (...\plotly.js\node_modules\jsdom\lib\jsdom\living\generated\HTMLCanvasElement.js:131:58)
at 4359 (about:blank:106137:48)
at __webpack_require__ (about:blank:128019:41)
at 4935 (about:blank:108491:35)
at __webpack_require__ (about:blank:128019:41)
at 3837 (about:blank:103258:32)
at __webpack_require__ (about:blank:128019:41)
at 4100 (about:blank:104906:32) undefined
Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
at module.exports (...\plotly.js\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)
at HTMLCanvasElementImpl.getContext (...\plotly.js\node_modules\jsdom\lib\jsdom\living\nodes\HTMLCanvasElement-impl.js:42:5)
at HTMLCanvasElement.getContext (...\plotly.js\node_modules\jsdom\lib\jsdom\living\generated\HTMLCanvasElement.js:131:58)
at node_modules/svg-path-sdf/index.js (about:blank:148569:24)
at __require (about:blank:42:52)
at src/traces/scattergl/convert.js (about:blank:148638:20)
at __require (about:blank:42:52)
at src/traces/scattergl/calc.js (about:blank:149375:21)
at __require (about:blank:42:52)
at src/traces/scattergl/base_index.js (about:blank:149636:15) undefined
Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
at module.exports (...\plotly.js\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)
at HTMLCanvasElementImpl.getContext (...\plotly.js\node_modules\jsdom\lib\jsdom\living\nodes\HTMLCanvasElement-impl.js:42:5)
at HTMLCanvasElement.getContext (...\plotly.js\node_modules\jsdom\lib\jsdom\living\generated\HTMLCanvasElement.js:131:58)
at node_modules/detect-kerning/index.js (about:blank:163622:24)
at __require (about:blank:42:52)
at node_modules/gl-text/dist.js (about:blank:163834:21)
at __require (about:blank:42:52)
at src/traces/scattergl/plot.js (about:blank:172852:18)
at __require (about:blank:42:52)
at src/traces/scattergl/index.js (about:blank:173168:20) undefined
Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
at module.exports (...\plotly.js\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)
at HTMLCanvasElementImpl.getContext (...\plotly.js\node_modules\jsdom\lib\jsdom\living\nodes\HTMLCanvasElement-impl.js:42:5)
at HTMLCanvasElement.getContext (...\plotly.js\node_modules\jsdom\lib\jsdom\living\generated\HTMLCanvasElement.js:131:58)
at node_modules/gl-text/dist.js (about:blank:164409:48)
at __require (about:blank:42:52)
at src/traces/scattergl/plot.js (about:blank:172852:18)
at __require (about:blank:42:52)
at src/traces/scattergl/index.js (about:blank:173168:20)
at __require (about:blank:42:52)
at lib/scattergl.js (about:blank:173177:24) undefined
ok plot-schema.json

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@robertclaus robertclaus assigned camdecoster and unassigned alexshoe Nov 25, 2025
@robertclaus
robertclaus requested a review from camdecoster November 25, 2025 19:25
@camdecoster

camdecoster commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

@my-tien could you please add some more information to the OP? I'm interested in seeing sections describing:

  • Changes
  • Before/after pictures or videos
  • Testing instructions

With that, I'll be able to better review the changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

my-tien added 2 commits November 26, 2025 13:34
@my-tien
Clarify that pie legend and showlegend can only be arrays if values…
3e5e53f
… is provided.
@my-tien
Add baseline test for pie legend/showlegend arrays when label0 is use…
ab11db2
…d instead of labels.
@my-tien

my-tien commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

Hi @camdecoster,
Thx for looking at my PR! Regarding my error above, this was resolved by completely deleting my node_modules and re-installing again.

I also updated the OP and added a better description of the properties for the plot schema. Please let me know if anything is unclear or missing!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@my-tien
baseline image for zz-pie-slice-legend3.png
73c531e
camdecoster
camdecoster requested changes Nov 26, 2025
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for adding this feature! There are a few changes to make, but it seems to work well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/components/legend/defaults.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/components/legend/defaults.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/components/legend/defaults.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/image/mocks/zz-pie-slice-legend.json Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/image/mocks/zz-pie-slice-legend3.json Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/lib/coerce.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/lib/coerce.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/image/mocks/zz-pie-slice-legend2.json Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/image/mocks/zz-pie-slice-legend.json Resolved

Uh oh!

There was an error while loading. Please reload this page.

my-tien added 4 commits November 27, 2025 14:28
@my-tien
Fix indentation in zz-pie-slice-legend mocks
8f983db
@my-tien
Enhance readability in legend groupdefaults
a115e4e
@my-tien
Fix default legend's groupdefaults calculation being skipped when pie…
ef93f2c
….legend is an array
@my-tien
coerce.js boolean and subplotid: Actually do checks on array values.
7ec5316
@my-tien
my-tien requested a review from camdecoster November 27, 2025 13:36
my-tien added 3 commits November 27, 2025 17:22
@my-tien
Fix missing opts param in boolean coerceFunction
795b911
@my-tien
Revert accidental change in zz-pie-slice-legend3 mock
a73c4f9
@my-tien
Replace baseline images for zz-pie-slice[2].png
2636c7b
figure width was changed.
camdecoster
camdecoster reviewed Dec 1, 2025
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Here are a few more suggestions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/components/legend/defaults.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/lib/coerce.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/lib/coerce.js Outdated
return value === true || value === false;
}

if (opts.arrayOk && isArrayOrTypedArray(v) && v.length > 0 && v.every(isBoolean)) {

@camdecoster camdecoster Nov 28, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Do you anticipate typed arrays being used here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@my-tien my-tien Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

No. So the general approach is not to accept typed arrays everywhere a normal array is accepted? Should I just check for Array.isArray?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@camdecoster camdecoster Dec 2, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If no typed arrays are anticipated, then I think you should just use Array.isArray.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/lib/coerce.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/lib/coerce.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/lib/coerce.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

my-tien and others added 3 commits December 2, 2025 11:26
@my-tien @camdecoster
Update src/lib/coerce.js
b968041
coerce: Simplify test for isSubplotId

Co-authored-by: Cameron DeCoster <[email protected]>
@my-tien
Simplify code for calculation of pie showlegend defaults
51fc434
@my-tien
Simplify coerce functions for boolean and subplotId
7aa08d8
camdecoster
camdecoster approved these changes Dec 2, 2025
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good! Thanks for adding this feature.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@camdecoster
Update draftlog
cbe853b
@camdecoster
camdecoster merged commit 8be5c4b into plotly:master Dec 3, 2025
5 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@emilykl emilykl mentioned this pull request Sep 1, 2026
showlegend parameter of piechart should take a list as argument plotly/plotly.py#4671
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@camdecoster camdecoster camdecoster approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@camdecoster camdecoster

Labels

community community contribution feature something new P1 needed for current cycle

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@my-tien @alexshoe @camdecoster @gvwilson
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.