Ovilia opened a new pull request, #20705:
URL: https://github.com/apache/echarts/pull/20705
<!-- Please fill in the following information to help us review your PR more
efficiently. -->
## Brief Information
This pull request is in the type of:
- [ ] bug fixing
- [x] new feature
- [ ] others
### What does this PR do?
Add support for dynamically changing themes after chart initialization.
### Fixed issues
- #19556
- #18716
## Details
### Before: What was the problem?
Currently, themes can only be set before chart initialization.
```js
echarts.registerTheme('dark', darkTheme);
const chart = echarts.init(dom, 'dark');
// You cannot change theme after chart is created unless dispose and reinit
it.
```
There's no way to change themes dynamically after the chart is created.
The deprecated `setTheme` method in ECharts 3.0 was removed without a
replacement.
### After: How does it behave after the fixing?
Now users can:
1. Change themes dynamically using `chart.setTheme('themeName')` or
`chart.setTheme(themeObject)` for registered themes
2. If `themeName` is used, both the themes registered before or after the
chart was created can be applied.
3. Theme changes are applied immediately without needing to call `setOption`.
Example usage:
```js
// Using registered theme
echarts.registerTheme('dark', darkTheme);
const chart = echarts.init(dom);
chart.setTheme('dark');
// Dynamically register theme after chart is created
echarts.registerTheme('forest', forestTheme);
chart.setTheme('forest');
// The above is equivalent to:
chart.setTheme(forestTheme);
// The only difference is that forestTheme is an anonymous object, so it
can't be reused for other charts.
// Using theme object directly
chart.setTheme({
backgroundColor: '#333',
title: {
textStyle: {
color: '#fff'
}
}
});
```
## Document Info
One of the following should be checked.
- [ ] This PR doesn't relate to document changes
- [x] The document should be updated later
- [ ] The document changes have been made in apache/echarts-doc#xxx
## Misc
### ZRender Changes
- [x] This PR doesn't depend on ZRender changes.
### Related test cases or examples to use the new APIs
- `test/theme.html`
## Others
### Merging options
- [x] Please squash the commits into a single one when merging.
### Other information
This PR is a pre-requisite for design token feature, with which we can
dynamically change themes using design tokens.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]