-
Notifications
You must be signed in to change notification settings - Fork 19.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ssr): add server-side rendering #15880
Conversation
chore: update download links in announcement email template
Merge release to master
Thanks for your contribution! The pull request is marked to be Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found deprecated call for getRenderedCanvas
Line 821 in b14b885
: chart.getRenderedCanvas(clone(opts)); |
@plainheart Fixed |
Congratulations! Your PR has been merged. Thanks for your contribution! 👍 |
Brief Information
This pull request is in the type of:
What does this PR do?
zrender introduces a brand new SVG renderer to support pure server-side rendering without dependencies of JSDOM and node-canvas. See the PR ecomfe/zrender#836.
This PR updates the zrender to the latest nightly version to use this new SVG renderer and introduces a new SSR mode to support rendering to SVG string without JSDOM and node-canvas.
In this new mode, the render speed is faster because we don't have to simulate the dom environment, the generated SVG string is smaller because we can do more optimizations based on the vnode, and there are more features that can be supported like CSS animation.
Usage
Sceneraios
SSR can be used in the scene that needs the chart to be displayed as fast as possible. Just like the server-side rendering in the vue and react.
The generated SVG will use CSS animation to play the basic enter animation when displayed. But user interaction is not available(perhaps we can support hover highlight with CSS in further times). We need to create a chart and
setOption
on the container again to have more rich user interactions, which is so-called hydration in the frameworks supporting SSR. This step is not integrated in echarts, you need to manage it in your project, or let wrappers likevue-echarts
do it.Limitations
Animation
Because of the limitation of CSS animation, which is not as flexible as JS animation. Animation of some series will be disabled or changed. For example, pie charts will use a very basic scale animation.
Font
Because NodeJS doesn't have the ability to measure text. It's better to use the default font in the server to have a correct layout. If you wan't to use a different font, especially the font glyph is very different from the default font, use
echarts.setCanvasCreator
to letnode-canvas
to measure the text is a better choice. Or use new addedecharts.setPlatformAPI
from ecomfe/zrender#840Misc
Other changes
echarts.setPlatformAPI
exposed directly from zrender. More detail of this method can be seen in feat: new setPlatformAPI method ecomfe/zrender#840getRenderedCanvas
is replaced byrenderToCanvas
to be more consistent with the newrenderToSVGString
API