From 638d97cfc50e5fad0836c8530d82d550947cb92f Mon Sep 17 00:00:00 2001 From: Nadir Ali <36660597+Xnadir@users.noreply.github.com> Date: Mon, 23 Nov 2026 05:26:27 +0500 Subject: [PATCH] fix(gauge): keep the progress list when neither pointer nor progress is shown. close #21863 GaugeView stored _progressEls only when the pointer or the progress was shown. After a render with both hidden it stayed undefined (or kept the elements of an older render), so turning the progress on afterwards threw "Cannot read properties of undefined (reading '0')" and no ring was drawn. It is now stored on every render. Co-Authored-By: Claude Opus 5.5 --- src/chart/gauge/GaugeView.ts | 6 ++- test/ut/spec/series/gauge.test.ts | 72 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 test/ut/spec/series/gauge.test.ts diff --git a/src/chart/gauge/GaugeView.ts b/src/chart/gauge/GaugeView.ts index de4aa4a2f5..6b1d5f951f 100644 --- a/src/chart/gauge/GaugeView.ts +++ b/src/chart/gauge/GaugeView.ts @@ -572,9 +572,11 @@ class GaugeView extends ChartView { toggleHoverEmphasis(progress, focus, blurScope, emphasisDisabled); } }); - - this._progressEls = progressList; } + + // Kept even when neither the pointer nor the progress is shown, so that + // the next update does not read the elements of an older render, or none. + this._progressEls = progressList; } _renderAnchor( diff --git a/test/ut/spec/series/gauge.test.ts b/test/ut/spec/series/gauge.test.ts new file mode 100644 index 0000000000..697bf16877 --- /dev/null +++ b/test/ut/spec/series/gauge.test.ts @@ -0,0 +1,72 @@ +/* +* 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 { createChart, removeChart } from '../../core/utHelper'; +import { EChartsType } from '@/src/echarts'; + + +describe('gauge', function () { + + let chart: EChartsType; + beforeEach(function () { + chart = createChart({width: 400, height: 300}); + }); + afterEach(function () { + removeChart(chart); + }); + + function gaugeOption(showProgress: boolean) { + return { + animation: false, + series: [{ + type: 'gauge', + pointer: { show: false }, + progress: { show: showProgress, width: 14 }, + data: [{ value: 68, name: 'Uptime' }] + }] + }; + } + + function progressSectors() { + const sectors: any[] = []; + (chart as any).getZr().storage.getDisplayList(true).forEach(function (el: any) { + if (el.type === 'sector' && el.shape && el.shape.r0 > 0) { + sectors.push(el); + } + }); + return sectors; + } + + it('shows the progress after a render with neither the pointer nor the progress', function () { + chart.setOption(gaugeOption(false)); + const before = progressSectors().length; + + expect(() => chart.setOption(gaugeOption(true))).not.toThrow(); + + expect(progressSectors().length).toBe(before + 1); + }); + + it('hides and shows the progress again', function () { + chart.setOption(gaugeOption(true)); + chart.setOption(gaugeOption(false)); + + expect(() => chart.setOption(gaugeOption(true))).not.toThrow(); + }); +});