Skip to content

Commit

Permalink
Use the same process for highlighting in LineChartRenderer that was…
Browse files Browse the repository at this point in the history
… used in `ScatterChartRenderer`.

Fixes ChartsOrg#1495.  I'm not sure if iterating over entries is necessary, or if this can be collapsed to
just a single `set.entryForXValue()` call.
  • Loading branch information
ryanschneider committed Oct 6, 2016
1 parent 61d10ba commit 8f2c2cb
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions Source/Charts/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -708,44 +708,47 @@ open class LineChartRenderer: LineRadarRenderer

for high in indices
{
guard let set = lineData.getDataSetByIndex(high.dataSetIndex) as? ILineChartDataSet
, set.isHighlightEnabled
guard
let set = lineData.getDataSetByIndex(high.dataSetIndex) as? ILineChartDataSet,
set.isHighlightEnabled
else { continue }

guard let e = set.entryForXValue(high.x) else { continue }

if !isInBoundsX(entry: e, dataSet: set)
{
continue
}

context.setStrokeColor(set.highlightColor.cgColor)
context.setLineWidth(set.highlightLineWidth)
if set.highlightLineDashLengths != nil
{
context.setLineDash(phase: set.highlightLineDashPhase, lengths: set.highlightLineDashLengths!)
}
else
{
context.setLineDash(phase: 0.0, lengths: [])
}

let x = high.x // get the x-position
let y = high.y * Double(animator.phaseY)

if x > chartXMax * animator.phaseX

let entries = set.entriesForXValue(high.x)

for entry in entries
{
continue
if entry.y != high.y { continue }

if !isInBoundsX(entry: entry, dataSet: set) { continue }

context.setStrokeColor(set.highlightColor.cgColor)
context.setLineWidth(set.highlightLineWidth)
if set.highlightLineDashLengths != nil
{
context.setLineDash(phase: set.highlightLineDashPhase, lengths: set.highlightLineDashLengths!)
}
else
{
context.setLineDash(phase: 0.0, lengths: [])
}

let x = entry.x // get the x-position
let y = entry.y * Double(animator.phaseY)

if x > chartXMax * animator.phaseX
{
continue
}

let trans = dataProvider.getTransformer(forAxis: set.axisDependency)

let pt = trans.pixelForValues(x: x, y: y)

high.setDraw(pt: pt)

// draw the lines
drawHighlightLines(context: context, point: pt, set: set)
}

let trans = dataProvider.getTransformer(forAxis: set.axisDependency)

let pt = trans.pixelForValues(x: x, y: y)

high.setDraw(pt: pt)

// draw the lines
drawHighlightLines(context: context, point: pt, set: set)
}

context.restoreGState()
Expand Down

0 comments on commit 8f2c2cb

Please sign in to comment.