Skip to content

autorange should not display zero line for certain bars with positive base and negative value #4701

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

Closed
emmanuelle opened this issue Mar 28, 2020 · 14 comments · Fixed by #4714
Assignees
Labels
bug something broken

Comments

@emmanuelle
Copy link
Contributor

See for example https://codepen.io/emmanuelle-plotly/pen/bGdOLmR?editable=true, the axis starts at 0 and therefore a large part of the domain is not used to represent data. For other sets of data the automatic range works well.

Triggered by plotly/plotly.py#2327

@archmoj
Copy link
Contributor

archmoj commented Mar 28, 2020

Something possibly went wrong in autorange when using base and the sum (without base) goes below the initial value.

@archmoj archmoj added the bug something broken label Mar 28, 2020
@archmoj
Copy link
Contributor

archmoj commented Mar 30, 2020

Minimal demo.

@archmoj
Copy link
Contributor

archmoj commented Mar 30, 2020

It works well if we force tozero to be false e.g. here:

var tozero = opts.tozero && (ax.type === 'linear' || ax.type === '-');

@archmoj
Copy link
Contributor

archmoj commented Mar 30, 2020

Not sure if we should have tag this as a bug.
Demo using bar.

@alexcjohnson
Copy link
Collaborator

Definitely a bug - and we have logic that appears intended to address exactly this, but somehow isn't working.

tozero: !allBaseAboveZero,

@archmoj archmoj changed the title waterfall axis range bug when using base attribute autorange should not display zero line for certain bars with positive base and negative value Mar 30, 2020
@archmoj
Copy link
Contributor

archmoj commented Mar 30, 2020

minimal demo in regards with the new title.

@archmoj archmoj self-assigned this Mar 30, 2020
@alexcjohnson
Copy link
Collaborator

Ah, nice sleuthing @archmoj! In fact, to dive into the details of tozero a bit: if an axis is autoranged tozero it means two things: (1) zero is always included in the autorange, and (2) if the lowest (or highest) point on the axis is exactly zero, no padding is added past zero. This is an interesting effect: it says that for a normal bar chart or filled area chart, the size axis starts exactly at zero, but we get the normal 5% padding at the other end.

I wonder if the correct tozero logic is as simple as "true if any bar has zero base"? I don't think it matters whether the base is positive or negative, or anything about the bar size.

@archmoj
Copy link
Contributor

archmoj commented Mar 30, 2020

@alexcjohnson I think we still want to display the zero line when the values are negative.
So this codepen is OK.

@archmoj
Copy link
Contributor

archmoj commented Mar 30, 2020

See for example https://codepen.io/emmanuelle-plotly/pen/bGdOLmR?editable=true, the axis starts at 0 and therefore a large part of the domain is not used to represent data. For other sets of data the automatic range works well.

@emmanuelle thanks very much for the report. In your codepen, would you mind set plotly.js version to 1.52.3 and not use the latest?

@alexcjohnson
Copy link
Collaborator

I think we still want to display the zero line when the values are negative.
So this codepen is OK.

Why? What makes that case different from its positive twin?

@archmoj
Copy link
Contributor

archmoj commented Mar 30, 2020

I don't have strong opinion on that. Perhaps as a result of this bug, I always thought we wanted to display zerolines for bars with negative values.

@alexcjohnson
Copy link
Collaborator

To my mind the primary purpose of tozero for bar charts is the second piece, NOT adding padding past zero for one-sided data. I don't think we really ever want the first part, extending the axis to zero if the data are far from zero.

@alexcjohnson
Copy link
Collaborator

For historical context, I think before we had a base attribute we didn't even put the bottoms of the bars into the autorange calculations - and I think we still do that when there's no base at all, for performance purpose. So in that case the "extend to include zero" part of tozero is required or you wouldn't see the full bars at all.

But yeah, when there are no bars with a base at zero, there's nothing special about the value zero anymore and tozero is inappropriate.

@nicolaskruchten
Copy link
Contributor

Why? What makes that case different from its positive twin?

My feeling is that we should behave symmetrically, and not arbitrarily try to include the zero line for either positive or negative bars. This has caused issues in the past actually, so I would consider the current behaviour a bug, unless it exists to support some specific use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants