plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
16.95k stars 1.86k forks source link

single-ended y-axis range specification [0,null] is not respected when x.automargin is triggered. (2.27.0) #6762

Open RichardNeill opened 11 months ago

RichardNeill commented 11 months ago

Please take a look at this: https://codepen.io/RichardNeill/pen/rNPVKKV in plotly 2.27.0 or 2.26.2

  1. Note that the y-axis range is specified as [0,null]. This means y-min must be explicitly 0, while y-max should be automatic, according to the data.
  2. Observe that the point on Wed 25th,00:00, with a value of -68 is visible, DESPITE the fact that the y-axis should never go below zero.
  3. Also observe that the y-axis range goes from -100 to 350, rather than 0 to 350 as expected.

This bug was tricky to reproduce. For it to happen:

  1. The y-axis range must be specified explicitly, single-sided e.g. [0,null]
    If the y-axis is automatic, the desired behaviour doesn't occur, while if the range is explicit at both ends: e.g. [0,300], the bug does not appear.

  2. Turning off x.automargin prevents the bug from manifesting.

  3. If the window width is too large (on my screen, this is at ~ 1920px), or there are too few data-points, this allows all the X-labels to fit horizontally. Since the layout engine does not move the labels to 45-deg or vertical, this doesn't trigger the x.automargin behaviour, which in turn prevents the y_axis[0] from getting borked.

I hope this is helpful. Thank you for your time.

alexcjohnson commented 11 months ago

Nice detective work @RichardNeill! As a workaround until we resolve this, you can use yaxis: {autorangeoptions: {minallowed:0}} to get the same initial effect without the bug.