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

Why set barRect.size.height = bottom - top to be negative? #465

Closed
liuxuan30 opened this issue Oct 12, 2015 · 5 comments
Closed

Why set barRect.size.height = bottom - top to be negative? #465

liuxuan30 opened this issue Oct 12, 2015 · 5 comments

Comments

@liuxuan30
Copy link
Member

@danielgindi I was looking into some details about bar chart view today, and I found that the barRect height is negative after calculation, this surprised me a little. Could you explain some details here? Also, where you made the trick to handle the negative height? I don't see you manipulate the matrix.

var top = isInverted ? (y <= 0.0 ? CGFloat(y) : 0) : (y >= 0.0 ? CGFloat(y) : 0)
var bottom = isInverted ? (y >= 0.0 ? CGFloat(y) : 0) : (y <= 0.0 ? CGFloat(y) : 0)
...
barRect.origin.x = left
barRect.size.width = right - left
barRect.origin.y = top
barRect.size.height = bottom - top // supposed to be negative
@danielgindi
Copy link
Collaborator

It could be negative or positive, depending on the specific bar - but you don't have to do any "trick", as all rendering platforms (that I know of, including iOS and Android) take care of negative heights automatically.
It's simple for them because they do not consider width and height, but x1 = left, x2 = left + width, y1 = top, y2 = top + height

@liuxuan30
Copy link
Member Author

@danielgindi but if I try to use barRect.size.height = abs(bottom - top), it actually broke the rendering. Any ideas?

@danielgindi
Copy link
Collaborator

Of course it did, you have change its direction. y2 = (10 + (-50)) = -40 vs y2 = (10 + abs(-50)) = 60

@liuxuan30
Copy link
Member Author

Ah I see. Thanks for the lesson!

@danielgindi
Copy link
Collaborator

:-)

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

No branches or pull requests

2 participants