echarts
echarts copied to clipboard
[Improvement] Canvas willReadFrequently warning.
What problem does this feature solve?
No bug, no feature. Just something I see on console (Chrome 109):
Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true. See: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently
What does the proposed API look like?
I have no idea. I just wanted to report this. Maybe we find a solution?
@infacto Please provide a demo for the issue either with Official Editor, CodePen, CodeSandbox or JSFiddle.
// Temporarily override getContext method to set willReadFrequently // Use this method with caution to ensure it does not interfere with other parts of your application. const originalGetContext = HTMLCanvasElement.prototype.getContext HTMLCanvasElement.prototype.getContext = function (type, attributes) { if (type === '2d') { attributes = { ...attributes, willReadFrequently: true } } return originalGetContext.call(this, type, attributes) }
mChart = echarts.init(target.value)
// Restore the getContext method after initialization to avoid affecting other canvas elements on the page. // Use setTimeout to ensure that ECharts initialization has completed setTimeout(() => { HTMLCanvasElement.prototype.getContext = originalGetContext }, 1000) // Restore after a delay of 1000 milliseconds, adjust based on actual situation
The answer above was provided by AI,
The issue has been around for a long time, perhaps echarts should provide a property to set willReadFrequently, just like this:
mChart = echarts.init(target.value, null, { renderer: 'canvas', willReadFrequently: true })
So as of today, are there any configurations that support willReadFrequently? I didn't see this configuration in the documentation.