Skip to content

Commit

Permalink
For ChartsOrg#2840. add dataIndex parameter in highlightValue() cal…
Browse files Browse the repository at this point in the history
…ls (ChartsOrg#2852)

* for ChartsOrg#2840. add dataIndex parameter in `highlightValue()` calls. Default is -1

* use latest swift syntax
  • Loading branch information
liuxuan30 authored and kalmurzayev committed Feb 26, 2018
1 parent 9a31804 commit 011c132
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 12 additions & 8 deletions Source/Charts/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,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.
Expand All @@ -370,28 +371,31 @@ 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: .nan, dataSetIndex: dataSetIndex, dataIndex: dataIndex, callDelegate: callDelegate)
}

/// Highlights the value at the given x-value and y-value in the given DataSet.
/// Provide -1 as the dataSetIndex to undo all highlighting.
/// - 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
{
Expand All @@ -405,7 +409,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)
}
}

Expand Down
4 changes: 3 additions & 1 deletion Source/Charts/Highlight/Highlight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,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
Expand Down

0 comments on commit 011c132

Please sign in to comment.