echarts icon indicating copy to clipboard operation
echarts copied to clipboard

[Improvement] Canvas willReadFrequently warning.

Open infacto opened this issue 2 years ago • 4 comments

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 avatar Jan 20 '23 13:01 infacto

@infacto Please provide a demo for the issue either with Official Editor, CodePen, CodeSandbox or JSFiddle.

echarts-bot[bot] avatar Feb 01 '23 08:02 echarts-bot[bot]

// 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

learntimes avatar Apr 19 '24 02:04 learntimes

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 })

learntimes avatar Apr 19 '24 02:04 learntimes

So as of today, are there any configurations that support willReadFrequently? I didn't see this configuration in the documentation.

night-peiqi avatar Jun 30 '24 09:06 night-peiqi