From d389c4f78380140ff8755489ef79f85bca916e3b Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Fri, 30 Oct 2015 10:14:20 +0200 Subject: [PATCH] Fixed (again...) the highlight vs. drag issue (Closes #520, closes #521) --- .../Classes/Charts/BarLineChartViewBase.swift | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Charts/Classes/Charts/BarLineChartViewBase.swift b/Charts/Classes/Charts/BarLineChartViewBase.swift index 556a95b8ac..a31d416f11 100644 --- a/Charts/Classes/Charts/BarLineChartViewBase.swift +++ b/Charts/Classes/Charts/BarLineChartViewBase.swift @@ -763,15 +763,23 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar { stopDeceleration() - if !_dataNotSet && _dragEnabled && - (!self.hasNoDragOffset || !self.isFullyZoomedOut || self.isHighlightPerDragEnabled) + if _dataNotSet + { // If we have no data, we have nothing to pan and no data to highlight + return; + } + + // If drag is enabled and we are in a position where there's something to drag: + // * If we're zoomed in, then obviously we have something to drag. + // * If we have a drag offset - we always have something to drag + if self.isDragEnabled && + (!self.hasNoDragOffset || !self.isFullyZoomedOut) { _isDragging = true _closestDataSetToTouch = getDataSetByTouchPoint(recognizer.locationOfTouch(0, inView: self)) let translation = recognizer.translationInView(self) - let didUserDrag = (self is HorizontalBarChartView) ? translation.y != 0.0 : translation.x != 0.0 + let didUserDrag = (self is HorizontalBarChartView) ? translation.y != 0.0 : translation.x != 0.0 // Check to see if user dragged at all and if so, can the chart be dragged by the given amount if (didUserDrag && !performPanChange(translation: translation)) @@ -794,6 +802,12 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar _lastPanPoint = recognizer.translationInView(self) } + else if self.isHighlightPerDragEnabled + { + // We will only handle highlights on UIGestureRecognizerState.Changed + + _isDragging = false + } } else if (recognizer.state == UIGestureRecognizerState.Changed) {