mermaid icon indicating copy to clipboard operation
mermaid copied to clipboard

Order pie chart slices clockwise by order of entries

Open jasmaa opened this issue 2 years ago • 3 comments

:bookmark_tabs: Summary

Order pie chart slices clockwise by order of entries.

Screenshot 2022-10-08 at 16-57-13 Mermaid testing

Resolves #3593

:straight_ruler: Design Decisions

Created an order field on pie chart data and added a sorting rule to D3 pie that sorts based on order.

:clipboard: Tasks

Make sure you

  • [x] :book: have read the contribution guidelines
  • [ ] :computer: have added unit/e2e tests (if appropriate)
  • [x] :bookmark: targeted develop branch

jasmaa avatar Oct 08 '22 21:10 jasmaa

To clarify, since it wasn't immediately obvious to me, is this a passive change? Or is the label order now the definitive ordering and to achieve the previous behavior a user would have to list the labels in descending value?

blakegearin avatar Oct 09 '22 15:10 blakegearin

That is correct. This change would make label order the definitive ordering.

jasmaa avatar Oct 09 '22 18:10 jasmaa

I think this will be helpful.

The documentation for pie charts should also be updated so users understand this. Existing users might be surprised at their pie charts suddently being re-ordered.

weedySeaDragon avatar Oct 09 '22 19:10 weedySeaDragon

I don't know what happened with the code in this issue, but it doesn't work.

pie title Pets adopted by volunteers
    "Dogs" : 386
    "Cats" : 85
    "Rats" : 155
pie title Pets adopted by volunteers
    "Dogs" : 386
    "Cats" : 85
    "Rats" : 155

Mermaid orders Rats second, so it sorts by value, not label.

JJ-Kamminga avatar Jul 04 '24 19:07 JJ-Kamminga

Looks like the index sorting order got removed in https://github.com/mermaid-js/mermaid/commit/9563b221327e4ac50f87d9e14626c974e4852a13

I'm not sure if intentional or regression though since I don't have context for changes after this one

@Yokozuna59 help?

jasmaa avatar Jul 05 '24 00:07 jasmaa

@jasmaa It has been re-added in 267935713c89b9316f0dd8750e9080072e78dcab.

Yokozuna59 avatar Jul 06 '24 01:07 Yokozuna59

It seems that it was intentional then? It would be nice if label/order sorting was possible, even if it's not the default.

If this feature will not be added back, the docs should at least be fixed, because currently they describe the previous situation.

JJ-Kamminga avatar Jul 08 '24 07:07 JJ-Kamminga

There be tests added for this. That way this won't happen again. In general, if a feature is accidentally (or intentionally) removed or a bug is found, a test should be written for it so that the removal or bug does not ever happen again.

These tests ultimately save time and effort because they stop this kind of regression.

(Of course there should be tests written when the feature is originally added so this kind of regression never happens. )

weedySeaDragon avatar Jul 08 '24 18:07 weedySeaDragon