Skip to content

Commit ccb143c

Browse files
committed
Improvements to highlight animation phase applying
1 parent 19e6b43 commit ccb143c

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

Charts/Classes/Renderers/BarChartRenderer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,15 @@ public class BarChartRenderer: ChartDataRendererBase
262262

263263
let left = x - barWidth + barspacehalf
264264
let right = x + barWidth - barspacehalf
265-
let top = CGFloat(y1) * CGFloat(_animator.phaseY)
266-
let bottom = CGFloat(y2) * CGFloat(_animator.phaseY)
265+
let top = CGFloat(y1)
266+
let bottom = CGFloat(y2)
267267

268268
rect.origin.x = left
269269
rect.origin.y = top
270270
rect.size.width = right - left
271271
rect.size.height = bottom - top
272272

273-
trans.rectValueToPixel(&rect)
273+
trans.rectValueToPixel(&rect, phaseY: _animator.phaseY)
274274
}
275275

276276
public override func drawValues(context context: CGContext?)

Charts/Classes/Renderers/HorizontalBarChartRenderer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ public class HorizontalBarChartRenderer: BarChartRenderer
221221

222222
let top = x - barWidth + barspacehalf
223223
let bottom = x + barWidth - barspacehalf
224-
let left = CGFloat(y1) * CGFloat(_animator.phaseY)
225-
let right = CGFloat(y2) * CGFloat(_animator.phaseY)
224+
let left = CGFloat(y1)
225+
let right = CGFloat(y2)
226226

227227
rect.origin.x = left
228228
rect.origin.y = top
229229
rect.size.width = right - left
230230
rect.size.height = bottom - top
231231

232-
trans.rectValueToPixelHorizontal(&rect)
232+
trans.rectValueToPixelHorizontal(&rect, phaseY: _animator.phaseY)
233233
}
234234

235235
public override func getTransformedValues(trans trans: ChartTransformer, entries: [BarChartDataEntry], dataSetIndex: Int) -> [CGPoint]

Charts/Classes/Utils/ChartTransformer.swift

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,11 @@ public class ChartTransformer: NSObject
205205
public func rectValueToPixel(inout r: CGRect, phaseY: CGFloat)
206206
{
207207
// multiply the height of the rect with the phase
208-
if (r.origin.y > 0.0)
209-
{
210-
r.origin.y *= phaseY
211-
}
212-
else
213-
{
214-
var bottom = r.origin.y + r.size.height
215-
bottom *= phaseY
216-
r.size.height = bottom - r.origin.y
217-
}
208+
var bottom = r.origin.y + r.size.height
209+
bottom *= phaseY
210+
let top = r.origin.y * phaseY
211+
r.size.height = bottom - top
212+
r.origin.y = top
218213

219214
r = CGRectApplyAffineTransform(r, valueToPixelMatrix)
220215
}
@@ -229,16 +224,11 @@ public class ChartTransformer: NSObject
229224
public func rectValueToPixelHorizontal(inout r: CGRect, phaseY: CGFloat)
230225
{
231226
// multiply the height of the rect with the phase
232-
if (r.origin.x > 0.0)
233-
{
234-
r.origin.x *= phaseY
235-
}
236-
else
237-
{
238-
var right = r.origin.x + r.size.width
239-
right *= phaseY
240-
r.size.width = right - r.origin.x
241-
}
227+
var right = r.origin.x + r.size.width
228+
right *= phaseY
229+
let left = r.origin.x * phaseY
230+
r.size.width = right - left
231+
r.origin.x = left
242232

243233
r = CGRectApplyAffineTransform(r, valueToPixelMatrix)
244234
}

0 commit comments

Comments
 (0)