-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Fix condition that is checked before chartTranslated
delegate method call
#3804
Fix condition that is checked before chartTranslated
delegate method call
#3804
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3804 +/- ##
=======================================
Coverage 32.67% 32.67%
=======================================
Files 114 114
Lines 10754 10754
=======================================
Hits 3514 3514
Misses 7240 7240
Continue to review full report at Codecov.
|
@@ -816,7 +816,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD | |||
|
|||
matrix = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true) | |||
|
|||
if delegate !== nil | |||
if matrix != originalMatrix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jjatie struct in swift 4.2 is still copied on assigning right? just checked the doc it's still copied.refresh()
will override _touchMatrix
with matrix
@anton-filimonov in refresh()->limitTransAndScale()
, matrix
will be different anyway so it makes matrix != originalMatrix
always true to me... and invalidates this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liuxuan30 yes, value types are copied on assigning, but that doesn't mean that comparing those values is useless because they are compared by value not by address. And since we are on the edge of available region we always get equal matrixes back from refresh()->limitTransAndScale()
. And test shows that this change prevents calls of chartTranslated
when no translation really happens.
The thing I really forgot to do is to do the same check when scale is performed. So I'll update this PR with that change soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liuxuan30 well I checked the situation with scale and same change there is not needed this much because delegate method calls there are limited with some other conditions. False calls are still possible there but it's only one call, for example when we zoom out the chart when it's already zoomed out to minimum (on the first call object think that we zoom in because no scale was made before)
So I'm not sure this change is needed. What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anton-filimonov @liuxuan30 A struct is not copied on assigning. While a struct is passed by value, it is copy-on-write, meaning it is only copied when the two values diverge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A value type is a type whose value is copied when itβs assigned to a variable or constant, or when itβs passed to a function.
from https://docs.swift.org/swift-book/LanguageGuide/ClassesAndStructures.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested on the edge, there are some matrix == originalMatrix
cases, but there are also multiple false cases mixing up at the same time?
is this why you asked So I'm not sure this change is needed.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm not sure this change is needed.
was about adding the same change to pinch gesture handling before calling chartScaled
. There are two checks before all the work is done (canZoomMoreX
, canZoomMoreY
) and they eliminate almost all false calls, that's why I'm not sure this change is needed for that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's much easier to reproduce the issue with false calls of chartTranslated
when you scroll to the corner (I edited two last steps to reproduce the issue in #3803 ) so that translation is blocked in two directions and every scrolling step will cause no change to the transformation matrix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but there are also multiple false cases mixing up at the same time
Probably some translation still occurs in this case. Maybe for example you reached the right edge but scrolled right-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I mean, adding this fix can filter a few calls, but generally, it won't prevent the delegate get called no matter where you are. You cannot rely on it to judge if you are on edge or something.
Issue Link π
#3803
Goals β½
eliminate not needed
chartTranslated
delegate method callsImplementation Details π§
Removed check if delegate is not nil because it's already done in next line by
?
operatorAdded check that transformation matrix has really been changed before
chartTranslated
call