Skip to content

Commit

Permalink
Merge pull request #4094 from danielgindi/4093
Browse files Browse the repository at this point in the history
Fix line chart x axis animation #4093, also close #3960
  • Loading branch information
liuxuan30 authored Sep 9, 2019
2 parents dd1bb78 + 952b5c0 commit e93bfb9
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 e93bfb9

Please sign in to comment.