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

Fix condition that is checked before chartTranslated delegate method call #3804

Merged
merged 1 commit into from
Jan 14, 2019
Merged

Fix condition that is checked before chartTranslated delegate method call #3804

merged 1 commit into from
Jan 14, 2019

Conversation

anton-filimonov
Copy link

Issue Link πŸ”—

#3803

Goals ⚽

eliminate not needed chartTranslated delegate method calls

Implementation Details 🚧

Removed check if delegate is not nil because it's already done in next line by ? operator
Added check that transformation matrix has really been changed before chartTranslated call

@codecov-io
Copy link

Codecov Report

Merging #3804 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3804   +/-   ##
=======================================
  Coverage   32.67%   32.67%           
=======================================
  Files         114      114           
  Lines       10754    10754           
=======================================
  Hits         3514     3514           
  Misses       7240     7240
Impacted Files Coverage Ξ”
Source/Charts/Charts/BarLineChartViewBase.swift 67.1% <ΓΈ> (ΓΈ) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 0749a2e...7d2e2db. Read the comment docs.

@@ -816,7 +816,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD

matrix = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true)

if delegate !== nil
if matrix != originalMatrix
Copy link
Member

@liuxuan30 liuxuan30 Jan 3, 2019

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? refresh() will override _touchMatrix with matrix just checked the doc it's still copied.

@anton-filimonov in refresh()->limitTransAndScale(), matrix will be different anyway so it makes matrix != originalMatrix always true to me... and invalidates this change

Copy link
Author

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

Copy link
Author

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?

Copy link
Collaborator

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.

Copy link
Member

Choose a reason for hiding this comment

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

@jjatie

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

Copy link
Member

@liuxuan30 liuxuan30 Jan 9, 2019

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.?

Copy link
Author

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.

Copy link
Author

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

Copy link
Author

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.

Copy link
Member

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.

@liuxuan30 liuxuan30 merged commit bd3d1eb into ChartsOrg:master Jan 14, 2019
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.

4 participants