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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Charts/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

{
delegate?.chartTranslated?(self, dX: translation.x, dY: translation.y)
}
Expand Down