From c5c80e0dc2e0a119401ffa449fb8ee3d1b69be56 Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Mon, 2 Nov 2026 12:11:05 +0100 Subject: [PATCH] Fixed infinite loop in LED indicator, Round switch and Switch widgets font fitting (#16529) * Fixed infinite loop in LED indicator, Round switch and Switch widgets font fitting * Fixed license headers --- .../home/components/widget/lib/rpc/knob.component.ts | 8 +++----- .../components/widget/lib/rpc/led-indicator.component.ts | 5 +++-- .../components/widget/lib/rpc/round-switch.component.ts | 5 +++-- .../home/components/widget/lib/rpc/switch.component.ts | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/knob.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/knob.component.ts index f1282106c7..753ca38de1 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/knob.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/knob.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { ChangeDetectorRef, Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { WidgetContext } from '@home/models/widget-component.models'; import { deepClone, isDefined } from '@core/utils'; @@ -318,11 +319,8 @@ export class KnobComponent extends BasicActionWidgetComponent implements OnInit, private setFontSize(element: JQuery, text: string, fontSize: number, maxWidth: number) { let textWidth = this.measureTextWidth(text, fontSize); - while (textWidth > maxWidth) { + while (textWidth > maxWidth && fontSize > 1) { fontSize--; - if (fontSize < 0) { - break; - } textWidth = this.measureTextWidth(text, fontSize); } element.css({fontSize: fontSize + 'px', lineHeight: fontSize + 'px'}); diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/led-indicator.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/led-indicator.component.ts index e3974d2ec3..a0eb933bd1 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/led-indicator.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/led-indicator.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { PageComponent } from '@shared/components/page.component'; import { WidgetContext } from '@home/models/widget-component.models'; @@ -212,7 +213,7 @@ export class LedIndicatorComponent extends PageComponent implements OnInit, OnDe private setFontSize(element: JQuery, text: string, fontSize: number, maxWidth: number) { let textWidth = this.measureTextWidth(text, fontSize); - while (textWidth > maxWidth) { + while (textWidth > maxWidth && fontSize > 1) { fontSize--; textWidth = this.measureTextWidth(text, fontSize); } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/round-switch.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/round-switch.component.ts index 03c10e3da5..05a93e434f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/round-switch.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/round-switch.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { PageComponent } from '@shared/components/page.component'; import { WidgetContext } from '@home/models/widget-component.models'; @@ -208,7 +209,7 @@ export class RoundSwitchComponent extends PageComponent implements OnInit, OnDes private setFontSize(element: JQuery, text: string, fontSize: number, maxWidth: number) { let textWidth = this.measureTextWidth(text, fontSize); - while (textWidth > maxWidth) { + while (textWidth > maxWidth && fontSize > 1) { fontSize--; textWidth = this.measureTextWidth(text, fontSize); } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/switch.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/switch.component.ts index e901852f36..095177bffa 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/rpc/switch.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/rpc/switch.component.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { AfterViewInit, Component, ElementRef, Input, OnDestroy, ViewChild } from '@angular/core'; import { PageComponent } from '@shared/components/page.component'; import { WidgetContext } from '@home/models/widget-component.models'; @@ -10,7 +11,6 @@ import { isDefined } from '@core/utils'; import { IWidgetSubscription, SubscriptionInfo, WidgetSubscriptionOptions } from '@core/api/widget-api.models'; import { DatasourceType, widgetType } from '@shared/models/widget.models'; import { EntityType } from '@shared/models/entity-type.models'; -import { MatSlideToggle } from '@angular/material/slide-toggle'; import { ThemePalette } from '@angular/material/core'; const switchAspectRation = 2.7893; @@ -241,7 +241,7 @@ export class SwitchComponent extends PageComponent implements AfterViewInit, OnD private setFontSize(element: JQuery, text: string, fontSize: number, maxWidth: number) { let textWidth = this.measureTextWidth(text, fontSize); - while (textWidth > maxWidth) { + while (textWidth > maxWidth && fontSize > 1) { fontSize--; textWidth = this.measureTextWidth(text, fontSize); }