ChartsOrg / ChartsOrg/Charts

Charts 3: Horizontally scrolling BarChart in a vertically scrolling UIScrollView?

Open
#1,847 9 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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:
```
if recognizer.state == NSUIGestureRecognizerState.began {
if self.isDragEnabled && // true
(!self.hasNoDragOffset || !self.isFullyZoomedOut) { // hasNoDragOffset: true, isFullyZoomedOut: false because viewPortHandler.isFullyZoomedOutX is false
let translation = recognizer.translation(in: self) // .x: 0, y: -n
let didUserDrag = (self is HorizontalBarChartView) ? translation.y != 0.0 : translation.x != 0.0
if didUserDrag && !performPanChange(translation: translation) { // didUserDrag: false
} else {
_outerScrollView?.nsuiIsScrollEnabled = false // _outerScrollView: my UIScrollView
}
```
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.

Contributor guide

Open the contributing guide

Research direction

Start in BarLineChartViewBase.panGestureRecognized(_:) and gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:), which the issue identifies as controlling the chart and containing UIScrollView gestures. Trace how vertical and horizontal translations affect _outerScrollView and performPanChange. Done means vertical pans reach the containing UIScrollView while horizontally scaled BarChartView scrolling still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.