Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CombinedChartView not draw markers #2702

Merged
merged 3 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
}
}
}