You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "learntimes (via GitHub)" <gi...@apache.org> on 2024/04/19 02:01:18 UTC

Re: [I] [Improvement] Canvas willReadFrequently warning. [echarts]

learntimes commented on issue #18199:
URL: https://github.com/apache/echarts/issues/18199#issuecomment-2065613418

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org