Merge pull request #13132 from maxunbearable/task/6001-math-show-help

Added show help on math funcs in Calculated field simple expression
This commit is contained in:
Igor Kulikov 2025-04-09 12:48:53 +03:00 committed by GitHub
commit bd72b8bb5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 68 additions and 0 deletions

View File

@ -79,6 +79,12 @@
</div> </div>
<mat-form-field class="mt-3" appearance="outline" subscriptSizing="dynamic" [class.hidden]="fieldFormGroup.get('type').value !== CalculatedFieldType.SIMPLE"> <mat-form-field class="mt-3" appearance="outline" subscriptSizing="dynamic" [class.hidden]="fieldFormGroup.get('type').value !== CalculatedFieldType.SIMPLE">
<input matInput formControlName="expressionSIMPLE" maxlength="255" [placeholder]="'(temperature - 32) / 1.8'" required> <input matInput formControlName="expressionSIMPLE" maxlength="255" [placeholder]="'(temperature - 32) / 1.8'" required>
<div matSuffix
class="pr-2"
[tb-help-popup]="'math/math-methods_fn'"
tb-help-popup-placement="left"
[tb-help-popup-style]="{maxWidth: '970px'}">
</div>
@if (configFormGroup.get('expressionSIMPLE').errors && configFormGroup.get('expressionSIMPLE').touched) { @if (configFormGroup.get('expressionSIMPLE').errors && configFormGroup.get('expressionSIMPLE').touched) {
<mat-error> <mat-error>
@if (configFormGroup.get('expressionSIMPLE').hasError('required')) { @if (configFormGroup.get('expressionSIMPLE').hasError('required')) {

View File

@ -32,6 +32,12 @@
<legend class="group-title">{{'rule-node-config.custom-expression-field-input' | translate }} *</legend> <legend class="group-title">{{'rule-node-config.custom-expression-field-input' | translate }} *</legend>
<mat-form-field class="mat-block no-margin-top flex-1" subscriptSizing="dynamic"> <mat-form-field class="mat-block no-margin-top flex-1" subscriptSizing="dynamic">
<input matInput formControlName="customFunction" required/> <input matInput formControlName="customFunction" required/>
<div matSuffix
class="pr-2"
[tb-help-popup]="'math/math-methods_fn'"
tb-help-popup-placement="left"
[tb-help-popup-style]="{maxWidth: '970px'}">
</div>
<mat-error *ngIf="mathFunctionConfigForm.get('customFunction').hasError('required')" translate> <mat-error *ngIf="mathFunctionConfigForm.get('customFunction').hasError('required')" translate>
rule-node-config.custom-expression-field-input-required rule-node-config.custom-expression-field-input-required
</mat-error> </mat-error>

View File

@ -0,0 +1,56 @@
## Built-in operators
The following operators can be used in expressions:
| Operator | Description | Example |
|----------|-------------------------------|-----------------|
| `+` | Addition or unary plus | `2 + 3` or `+3` |
| `-` | Subtraction or unary minus | `5 - 2` or `-3` |
| `*` | Multiplication | `4 * 2` |
| `/` | Division | `10 / 2` |
| `^` | Exponentiation | `2 ^ 3` |
| `%` | Modulo | `10 % 3` |
## Implicit multiplication
Expressions supports implicit multiplication, allowing you to omit the multiplication operator in certain cases. For example, the expression `2cos(yx)` is interpreted as `2*cos(y*x)`. Similarly, `3x` is interpreted as `3*x`, and `xy` as `x*y`. This feature makes writing expressions more concise and natural.
## Built-in constants
Available constants for calculations:
| Constant | Description | Value |
|-------------|-----------------------------|-------------------|
| `π` or `pi` | The mathematical constant π | 3.141592653589793 |
| `e` | Euler's number | 2.718281828459045 |
| `φ` | The golden ratio | 1.618033988749895 |
## Built-in mathematical functions
The following built-in mathematical functions can be used to perform various calculations:
| Function | Description | Example |
|---------------|---------------------------------------------------------------------|-------------------|
| `abs(x)` | Absolute value of `x`. | `abs(-7) = 7` |
| `acos(x)` | Arc cosine of `x`, result in radians. Requires `-1 ≤ x ≤ 1`. | `acos(1) = 0` |
| `asin(x)` | Arc sine of `x`, result in radians. Requires `-1 ≤ x ≤ 1`. | `asin(0) = 0` |
| `atan(x)` | Arc tangent of `x`, result in radians. | `atan(0) = 0` |
| `cbrt(x)` | Cube root of `x`. | `cbrt(8) = 2` |
| `ceil(x)` | Rounds `x` up to the nearest integer. | `ceil(3.1) = 4` |
| `cos(x)` | Cosine of `x`, where `x` is in radians. | `cos(0) = 1` |
| `cosh(x)` | Hyperbolic cosine of `x`. | `cosh(0) = 1` |
| `cot(x)` | Cotangent of `x` (1 / tan(`x`)), where `x` is in radians. | `cot(0.7854) ≈ 1` |
| `exp(x)` | Computes `e^x`. | `exp(0) = 1` |
| `expm1(x)` | Computes `e^x - 1` accurately for small `x`. | `expm1(0) = 0` |
| `floor(x)` | Rounds `x` down to the nearest integer. | `floor(3.9) = 3` |
| `ln(x)` | Natural logarithm (base *e*) of `x`. Requires `x > 0`. | `ln(1) = 0` |
| `log(x)` | Natural logarithm (base *e*) of `x`. Requires `x > 0`. | `log(1) = 0` |
| `lg(x)` | Natural logarithm (base 10) of `x`. Requires `x > 0`. | `lg(10) = 1` |
| `log10(x)` | Logarithm base 10 of `x`. Requires `x > 0`. | `log10(100) = 2` |
| `log2(x)` | Logarithm base 2 of `x`. Requires `x > 0`. | `log2(8) = 3` |
| `logab(a, b)` | Logarithm of `b` with base `a`. Requires `a > 0`, `b > 0`, `a ≠ 1`. | `logab(2, 8) = 3` |
| `log1p(x)` | Computes `ln(1 + x)` accurately for small `x`. Requires `x > -1`. | `log1p(0) = 0` |
| `pow(x, y)` | Raises `x` to the power of `y` (`x^y`). | `pow(2, 3) = 8` |
| `signum(x)` | Returns the sign of `x`: -1 if `x < 0`, 0 if `x = 0`, 1 if `x > 0`. | `signum(-5) = -1` |
| `sin(x)` | Sine of `x`, where `x` is in radians. | `sin(0) = 0` |
| `sinh(x)` | Hyperbolic sine of `x`. | `sinh(0) = 0` |
| `sqrt(x)` | Square root of `x`. Requires `x ≥ 0`. | `sqrt(4) = 2` |
| `tan(x)` | Tangent of `x`, where `x` is in radians. | `tan(0) = 0` |
| `tanh(x)` | Hyperbolic tangent of `x`. | `tanh(0) = 0` |