From 0c0f46685634533c2ec201b186762948e210d7a9 Mon Sep 17 00:00:00 2001 From: Justin-ZS Date: Tue, 21 Apr 2026 17:18:49 +0800 Subject: [PATCH] fix(parallel): preserve areaSelectStyle on persisted selection. close #21583 --- src/component/helper/BrushController.ts | 7 +- .../component/helper/BrushController.test.ts | 74 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 test/ut/spec/component/helper/BrushController.test.ts diff --git a/src/component/helper/BrushController.ts b/src/component/helper/BrushController.ts index 09022330a7..f394491862 100644 --- a/src/component/helper/BrushController.ts +++ b/src/component/helper/BrushController.ts @@ -72,7 +72,9 @@ export interface BrushCoverConfig { panelId?: string; brushMode?: BrushMode; - // `brushStyle`, `transformable` is not mandatory, use DEFAULT_BRUSH_OPT by default. + // `brushStyle`, `transformable` is not mandatory. When the controller is enabled, + // `updateCovers` inherits from the current brush option first, and then falls back + // to `DEFAULT_BRUSH_OPT`. brushStyle?: Pick; transformable?: boolean; removeOnClick?: boolean; @@ -381,8 +383,9 @@ class BrushController extends Eventful<{ assert(this._mounted); } + const baseBrushOption = this._brushOption || DEFAULT_BRUSH_OPT; coverConfigList = map(coverConfigList, function (coverConfig) { - return merge(clone(DEFAULT_BRUSH_OPT), coverConfig, true); + return merge(clone(baseBrushOption), coverConfig, true); }) as BrushCoverConfig[]; const tmpIdPrefix = '\0-brush-index-'; diff --git a/test/ut/spec/component/helper/BrushController.test.ts b/test/ut/spec/component/helper/BrushController.test.ts new file mode 100644 index 0000000000..94f3382f82 --- /dev/null +++ b/test/ut/spec/component/helper/BrushController.test.ts @@ -0,0 +1,74 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +import BrushController from '../../../../../src/component/helper/BrushController'; +import { createChart } from '../../../core/utHelper'; +import { EChartsType } from '../../../../../src/echarts'; +import Rect from 'zrender/src/graphic/shape/Rect'; + + +describe('component/helper/BrushController', function () { + + let chart: EChartsType; + + beforeEach(function () { + chart = createChart(); + }); + + afterEach(function () { + chart.dispose(); + }); + + it('updateCovers inherits the enabled brush style', function () { + const controller = new BrushController(chart.getZr()).mount(); + const brushStyle = { + fill: 'rgba(255, 0, 0, 0.35)', + stroke: 'rgb(255, 0, 0)', + lineWidth: 6, + opacity: 0.45 + }; + + controller + .enableBrush({ + brushType: 'lineX', + brushStyle: brushStyle, + transformable: false, + removeOnClick: true + }) + .updateCovers([{ + brushType: 'lineX', + range: [20, 60] + }]); + + // @ts-ignore access internal state for behavior verification. + const cover = controller._covers[0]; + // @ts-ignore access internal state for behavior verification. + const brushOption = cover.__brushOption; + const mainEl = cover.childAt(0) as Rect; + + expect(brushOption.brushStyle).toEqual(brushStyle); + expect(brushOption.transformable).toEqual(false); + expect(brushOption.removeOnClick).toEqual(true); + expect(mainEl.style.fill).toEqual(brushStyle.fill); + expect(mainEl.style.stroke).toEqual(brushStyle.stroke); + expect(mainEl.style.lineWidth).toEqual(brushStyle.lineWidth); + expect(mainEl.style.opacity).toEqual(brushStyle.opacity); + }); + +});