Skip to content

Commit 2565079

Browse files
committed
fix: Change the thought process
1 parent 6be0e14 commit 2565079

File tree

2 files changed

+106
-7
lines changed

2 files changed

+106
-7
lines changed

src/model/Global.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ class GlobalModel extends Model<ECUnitOption> {
242242
* @return Whether option changed.
243243
*/
244244
resetOption(
245-
type: 'recreate' | 'timeline' | 'media',
245+
type: 'recreate' | 'timeline' | 'media'| 'theme',
246246
opt?: Pick<GlobalModelSetOptionOpts, 'replaceMerge'>
247247
): boolean {
248248
return this._resetOption(type, normalizeSetOptionInput(opt));
249249
}
250250

251251
private _resetOption(
252-
type: 'recreate' | 'timeline' | 'media',
252+
type: 'recreate' | 'timeline' | 'media'| 'theme',
253253
opt: InnerSetOptionOpts
254254
): boolean {
255255
let optionChanged = false;
@@ -283,6 +283,13 @@ class GlobalModel extends Model<ECUnitOption> {
283283
// If we really need to modify a props in each `MediaUnit['option']`, use the full version
284284
// (`{baseOption, media}`) in `setOption`.
285285
// For `timeline`, the case is the same.
286+
if (type === 'theme') {
287+
const themeOption = this._theme.option;
288+
if (themeOption) {
289+
optionChanged = true;
290+
this._mergeOption({ theme: themeOption }, opt);
291+
}
292+
}
286293

287294
if (!type || type === 'recreate' || type === 'timeline') {
288295
const timelineOption = optionManager.getTimelineOption(this);
@@ -322,6 +329,9 @@ class GlobalModel extends Model<ECUnitOption> {
322329

323330
resetSourceDefaulter(this);
324331

332+
if (newOption.theme) {
333+
mergeTheme(option, newOption.theme);
334+
}
325335
// If no component class, merge directly.
326336
// For example: color, animaiton options, etc.
327337
each(newOption, function (componentOption, mainType: ComponentMainType) {
@@ -547,7 +557,7 @@ echarts.use([${seriesImportName}]);`);
547557

548558
setTheme(theme: object) {
549559
this._theme = new Model(theme);
550-
this._resetOption('recreate', null);
560+
this._resetOption('theme', null);
551561
}
552562

553563
getTheme(): Model {
@@ -1012,8 +1022,7 @@ function isNotTargetSeries(seriesModel: SeriesModel, payload: Payload): boolean
10121022
}
10131023

10141024
function mergeTheme(option: ECUnitOption, theme: ThemeOption): void {
1015-
// PENDING
1016-
// NOT use `colorLayer` in theme if option has `color`
1025+
10171026
const notMergeColorLayer = option.color && !option.colorLayer;
10181027

10191028
each(theme, function (themeItem, name) {
@@ -1023,8 +1032,6 @@ function mergeTheme(option: ECUnitOption, theme: ThemeOption): void {
10231032
return;
10241033
}
10251034

1026-
// If it is component model mainType, the model handles that merge later.
1027-
// otherwise, merge them here.
10281035
if (!ComponentModel.hasClass(name)) {
10291036
if (typeof themeItem === 'object') {
10301037
option[name] = !option[name]

test/theme-switch-keep-data.html

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)