Skip to content

Commit

Permalink
fix #4093, also close #3960
Browse files Browse the repository at this point in the history
1. change XBounds iterator to use self.min + self.range rather than self.x
2. align drawLinear,  drawCubicBezier to new XBounds iterator.
3. fix unexpected dash line during linear animation due to reading the next entry point
  • Loading branch information
liuxuan30 committed Aug 7, 2019
1 parent 8c28cfa commit 952b5c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ extension BarLineScatterCandleBubbleRenderer.XBounds: Sequence {
}

public func makeIterator() -> Iterator {
return Iterator(min: self.min, max: self.max)
return Iterator(min: self.min, max: self.min + self.range)
}
}

extension BarLineScatterCandleBubbleRenderer.XBounds: CustomDebugStringConvertible
{
public var debugDescription: String
{
return "min:\(self.min), max:\(self.max), range:\(self.range)"
}
}
11 changes: 6 additions & 5 deletions Source/Charts/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ open class LineChartRenderer: LineRadarRenderer
// Take an extra point from the left, and an extra from the right.
// That's because we need 4 points for a cubic bezier (cubic=4), otherwise we get lines moving and doing weird stuff on the edges of the chart.
// So in the starting `prev` and `cur`, go -2, -1
// And in the `lastIndex`, add +1

let firstIndex = _xBounds.min + 1
let lastIndex = _xBounds.min + _xBounds.range

var prevPrev: ChartDataEntry! = nil
var prev: ChartDataEntry! = dataSet.entryForIndex(max(firstIndex - 2, 0))
Expand All @@ -133,7 +131,7 @@ open class LineChartRenderer: LineRadarRenderer
// let the spline start
cubicPath.move(to: CGPoint(x: CGFloat(cur.x), y: CGFloat(cur.y * phaseY)), transform: valueToPixelMatrix)

for j in stride(from: firstIndex, through: lastIndex, by: 1)
for j in _xBounds.dropFirst() // same as firstIndex
{
prevPrev = prev
prev = cur
Expand Down Expand Up @@ -316,8 +314,8 @@ open class LineChartRenderer: LineRadarRenderer
// Allocate once in correct size
_lineSegments = [CGPoint](repeating: CGPoint(), count: pointsPerEntryPair)
}
for j in stride(from: _xBounds.min, through: _xBounds.range + _xBounds.min, by: 1)

for j in _xBounds.dropLast()
{
var e: ChartDataEntry! = dataSet.entryForIndex(j)

Expand All @@ -328,6 +326,9 @@ open class LineChartRenderer: LineRadarRenderer

if j < _xBounds.max
{
// TODO: remove the check.
// With the new XBounds iterator, j is always smaller than _xBounds.max
// Keeping this check for a while, if xBounds have no further breaking changes, it should be safe to remove the check
e = dataSet.entryForIndex(j + 1)

if e == nil { break }
Expand Down

0 comments on commit 952b5c0

Please sign in to comment.