Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pie legend and showlegend per slice#7580

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
my-tien wants to merge20 commits intoplotly:master
base:master
Choose a base branch
Loading
frommy-tien:pie-legend-visibility

Conversation

@my-tien
Copy link
Contributor

@my-tienmy-tien commentedOct 13, 2025
edited
Loading

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 andtraces.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 whenlabel0 anddlabel are set instead oflabels.

Note:

This feature is not expected to work when pievalues are not set.

DisclaimerI 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.

@alexshoealexshoe self-assigned thisOct 14, 2025
@gvwilsongvwilson added featuresomething new communitycommunity contribution P1needed for current cycle labelsOct 28, 2025
@my-tien
Copy link
ContributorAuthor

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

@alexshoe
Copy link
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

@my-tien
Copy link
ContributorAuthor

my-tien commentedNov 25, 2025
edited
Loading

@alexshoe Hi Alex, I saw that my branch got out of date and conflicted with the currenttest/plot-schema.json .
I merged master into my branch, rerannpm 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 vianpm run i -d and I have canvas in my node_modules folder)?

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

plotly.js@3.3.0 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

@camdecoster
Copy link
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.

@my-tien
Copy link
ContributorAuthor

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!

Copy link
Contributor

@camdecostercamdecoster left a 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.

Comment on lines 65 to 69
!Array.isArray(trace.showlegend)
?trace.showlegend||trace._dfltShowLegend
:trace.showlegend[index]==null
?trace._dfltShowLegend
:trace.showlegend[index]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please refactor this to avoid nested ternary expressions?

my-tien reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Hope it's clearer now! Leaving the conversation unresolved for your judgement :)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@camdecostercamdecosterAwaiting requested review from camdecoster

Requested changes must be addressed to merge this pull request.

Assignees

@camdecostercamdecoster

Labels

communitycommunity contributionfeaturesomething newP1needed for current cycle

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@my-tien@alexshoe@camdecoster@gvwilson

[8]ページ先頭

©2009-2025 Movatter.jp