Skip to content
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

[graph] fix top margin location and simplify y-coordinate calculation #1915

Merged
merged 1 commit into from
Jun 20, 2023

Conversation

midichef
Copy link
Contributor

@midichef midichef commented Jun 8, 2023

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 inverse unscaleY(). The change happens to fix the topMarginPixels bug and simplify calcTopCursorY(), 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.

return p

def render_sync(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is almost-but-not-exactly identical to Canvas.render_sync? Is there any reasonable way to parameterize it for the inverted canvas, without duplicating the code?

@@ -10,6 +10,10 @@ def numericCols(vd, cols):


class InvertedCanvas(Canvas):
@asyncthread
def render_async(self):
self.plot_elements(True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all great, but we should probably use invert_y=True for good measure.

Copy link
Owner

@saulpw saulpw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again, this is really helpful. I wish you'd email me so I can send you some stickers! =)

@midichef
Copy link
Contributor Author

Oops sorry, I have just rebased the squashed version onto the latest develop commit.

@anjakefala anjakefala merged commit b401b34 into saulpw:develop Jun 20, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants