Skip to content

Commit

Permalink
1. fix bug in getDataSetIndex, it will detect what dataSet it is and …
Browse files Browse the repository at this point in the history
…determine how to proceed

2. I also override getMarkerPosition for CombinedChartView
  • Loading branch information
liuxuan30 committed Sep 2, 2015
1 parent 80aa1b3 commit 90a327d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
41 changes: 41 additions & 0 deletions Charts/Classes/Charts/CombinedChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,47 @@ public class CombinedChartView: BarLineChartViewBase
}
}

public override func getMarkerPosition(#entry: ChartDataEntry, highlight: ChartHighlight) -> CGPoint
{
let dataSetIndex = highlight.dataSetIndex
let dataSet = _data.getDataSetByIndex(dataSetIndex)
var xPos = CGFloat(entry.xIndex)
var yPos = entry.value

if (dataSet.isKindOfClass(BarChartDataSet))
{
var bd = (_data as! CombinedChartData).barData
var space = bd.groupSpace

let barDataSetIndex = bd.indexOfDataSet(dataSet)

var x = CGFloat(entry.xIndex * (bd.dataSetCount - 1) + barDataSetIndex) + space * CGFloat(entry.xIndex) + space / 2.0

xPos += x

if let barEntry = entry as? BarChartDataEntry
{
if barEntry.values != nil && highlight.range !== nil
{
yPos = highlight.range!.to
}
}
}

var pt = CGPoint(x: xPos, y: CGFloat(yPos) * _animator.phaseY)

if (dataSet.isKindOfClass(BarChartDataSet))
{
getBarChartTransformer(_data.getDataSetByIndex(dataSetIndex)!.axisDependency).pointValueToPixel(&pt)
}
else
{
getTransformer(_data.getDataSetByIndex(dataSetIndex)!.axisDependency).pointValueToPixel(&pt)
}

return pt
}

public override var data: ChartData?
{
get
Expand Down
23 changes: 20 additions & 3 deletions Charts/Classes/Highlight/CombinedChartHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,21 @@ internal class CombinedChartHighlighter: ChartHighlighter
{
if !barData.isGrouped
{
return 0
return super.getDataSetIndex(xIndex: xIndex, x: x, y: y)
}
else
{
let superDataSetIndex = super.getDataSetIndex(xIndex: xIndex, x: x, y: y)
let dataSet = (_chart as? CombinedChartView)?.data?.getDataSetByIndex(superDataSetIndex)

if (dataSet != nil)
{
if (dataSet!.isKindOfClass(LineChartDataSet))
{
return superDataSetIndex
}
}

let baseNoSpace = getBase(x)

let setCount = barData.dataSetCount
Expand All @@ -129,12 +140,18 @@ internal class CombinedChartHighlighter: ChartHighlighter
dataSetIndex = setCount - 1
}

return dataSetIndex
var barDataSet = barData.getDataSetByIndex(dataSetIndex)

var combinedData = (_chart as! CombinedChartView).data

var barDataSetIndexInCombinedChartData = combinedData!.indexOfDataSet(barDataSet!)

return barDataSetIndexInCombinedChartData
}
}
else
{
return 0
return super.getDataSetIndex(xIndex: xIndex, x: x, y: y)
}
}

Expand Down

0 comments on commit 90a327d

Please sign in to comment.