From 733f803b6311f035d379cbed1958f0c0689fc7a3 Mon Sep 17 00:00:00 2001 From: Xuan Liu Date: Sun, 8 Oct 2017 11:28:51 +0800 Subject: [PATCH 1/2] for #2840. add dataIndex parameter in `highlightValue()` calls. Default is -1 --- Source/Charts/Charts/ChartViewBase.swift | 20 ++++++++++++-------- Source/Charts/Highlight/Highlight.swift | 4 +++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index 1b17d817fc..f2766da5a8 100755 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -475,9 +475,10 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// This method will call the delegate. /// - parameter x: The x-value to highlight /// - parameter dataSetIndex: The dataset index to search in - @objc open func highlightValue(x: Double, dataSetIndex: Int) + /// - parameter dataIndex: The data index to search in (only used in CombinedChartView currently) + @objc open func highlightValue(x: Double, dataSetIndex: Int, dataIndex: Int = -1) { - highlightValue(x: x, dataSetIndex: dataSetIndex, callDelegate: true) + highlightValue(x: x, dataSetIndex: dataSetIndex, dataIndex: dataIndex, callDelegate: true) } /// Highlights the value at the given x-value and y-value in the given DataSet. @@ -486,19 +487,21 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// - parameter x: The x-value to highlight /// - parameter y: The y-value to highlight. Supply `NaN` for "any" /// - parameter dataSetIndex: The dataset index to search in - @objc open func highlightValue(x: Double, y: Double, dataSetIndex: Int) + /// - parameter dataIndex: The data index to search in (only used in CombinedChartView currently) + @objc open func highlightValue(x: Double, y: Double, dataSetIndex: Int, dataIndex: Int = -1) { - highlightValue(x: x, y: y, dataSetIndex: dataSetIndex, callDelegate: true) + highlightValue(x: x, y: y, dataSetIndex: dataSetIndex, dataIndex: dataIndex, callDelegate: true) } /// Highlights any y-value at the given x-value in the given DataSet. /// Provide -1 as the dataSetIndex to undo all highlighting. /// - parameter x: The x-value to highlight /// - parameter dataSetIndex: The dataset index to search in + /// - parameter dataIndex: The data index to search in (only used in CombinedChartView currently) /// - parameter callDelegate: Should the delegate be called for this change - @objc open func highlightValue(x: Double, dataSetIndex: Int, callDelegate: Bool) + @objc open func highlightValue(x: Double, dataSetIndex: Int, dataIndex: Int = -1, callDelegate: Bool) { - highlightValue(x: x, y: Double.nan, dataSetIndex: dataSetIndex, callDelegate: callDelegate) + highlightValue(x: x, y: Double.nan, dataSetIndex: dataSetIndex, dataIndex: dataIndex, callDelegate: callDelegate) } /// Highlights the value at the given x-value and y-value in the given DataSet. @@ -506,8 +509,9 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// - parameter x: The x-value to highlight /// - parameter y: The y-value to highlight. Supply `NaN` for "any" /// - parameter dataSetIndex: The dataset index to search in + /// - parameter dataIndex: The data index to search in (only used in CombinedChartView currently) /// - parameter callDelegate: Should the delegate be called for this change - @objc open func highlightValue(x: Double, y: Double, dataSetIndex: Int, callDelegate: Bool) + @objc open func highlightValue(x: Double, y: Double, dataSetIndex: Int, dataIndex: Int = -1, callDelegate: Bool) { guard let data = _data else { @@ -521,7 +525,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate } else { - highlightValue(Highlight(x: x, y: y, dataSetIndex: dataSetIndex), callDelegate: callDelegate) + highlightValue(Highlight(x: x, y: y, dataSetIndex: dataSetIndex, dataIndex: dataIndex), callDelegate: callDelegate) } } diff --git a/Source/Charts/Highlight/Highlight.swift b/Source/Charts/Highlight/Highlight.swift index a0b585ea98..121c750e52 100644 --- a/Source/Charts/Highlight/Highlight.swift +++ b/Source/Charts/Highlight/Highlight.swift @@ -127,11 +127,13 @@ open class Highlight: NSObject /// - parameter x: the x-value of the highlighted value /// - parameter y: the y-value of the highlighted value /// - parameter dataSetIndex: the index of the DataSet the highlighted value belongs to - @objc public init(x: Double, y: Double, dataSetIndex: Int) + /// - parameter dataIndex: The data index to search in (only used in CombinedChartView currently) + @objc public init(x: Double, y: Double, dataSetIndex: Int, dataIndex: Int = -1) { _x = x _y = y _dataSetIndex = dataSetIndex + self.dataIndex = dataIndex } /// - parameter x: the x-value of the highlighted value From 62aa8b940d5494d0fe410b1f3389baf0af586954 Mon Sep 17 00:00:00 2001 From: Xuan Liu Date: Tue, 23 Jan 2018 15:54:28 +0800 Subject: [PATCH 2/2] use latest swift syntax --- Source/Charts/Charts/ChartViewBase.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index f2766da5a8..2285cb0af6 100755 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -501,7 +501,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// - parameter callDelegate: Should the delegate be called for this change @objc open func highlightValue(x: Double, dataSetIndex: Int, dataIndex: Int = -1, callDelegate: Bool) { - highlightValue(x: x, y: Double.nan, dataSetIndex: dataSetIndex, dataIndex: dataIndex, callDelegate: callDelegate) + highlightValue(x: x, y: .nan, dataSetIndex: dataSetIndex, dataIndex: dataIndex, callDelegate: callDelegate) } /// Highlights the value at the given x-value and y-value in the given DataSet.