-
-
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
Charts 3: Horizontally scrolling BarChart in a vertically scrolling UIScrollView? #1847
Comments
Would you be able to provide your own gesture handler for your needs? It looks like you already had the solution. The library can't satisfy all needs, and the handler is private - you can provide you own. |
hi, I have similar scenario,that,I disable Y axis scale,but I can not scroll vertically tableview in the chart.
in func diff:
|
@liuxuan30 thank you for responding. I appreciate that Charts can't be all things to all apps. I hope you see my point it's a poor user experience when a tap+vertical pan in one part of a TableCell scrolls the table as expected, but the same tap+pan action on the BarChartView in that cell has no effect. In my case 80% of a row's height is the chart, so most of the cell is effectively dead space. I respectfully urge you to reconsider support for this use case. If a pan occurs on an axis in which the chart has no interest, I contend Charts should not unilaterally decide the pan gesture is of no interest to the parent UIScrollView either. IMO there should be a mechanism that allows the app code to participate in that decision. For example, if I drag diagonally across the BarChart, it may be perfectly acceptable in some UIs for the chart to scroll horizontally while the table scrolls vertically. That aside, I perhaps misunderstand your recommendation to provide my own PanGestureRecognizer. Would you mind describing your approach in more detail? If I add a PanGestureRecognizer to the BarChartView, I can in the associated "panGestureRecognized" action method, when recognizer.state == .changed, check recognizer.translation.y, and if it's a vertical drag, I could update TableView.contentOffset to scroll the table vertically. But because BarLineChartViewBase.panGestureRecognized(_:) sets the TableView.isScrollEnabled false for the lifetime of the Pan gesture, the contentOffset changes made by my PGR will have no effect until the pan ends when BarLineChartViewBase reenables TableView scrolling. My PGR delegate's gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) would be of no help here. My shouldRecognizeSimultaneouslyWith: would need to know whether it's a horizontal or vertical pan in order to decide whether BarChartView's PGR should be allowed to "RecognizeSimultaneously" the gesture. But the pan translation direction isn't known at this point. What am I missing? Thanks! |
Hey @spalmen, thanks for writing. What I am saying is that, the gesture handlers are private func, so you can provide another gesture handler in your sub class to replace the old one, than you can do whatever you want. You shouldn't add a duplicated gesture, just replace the handlers. I know the scrolling in a UIScrollView is a problem, there is another thread also talking about this, like #1931. It would be nice that we can have more fine-grained control over this. However, it usually is a custom situation, and you know we can't satisfy them all, and usually it might bind to business logic which is easier on your side to solve that, not us. So bottom line: you can replace the handler to solve your problems; and you are more than welcome to file a PR for this feature, satisfying the library code style. |
On Dec 12, 2016, at 05:40 PM, Xuan <notifications@github.com> wrote:
Hey@spalmen, thanks for writing. What I am saying is that, the gesture handlers are private func, so you can provide another gesture handler in your sub class to replace the old one, than you can do whatever you want. You shouldn't add a duplicated gesture, just replace the handlers.
I know the scrolling in a UIScrollView is a problem, there is another thread also talking about this, like #1931. It would be nice that we can have more fine-grained control over this. It would be better that you guys can contribute when you can, we are very short handed, and also have to work daily and take care of family..
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Hi @liuxuan30,
Hey, if my tone came across and unappreciative or demanding, I _deeply_ apologize -- it wasn't my intent. I know Charts isn't your "day" job, and well understand the demands of family and work. I am grateful for your efforts to help me, and the Charts community at large. Thank you.
It would be better that you guys can contribute when you can, we are very short handed.
OK. I'll bite. How do I "sign up" to help? I'm a Charts nooB, I know only the limited ways I use Line and Bar charts, but yah, if you have some "easy" issues to see if I have the skills to help out, I'll give it a shot.
Re: your clarification, thank you. Forgive me, if the goal is to customize Pan behavior without modifying Charts, I don't see how subclassing BarChartView and replacing the default PanGestureHandler is possible given BarLineChartViewBase's current access controls. What am I missing?
<TL;DR>
If you meant substituting a custom PanGestureRecognizer for the default created in BarLineChartViewBase.initialize(), _panGestureRecognizer is internal — my subclass can't reference it.
If it were open, BarLineChartViewBase.panGestureRecognized(_:) is fileprivate, so I can't reuse it. My custom PanGestureRecognizer handler would have to duplicate 99% of BarLineChartViewBase.panGestureRecognized, but that won't work because many of the vars and funcs it references aren't accessible outside Charts.
But 💡 if BarLineChartViewBase.panGestureRecognized(_:) were open, I wouldn't need to replace the default _panGestureRecognizer. I could just override panGestureRecognized(_:), and in my override invoke super. That way BarLineChartViewBase.panGestureRecognized(_:) manages all the relevant state — performPanChange(), isDragging, _outerScrollView.isScrollEnabled, etc. — without having to expose those funcs and vars outside Charts.
And then my override just needs to reset the outer ScrollView .isScrollEnabled if appropriate. Or so I thought.
I discovered that when BarLineChartViewBase.panGestureRecognized(_:) sets outer ScrollView.isScrollEnabled false, the side effect is the outer ScrollView's UIScrollViewPanGestureRecognizer is disabled and its state is set .cancelled. Makes sense.
Then when my BarChartView subclass panGestureRecognized(_:) override reset ScrollView.isScrollEnabled true, the ScrollView's UIScrollViewPanGestureRecognizer is re-enabled, but the gesture's state remains .cancelled. And because it's cancelled, the outer ScrollView's Pan gesture remains unresponsive for the lifetime of the pan gesture, until at the end of which its state gets reset.
Effectively, once BarLineChartViewBase.panGestureRecognized(_:) disables outer ScrollView scrolling, outer scrolling remains disabled until the pan ends. Resetting ScrollView.isScrollEnabled true in my panGestureRecognized(_:) override has no effect.
Unless I'm missing something obvious (entirely possible) that means without some refactoring here, my idea of open access to BarLineChartViewBase's Pan gesture funcs and vars isn't going to help. :(
</TL;DR>
I'm trying to avoid the maintenance burden of altering Charts source, so the simplest solution I could come up with was to add to BarLineChartViewBase an open "is outer ScrollView scrolling enabled" Bool property, that when true, causes BarLineChartViewBase.panGestureRecognized(_:) .begin to _not_ disable _outerScrollView scrolling. By default, this property is false so BarLineChartViewBase.panGestureRecognized behaves just as it does now. But it lets me control whether the outer scrolling view in which my Bar Chart resides, scrolls when the user pans on the Bar Chart. Seems to work for my use case, and doesn't break the other non-scrolling Bar Chart I have.
Cheers…
|
I didn't feel any offend, so no apology from you is needed :) For the gestures: If I found anything is private, I will modify the source code to make it public so I can continue. I know it's not always good, but it fix my problems. If you want to refer some private funcs without touching the source code, then you might want to really implement something based on the library, and get it merged, but it will take a long time. So I still suggest, if needed, use the source code of this library in your project, try not to modify it unless you really do, and leave enough comments so when you upgrade the library, you will know how do you changed it before and make it easier to upgrade. |
@spalmen Hey I have the same issue. I have to display chart in tableView, But after graph is plotted, the tableView does not scroll vertically. I did this for now,
but modifying the source file is wrong I guess. Also after doing this when I scroll (the tableView scrolls if above set to true) the tableView, the graph view in the cells stop scrolling and after I release the touch, they start scrolling again. So did you find any fix solution to your problem? Can you please help with this. I have mentioned the problem here https://github.com/danielgindi/Charts/issues/2757 |
in MyGraphTableViewCell.swift
|
I'm displaying a (Charts 3.0) BarChartView in a UIScrollView (a UITableView to be specific.)
The BarChartView is scaled on the X axis only (
setScaleMinima(n, scaleY:1)
) so the Bar chart horizontally scrolls the data set.What's the technique for enabling the containing UIScrollView to scroll vertically, when a vertical Pan gesture occurs on the BarChartView?
Charts.BarLineChartViewBase.panGestureRecognized(_:)
purposely prevents the containing Scroll view from scrolling during the Pan gesture. Paraphrasing:Note that my Bar chart does not scroll vertically, and the pan gesture translation is Y-axis only, yet Bar chart disables ScrollView scrolling for the lifetime of the gesture.
BarLineChartViewBase.gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)
is written to allow a ScrollView superview to recognize Pan gestures, and sets_outerScrollView
to my containing ScrollView, so clearly a ScrollView-contains-a-BarChartView hierarchy is supported.I've searched all the "scroll" Issues here, and SO [ios-charts], but come up empty for a Chart 3 solution.
I'm just stumped on how to configure my scaled-on-X-axis-Bar chart to allow Y-axis pan gestures to the Scroll view.
Help appreciated. Thank you.
The text was updated successfully, but these errors were encountered: