Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Platform-specific requestAnimationFrame

Open CatchABus opened this issue 2 years ago • 3 comments

Feature Proposal

Library has a really interesting configuration that lets one use it on platforms other than browser, and that's really amazing. While using platform configuration on NativeScript for rendering charts in mobile platforms, we had trouble making animations work out of the box, unless we added a polyfill for window.

Possible Implementation

It would be helpful if platform class had support for declaring requestAnimationFrame logic internally and library used that method instead. For example:

class MyCustomPlatform extends BasePlatform {
     acquireContext(canvas) {
        // Context logic
    }

    requestAnimationFrame(callback) {
        // Frame animation logic
    }
}

This would make using animations on other platforms easier.

CatchABus avatar Nov 12 '23 18:11 CatchABus

This is a good enhancement. I'd be open to reviewing a PR that has implements this

etimberg avatar Nov 12 '23 21:11 etimberg

This is a good enhancement. I'd be open to reviewing a PR that has implements this

I would gladly work on this but it seems moving that feature to platform doesn't seem to work very well for API.

Method requestAnimationFrame is called by Animator singleton to handle the animation of multiple pending charts. However, a different platform can be set per chart so I wonder what the ideal solution would be as the feature cannot be chart-specific.

CatchABus avatar Nov 14 '23 12:11 CatchABus

Is it possible to do something like chart.platform.requestAnimationFrame? That would be my first avenue of investigation

etimberg avatar Nov 14 '23 19:11 etimberg