Skip to content

Conversation

@CarterLi
Copy link
Contributor

Web workers do support addEventListener ( aka. EventTarget ) and requestAnimationFrame, but worker do not have the global object window.

Instead of window, we should use a better option to get the global object. globalThis is the best option indeed, but we can't use it due to its poor compatibility. Browser and worker both support self, and it has very good browser compatibility. Using self can be a better option than using window.

This PR generally enables OffscreenCanvas support of zrender, which may greatly improve the performance of echarts.

Ref: apache/echarts#9232

@yuqianma
Copy link
Contributor

Good catch!
But maybe it's unnecessary to instance a handlerProxy?
I had bypassed the proxy and used the handler directly in a different case.

@CarterLi
Copy link
Contributor Author

CarterLi commented Mar 20, 2019

I had bypassed the proxy and used the handler directly in a different case.

I'm not sure I understand what you mean, but do you mean using zrender.handler directly?

I know I can access zrender.handler by using echartsInstance._zr.handler, but I don't know if it's a good idea of accessing the private _zr property. AFAIK triggering mouse events using dispatchEvent is a much easier way to reuse existing code.

@yuqianma
Copy link
Contributor

Got it. It's reasonable in echarts.
I'm using zrender alone. Considering some non-browser environments, I keep dom event things away to make it easier.

@CarterLi
Copy link
Contributor Author

I have tried bypassing handlerProxy by calling echartsInstance._zr.zrender.trigger directly (zrX, zrY and friends are set before), and got various errors.

I gave up, and reverted back to dispatchEvent on OffscreenCanvas.

@CarterLi CarterLi closed this Sep 15, 2020
@CarterLi CarterLi reopened this Sep 15, 2020
@CarterLi
Copy link
Contributor Author

CarterLi commented Sep 15, 2020

It has been more than 1 year, any chance to review this?

I have tested that even IE5 ( with IE11 compatible mode though ) supports self

@pissang
Copy link
Contributor

pissang commented Sep 15, 2020

@CarterLi Sorry for missing this PR.

addEventListener in web worker is for receiving messages. It doesn't have the function of listening to mouse events. Ignoring it and still treat it as in the dom environment may lead to other problems in the further.

About mouse event. Perhaps you can reference to the code in ECharts GL.
https://github.com/ecomfe/echarts-gl/blob/master/src/util/EChartsSurface.js#L140

It does a similar thing.

@CarterLi
Copy link
Contributor Author

Thanks @pissang

@CarterLi CarterLi closed this Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants