Plotly.js: Let the first sector of a pie chart unfold counterclockwise

Created on 7 May 2020  路  7Comments  路  Source: plotly/plotly.js

When I create a pie chart, and I set attribute direction = "counterclockwise", I would like that the first sector can be configured to unfold counterclockwise as well.

Although I could "manually" compute the angular width of the sector and subtract it from the desired value in the rotation argument, that would still fix the first edge (in clockwise order) when I turn on/off categories in the legend, and thus the last edge would not be aligned with the desired rotation. The desired behavior would be that the last edge is fixed so that the rotation argument fixes the rotation of the first sector shown, no matter which one it is.

In this example, the first sector "a" unfolds clockwise, while the categories are plot counterclockwise
from the reference direction (12 o'clock):

As a workaround, I can subtract the width of first category from the desired value for
rotation; this is ok as long as all traces are active, but not when they are clicked on/off on legend:

feature

Most helpful comment

This makes sense and we'd certainly accept a pull request that added a new attribute to pie traces to control the placement of the first slice to make it work more similarly to something like Excel :)

This attribute could be called e.g. firstslicedirection with accepted values forward and reverse (defaulting to reverse to preserve the current behaviour for existing users).

All 7 comments

+1 for the ability to let the 1st slice go "the logical way", ie from right (angle 0) to the left (ex angle minus 20) when going anticlockwise.

FYI, more complete workaround (for R only) here in this closed issue https://github.com/ropensci/plotly/issues/1564

Yes, I created that issue in the ropensci repo myself. The problem is that the behavior is not as expected when I turn traces off.

This makes sense and we'd certainly accept a pull request that added a new attribute to pie traces to control the placement of the first slice to make it work more similarly to something like Excel :)

This attribute could be called e.g. firstslicedirection with accepted values forward and reverse (defaulting to reverse to preserve the current behaviour for existing users).

Would this affect also a "clockwise" pie chart? If so, defaulting to reverse would imply that the first slice would go "counterclockwise", instead of "clockwise" (i.e. forward) as it is now.

If it helps clarifying it, please consider the accepted values clockwise and counterclockwise instead.

I think that it's more flexible/orthogonal to support forward/reverse with respect to the existing direction attribute, so if direction is clockwise then the reverse firstslicedirection means "counterclockwise" and vice-versa.

Ok, I think I missunderstood, it's clear now. I'd also like to ask, is there any reason for not using a boolean (e.g. reversefirstslice = false/true) instead?

That would be fairly equivalent, yes.

Was this page helpful?
0 / 5 - 0 ratings