[graph] fix top margin location and simplify y-coordinate calculation #1915
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes are for the y-coordinate calculations in InvertedCanvas.
They do not properly take
topMarginPixels
into account, though the problem is hidden because the top margin is currently 0. If we increase it, the new margin shows up below the graph points instead of above, and the y-axis labels become misaligned.Another problem is that the calculation of y-coordinate inversion is done separately at a few too many interfaces (
plotpixel()
,scaleY()
,canvasH()
,canvasMouse()
), and sometimes with slight differences. That makes it extremely difficult to reason about y coordinates. So I have simplified the inversions, making them go through just one pair of functions:scaleY()
and its inverseunscaleY()
. The change happens to fix thetopMarginPixels
bug and simplifycalcTopCursorY()
, which is a sign it's a good way to handle the y coordinates.I've also added a fix to the y coordinates in
zoom-cursor
(zz
). The zoom used to go incorrectly to the area above the cursor. Now it zooms into it.