From b7c4db0f51003b62ebfe4ced515aed2920416dfc Mon Sep 17 00:00:00 2001 From: Eric Yuan Date: Mon, 24 Apr 2017 10:35:49 +0800 Subject: [PATCH] add switch for clearing `lastHighlighted` in clear() (#2355) add switch for clearing `lastHighlighted` in clear() fixing a bug: when clearing chart, the 'lastHighlighted' var isn't set to nil. This will cause user to tap twice to highlight the new value, if the new value's index is the same as the old 'lastHighlighted' var's. * adding a switch it controls whether to clear the lasthighlighted value or not --- Source/Charts/Charts/ChartViewBase.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index 695a622996..297f3bb239 100755 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -155,7 +155,10 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// flag that indicates if offsets calculation has already been done or not fileprivate var _offsetsCalculated = false - + + /// if `true` , when call clear(), also set lastHighlighted to nil + open var clearLastHighlightedEnabled = false + /// array of Highlight objects that reference the highlighted slices in the chart internal var _indicesToHighlight = [Highlight]() @@ -276,6 +279,10 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate _data = nil _offsetsCalculated = false _indicesToHighlight.removeAll() + if clearLastHighlightedEnabled + { + lastHighlighted = nil + } setNeedsDisplay() }