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

Allow turning off drag in X and Y axes separately. #2413

Merged
merged 2 commits into from
Sep 7, 2017
Merged
Changes from 1 commit
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
31 changes: 30 additions & 1 deletion Source/Charts/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
fileprivate var _pinchZoomEnabled = false
fileprivate var _doubleTapToZoomEnabled = true
fileprivate var _dragEnabled = true
fileprivate var _dragYEnabled = true
Copy link
Member

Choose a reason for hiding this comment

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

Shall we change to false by default? Ideally this should be set by user explicitly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dragEnabled is true by default. Having dragYEnabled false by default would change the current default behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

oops, my bad. Lots of || and !..

fileprivate var _dragXEnabled = true

fileprivate var _scaleXEnabled = true
fileprivate var _scaleYEnabled = true
Expand Down Expand Up @@ -853,8 +855,11 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
{
if gestureRecognizer == _panGestureRecognizer
{
let velocity = _panGestureRecognizer.velocity(in: self)
if _data === nil || !_dragEnabled ||
(self.hasNoDragOffset && self.isFullyZoomedOut && !self.isHighlightPerDragEnabled)
(self.hasNoDragOffset && self.isFullyZoomedOut && !self.isHighlightPerDragEnabled) ||
(!_dragYEnabled && fabs(velocity.y) > fabs(velocity.x)) ||
(!_dragXEnabled && fabs(velocity.y) < fabs(velocity.x))
{
return false
}
Expand Down Expand Up @@ -1517,10 +1522,34 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
if _dragEnabled != newValue
{
_dragEnabled = newValue
_dragYEnabled = newValue
_dragXEnabled = newValue
}
}
}

open var dragYEnabled: Bool {
get
{
return _dragYEnabled
}
set
{
_dragYEnabled = newValue
}
}

open var dragXEnabled: Bool {
get
{
return _dragXEnabled
}
set
{
_dragXEnabled = newValue
}
}

/// is dragging enabled? (moving the chart with the finger) for the chart (this does not affect scaling).
open var isDragEnabled: Bool
{
Expand Down