Charts: Rendering with Core Animation

Created on 24 Dec 2017  路  6Comments  路  Source: danielgindi/Charts

@petester42 @liuxuan30 @danielgindi

Continuing on #29, why have we not considered using Core Animation instead of Core Graphics? Core Animation is what virtually all of iOS's UI is using and was recently rewritten with a Metal backing (iOS 9/macOS 10.11 I believe).

In my experience it has been hard to match the performance of Core Animation with Core Graphics code, which is probably why Core Graphics hasn't been mentioned at WWDC in many years. Given CA heavily relies on the GPU instead of the CPU AND we are not taxing the GPU, any CPU bottlenecks should be gone, performance should improve, and energy consumption should be reduced.

I understand this would be a very big undertaking (one I'd be happy to participate in), but it seems like it would be able to provide significant benefits for consumers. Given Apple's focus on Core Animation, it is likely that it will allow us keep up with modern best practices more easily.

discussion idea

Most helpful comment

Any update on this?

All 6 comments

I'm curious as well.
I guess at the first beginning, the library is just about Charts, and purely designed on CoreGraphics, not want to involve layer. And when animation comes in, it uses display link.

But can we use CA without layer? I'm not sure how we can live with layer, like for bar chart. I used to write a bar chart view, while each bar is a layer/view, the performance is not ideal than this library though (maybe because I just get started at that time). But it's great we can review back.

CA is all about layers, so there's no getting around that. I think it's likely that it was because you were just getting started in CA. I've seen games written entirely in UIKit (which is all backed by CA) which run with great performance.

(I'm guessing from experience) I think that for the simple rendering there will be slightly more work for us, but for the more complex stuff there will be less work.

+1 this would help with #2402

UIView already contains a CALayer which you can override, and every chart extends from the ChartViewBase so you could have something like this:

// MARK: - Chart Layer Provider
extension ChartViewBase: ChartLayerProvider {
    override open class var layerClass: Swift.AnyClass {
        return CAShapeLayer.self
    }

    public var chartLayer: CAShapeLayer {
        return layer as! CAShapeLayer
    }
}

And use this "ChartLayerProvider" to pass the layer to the Renderers. Looks like this will require a lot of refactoring 馃檨 But I was able to easily get the animation working with a CALayer for Cubic Bezier path! (Didn't get it to use CALayer for the fill though, so ignore that haha... Also the animation is in the draw call so that's why it is jumpy before it starts)

animation

major WIP: https://github.com/danielgindi/Charts/compare/master...iMacHumphries:feature/line-animation-with-calayer?expand=1

Any update on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deepumukundan picture deepumukundan  路  3Comments

BrandonShega picture BrandonShega  路  4Comments

Bharati555 picture Bharati555  路  4Comments

kwstasna picture kwstasna  路  3Comments

PrashantKT picture PrashantKT  路  3Comments