diff --git a/Source/Charts/Charts/CombinedChartView.swift b/Source/Charts/Charts/CombinedChartView.swift index 0fce9e8d94..4464bf666f 100644 --- a/Source/Charts/Charts/CombinedChartView.swift +++ b/Source/Charts/Charts/CombinedChartView.swift @@ -222,4 +222,45 @@ open class CombinedChartView: BarLineChartViewBase, CombinedChartDataProvider /// - returns: `true` the highlight is be full-bar oriented, `false` ifsingle-value open var isHighlightFullBarEnabled: Bool { return highlightFullBarEnabled } + + // MARK:- override drawMarkers + + /// draws all MarkerViews on the highlighted positions. override here for combined chart view's special data structure + override func drawMarkers(context: CGContext) + { + guard + let marker = marker, + isDrawMarkersEnabled && valuesToHighlight() + else { return } + + for i in 0 ..< _indicesToHighlight.count + { + let highlight = _indicesToHighlight[i] + + guard + let set = combinedData?.getDataSetByHighlight(highlight), + let e = _data?.entryForHighlight(highlight) + else { continue } + + let entryIndex = set.entryIndex(entry: e) + if entryIndex > Int(Double(set.entryCount) * _animator.phaseX) + { + continue + } + + let pos = getMarkerPosition(highlight: highlight) + + // check bounds + if !_viewPortHandler.isInBounds(x: pos.x, y: pos.y) + { + continue + } + + // callbacks to update the content + marker.refreshContent(entry: e, highlight: highlight) + + // draw the marker + marker.draw(context: context, point: pos) + } + } } diff --git a/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift b/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift index d356d32994..d37e8f941a 100644 --- a/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift @@ -261,21 +261,18 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData super.notifyDataChanged() // recalculate everything } - /// Get the Entry for a corresponding highlight object /// /// - parameter highlight: /// - returns: The entry that is highlighted open override func entryForHighlight(_ highlight: Highlight) -> ChartDataEntry? { - let dataObjects = allData - - if highlight.dataIndex >= dataObjects.count + if highlight.dataIndex >= allData.count { return nil } - let data = dataObjects[highlight.dataIndex] + let data = dataByIndex(highlight.dataIndex) if highlight.dataSetIndex >= data.dataSetCount { @@ -292,8 +289,30 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData return e } } - return nil } } + + /// get data set for highlight + /// + /// - Parameter highlight: current highlight + /// - Returns: dataset related to highlight + open func getDataSetByHighlight(_ highlight: Highlight) -> IChartDataSet! + { + if highlight.dataIndex >= allData.count + { + return nil + } + + let data = dataByIndex(highlight.dataIndex) + + if highlight.dataSetIndex >= data.dataSetCount + { + return nil + } + else + { + return data.dataSets[highlight.dataSetIndex] + } + } }