Skip to content

Commit

Permalink
Merge pull request #2702 from xzysun/master
Browse files Browse the repository at this point in the history
Fix CombinedChartView not draw markers
  • Loading branch information
liuxuan30 committed Sep 5, 2017
2 parents d7dc8f0 + 59218f0 commit f9eea57
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
41 changes: 41 additions & 0 deletions Source/Charts/Charts/CombinedChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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]
}
}
}

0 comments on commit f9eea57

Please sign in to comment.