# Threshold

The **threshold** component compares an input signal to specific threshold values and produces an output based on whether the input signal is above or below the threshold.

The threshold editor enables the user to create and edit thresholds and their conditions.

## Usage

A threshold editor component is typically used in situations where a user needs to set a specific threshold value or range for a particular parameter or setting. This can be useful in a variety of contexts, such as setting comfort-levels, air quality-levels and more.

![Threshold](<../images/threshold.png>)

The component is highly flexible and can be customized to specific project needs in terms of:

- Number of thresholds (*1..n*)
- Unit of threshold values
- Condition levels
- Adding and deleting thresholds
- Layout: Vertical, horizontal

## Design

### Elements

![Threshold elements](<../images/threshold-usage-specification.png>)

1. **Threshold value:** Allows users to input a numeric value. The unit (optional) is configurable to a specific to need and has to be the same for all threshold values. See the [*number input*](<https://element.siemens.io/components/forms-inputs/number-input/>) component to for its interaction states.
2. **Connector:** Visually links the different steps together. It can assume different colors according to the selected condition.
3. **Condition:** Allows users to select a condition. It can have an icon or a composite icon. See the [*select*](<https://element.siemens.io/components/forms-inputs/select/>) component for further details.

### Number of thresholds

The number of thresholds is defined by the use-case but limited by the available space based on viewport and orientation. There should be at least a single threshold and ideally not more than 6.

![Number of thresholds](<../images/threshold-usage-number.png>)

### Layout

The project can choose between a horizontal or vertical layout. The vertical orientation adapts better to small screen sizes and higher number of thresholds.

![Threshold Layout](<../images/threshold-usage-layout.png>)

### Modes

Depending on the use-case, the threshold component can be used in two different modes:

- **Static:** Predefined number of thresholds, where the user can only adapt the threshold values and the conditions.
- **Configurable:** In addition to the static mode, the user can also add and remove thresholds.

![Threshold modes](<../images/threshold-usage-configuration.png>)

> 1. Add, 2. Delete

### Validation

Threshold values have to be in an ascending and logical order. If the threshold values are not entered in a ascending order by the user, then he will get a feedback.

![Threshold validation](<../images/threshold-usage-validation.png>)

## Code

### Usage

```
import { SiThresholdComponent } from '@siemens/element-ng/threshold';

@Component({
  imports: [SiThresholdComponent, ...]
})
```

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { SiFormItemComponent } from '@siemens/element-ng/form';
import { SiNumberInputComponent } from '@siemens/element-ng/number-input';
import { SelectOption } from '@siemens/element-ng/select';
import { SiThresholdComponent, ThresholdStep } from '@siemens/element-ng/threshold';

@Component({
  selector: 'app-sample',
  imports: [FormsModule, SiFormItemComponent, SiNumberInputComponent, SiThresholdComponent],
  templateUrl: './si-threshold.html',
  host: { class: 'p-5' }
})
export class SampleComponent {
  readonly optionsList: SelectOption<string>[] = [
    {
      type: 'option',
      value: 'very-good',
      icon: 'element-circle-filled',
      iconColor: 'status-success',
      stackedIcon: 'element-state-face-very-happy',
      stackedIconColor: 'status-success-contrast',
      label: 'Very good'
    },
    {
      type: 'option',
      value: 'good',
      icon: 'element-circle-filled',
      iconColor: 'status-success',
      stackedIcon: 'element-state-face-happy',
      stackedIconColor: 'status-success-contrast',
      label: 'Good'
    },
    {
      type: 'option',
      value: 'average',
      icon: 'element-circle-filled',
      iconColor: 'status-warning',
      stackedIcon: 'element-state-face-neutral',
      stackedIconColor: 'status-warning-contrast',
      label: 'Average'
    },
    {
      type: 'option',
      value: 'poor',
      icon: 'element-circle-filled',
      iconColor: 'status-danger',
      stackedIcon: 'element-state-face-unhappy',
      stackedIconColor: 'status-danger-contrast',
      label: 'Poor'
    },
    {
      type: 'option',
      value: 'unhealthy',
      icon: 'element-circle-filled',
      iconColor: 'status-critical',
      stackedIcon: 'element-state-face-very-unhappy',
      stackedIconColor: 'status-critical-contrast',
      label: 'Unhealthy'
    }
  ];

  readonly thresholdSteps: ThresholdStep[] = [
    { value: undefined, optionValue: 'unhealthy', aliasLabel: 'No value' },
    { value: 10, optionValue: 'poor', aliasLabel: 'Ten' },
    { value: 15, optionValue: 'average', aliasLabel: 'Fifteen' },
    { value: 20, optionValue: 'good', aliasLabel: 'Twenty' },
    { value: 23, optionValue: 'very-good', aliasLabel: 'Twenty-three' },
    { value: 26, optionValue: 'good', aliasLabel: 'Twenty-six' },
    { value: 28, optionValue: 'average', aliasLabel: 'Twenty-eight' },
    { value: 33, optionValue: 'poor', aliasLabel: 'Thirty-three' },
    { value: 40, optionValue: 'unhealthy', aliasLabel: 'Forty' }
  ];

  canAddRemove = true;
  maxSteps = 15;
  horizontalLayout = false;
  readonly = false;
  readonlyConditions = false;
  minValue = -10;
  maxValue = 50;
  stepSize = 1;
  unit = '°C';
  showDecIncButtons = true;
  validation = true;
  valid = true;
  wrap = false;
  useAliasForStepValues = false;
}
```

Template:

```html
<div class="card">
  <div class="card-body overflow-auto">
    <si-threshold
      [class.flex-wrap]="wrap"
      [options]="optionsList"
      [thresholdSteps]="thresholdSteps"
      [unit]="unit"
      [canAddRemoveSteps]="canAddRemove"
      [horizontalLayout]="horizontalLayout"
      [maxSteps]="maxSteps"
      [readonly]="readonly"
      [readonlyConditions]="readonlyConditions"
      [minValue]="minValue"
      [maxValue]="maxValue"
      [stepSize]="stepSize"
      [showDecIncButtons]="showDecIncButtons"
      [validation]="validation"
      [useAliasForStepValues]="useAliasForStepValues"
      (validChange)="valid = $event"
    />
  </div>
</div>

<div class="card mt-6 e2e-ignore">
  <div class="card-header">Control panel</div>
  <div class="card-body">
    <div class="mb-6"> Validation: {{ valid }} </div>
    <div class="row align-items-end">
      <div class="col-sm-3">
        <si-form-item label="Can add/remove steps">
          <input type="checkbox" class="form-check-input" [(ngModel)]="canAddRemove" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Horizontal layout">
          <input type="checkbox" class="form-check-input" [(ngModel)]="horizontalLayout" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Readonly">
          <input type="checkbox" class="form-check-input" [(ngModel)]="readonly" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Readonly conditions">
          <input type="checkbox" class="form-check-input" [(ngModel)]="readonlyConditions" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="-/+ buttons">
          <input type="checkbox" class="form-check-input" [(ngModel)]="showDecIncButtons" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Validate">
          <input type="checkbox" class="form-check-input" [(ngModel)]="validation" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Can wrap">
          <input type="checkbox" class="form-check-input" [(ngModel)]="wrap" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Use alias for step values">
          <input type="checkbox" class="form-check-input" [(ngModel)]="useAliasForStepValues" />
        </si-form-item>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-3">
        <si-form-item label="Max. steps">
          <si-number-input class="form-control" [min]="0" [(ngModel)]="maxSteps" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Min. value">
          <si-number-input class="form-control" [(ngModel)]="minValue" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Max. value">
          <si-number-input class="form-control" [(ngModel)]="maxValue" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Step size">
          <si-number-input class="form-control" [(ngModel)]="stepSize" />
        </si-form-item>
      </div>
      <div class="col-sm-3">
        <si-form-item label="Unit">
          <input class="form-control" [(ngModel)]="unit" />
        </si-form-item>
      </div>
    </div>
  </div>
</div>
```

### [SiThresholdComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L68-L293>)

**Kind:** component

**Selector:** `si-threshold`

```
import { SiThresholdComponent } from '@siemens/element-ng/threshold';
```

```
component SiThresholdComponent implements OnChanges
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [addAriaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L170-L170>) | `TranslatableString` | `` $localize`:@@SI_THRESHOLD.ADD:Add step` `` | The aria-label for add button |
| [canAddRemoveSteps](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L122-L122>) | `boolean` | `true` | When disabled, steps cannot be added/removed |
| [deleteAriaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L161-L161>) | `TranslatableString` | `` $localize`:@@SI_THRESHOLD.DELETE:Remove step` `` | The aria-label for delete button |
| [horizontalLayout](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L128-L128>) | `boolean` | `false` | Use horizontal layout? |
| [inputAriaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L179-L179>) | `TranslatableString` | `` $localize`:@@SI_THRESHOLD.INPUT_LABEL:Threshold value` `` | The aria-label for input field |
| [maxSteps](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L110-L110>) | `number` | `0` | Max. number of steps, 0 for no hard limit |
| [maxValue](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L98-L98>) | `number` | `100` | The max. value for the threshold value |
| [minValue](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L92-L92>) | `number` | `0` | The min. value for the threshold value |
| [options](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L74-L74>) | `SelectOption<unknown>[]` | `[]` | Options to be shown in select dropdown |
| [readonly](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L140-L140>) | `boolean` | `false` | The obvious |
| [readonlyConditions](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L146-L146>) | `boolean` | `false` | Indicate that the threshold options are readonly and cannot be changed. This will also disable adding / removing steps. |
| [scrollStrategy](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L152-L152>) | `ScrollStrategy` | `defaultConnectedOverlayScrollStrategy()` | CDK scroll strategy used for threshold option select overlays. |
| [showDecIncButtons](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L134-L134>) | `boolean` | `true` | Show dec/inc buttons? |
| [statusAriaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L188-L188>) | `TranslatableString` | `` $localize`:@@SI_THRESHOLD.STATUS:Status` `` | The aria-label for status selection |
| [stepSize](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L104-L104>) | `number` | `1` | The step size for the threshold value |
| [thresholdSteps](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L80-L80>) | `ThresholdStep[]` | `[]` | The thresholds |
| [unit](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L86-L86>) | `string` | `''` | The unit to show |
| [useAliasForStepValues](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L196-L196>) | `boolean` | `false` | When enabled, numeric step inputs are replaced with readonly text fields displaying the `aliasLabel` of each step. Add/remove step buttons are also hidden. |
| [validation](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L116-L116>) | `boolean` | `true` | Do validation? |

#### Output Properties

| Name | Type | Description |
| --- | --- | --- |
| [thresholdStepsChange](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L80-L80>) | `ThresholdStep[]` | The thresholds |
| [validChange](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L199-L199>) | `boolean` | Fired when validation status changes |

#### Attributes and Methods

##### valid

[Source for valid](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L214-L216>)

**Modifiers:** readonly

**Type:** `boolean`

Whether the current input value is valid or not.

### Types Documentation

### [SelectOption](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L21-L51>)

**Kind:** interface

```
import type { SelectOption } from '@siemens/element-ng/select';
```

A select option

```
interface SelectOption<T>
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [disabled](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L32-L32>) (optional) | `boolean` | Whether this option is disabled. |
| [icon](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L34-L34>) (optional) | `string` | An optional icon. |
| [iconColor](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L36-L36>) (optional) | `string` | The color of an icon. |
| [label](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L45-L45>) (optional) | `TranslatableString` | A label to be shown for this option. Is optional if a custom template is provided or if the value should directly be rendered. |
| [stackedIcon](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L38-L38>) (optional) | `string` | An optional stacked icon. |
| [stackedIconColor](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L40-L40>) (optional) | `string` | The color of a stacked icon. |
| [type](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L23-L23>) | `"option"` | Defines this to be an option. |
| [typeaheadLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L50-L50>) (optional) | `TranslatableString` | Used for typeahead functionality when filtering is disabled. If provided, this will be used, otherwise the innerText of the rendered element. |
| [value](<https://github.com/siemens/element/blob/main/projects/element-ng/select/si-select.types.ts#L30-L30>) | `T` | The value if this option. It will be used for formControls and the value property of this `si-select`. The value will internally be checked on equality by using `===`. So an app should either use `string` or ensure that same values are referentially equal. |

### [ThresholdStep](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L35-L44>)

**Kind:** interface

```
import type { ThresholdStep } from '@siemens/element-ng/threshold';
```

One step in a list of thresholds

```
interface ThresholdStep
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [aliasLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L43-L43>) (optional) | `TranslatableString` | Optional alias label for the threshold step, used when `useAliasForStepValues` is `true` |
| [optionValue](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L39-L39>) | `string` | One of the `SelectOption.id` |
| [valid](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L41-L41>) (optional) | `boolean` | When set to `false`, input fields are highlighted as invalid |
| [value](<https://github.com/siemens/element/blob/main/projects/element-ng/threshold/si-threshold.component.ts#L37-L37>) (optional) | `number` | Threshold value, the first step has no value |

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```
