Skip to content

Commit

Permalink
- Feature: output speed unit name can be changed to support different…
Browse files Browse the repository at this point in the history
… languages.

- version to 0.11.0
  • Loading branch information
aukedejong committed Apr 30, 2023
1 parent 58b3529 commit 01ba1b5
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Else, if you prefer the graphical editor, use the menu to add the resource:
| wind_direction_unit | string | degrees | - | Wind direction unit, options: `degrees`, `letters`. Where letters being N, NE upto 32 directions. |
| input_speed_unit | string | mps | - | Windspeed unit of measurement, see Speed unit options bellow. |
| output_speed_unit | string | bft | - | Windspeed unit used on card, see Spped unit options bellow. |
| output_speed_unit_label | string | | - | Overwrite the output speed units name, only for display. |
| speed_range_step | number | depends on output speed unit | - | Sets the speed range step to use. Not possible for output speed unit bft (Beaufort) . |
| speed_range_max | number | depends on output speed unit | - | Sets the speed range max to use. Not possible for output speed unit bft (Beaufort). For example: step 5, max 20 creates ranges: 0-5, 5-10, 10-15, 15-20, 20-infinity |
| speed_ranges | object | depends on output speed unit | - | Define custom speedranges and colours. Not possible for output speed unit bft (Beaufort). |
Expand Down Expand Up @@ -108,7 +109,7 @@ CSS color values are allowed.
| bar_name | string | | --primary-text-color | Entity name color |
| bar_unit_values | string | | --primary-text-color | Unit value color |
| bar_percentages | string | | black | Percentage color |

_
#### Example colors yaml
```yaml
colors:
Expand Down
1 change: 1 addition & 0 deletions src/CardConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface CardConfig {
wind_direction_unit: string;
input_speed_unit: string;
output_speed_unit: string;
output_speed_unit_label: string;
speed_range_step: number;
speed_range_max: number;
speed_ranges: CardConfigSpeedRange[];
Expand Down
9 changes: 9 additions & 0 deletions src/CardConfigWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class CardConfigWrapper {
windRoseDrawNorthOffset: number;
inputSpeedUnit: string;
outputSpeedUnit: string;
outputSpeedUnitLabel: string | undefined;
speedRangeStep: number | undefined;
speedRangeMax: number | undefined;
speedRanges: SpeedRange[] = [];
Expand Down Expand Up @@ -75,6 +76,7 @@ export class CardConfigWrapper {
this.windDirectionUnit = this.checkWindDirectionUnit();
this.inputSpeedUnit = this.checkInputSpeedUnit();
this.outputSpeedUnit = this.checkOutputSpeedUnit();
this.outputSpeedUnitLabel = this.checkOutputSpeedUnitLabel();
this.speedRangeStep = this.checkSpeedRangeStep();
this.speedRangeMax = this.checkSpeedRangeMax();
this.speedRanges = this.checkSpeedRanges();
Expand Down Expand Up @@ -230,6 +232,13 @@ export class CardConfigWrapper {
return GlobalConfig.defaultOutputSpeedUnit;
}

private checkOutputSpeedUnitLabel(): string | undefined {
if (this.cardConfig.output_speed_unit_label) {
return this.cardConfig.output_speed_unit_label
}
return undefined;
}

private checkSpeedRangeStep(): number | undefined {
if (this.cardConfig.speed_range_step && isNaN(this.cardConfig.speed_range_step)) {
throw new Error('WindRoseCard: Invalid speed_range_step, should be a positive number.');
Expand Down
6 changes: 5 additions & 1 deletion src/WindBarCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export class WindBarCanvas {
constructor(config: WindBarConfig, windSpeedConverter: WindSpeedConverter) {
this.config = config;
this.windSpeedConverter = windSpeedConverter;
this.outputUnitName = this.windSpeedConverter.getOutputSpeedUnit().name;
if (config.outputUnitLabel) {
this.outputUnitName = config.outputUnitLabel;
} else {
this.outputUnitName = this.windSpeedConverter.getOutputSpeedUnit().name;
}
this.speedRanges = this.windSpeedConverter.getOutputSpeedUnit().speedRanges;
}

Expand Down
1 change: 1 addition & 0 deletions src/WindBarConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class WindBarConfig {
public full: boolean,
public inputUnit: string,
public outputUnit: string,
public outputUnitLabel: string | undefined,

public barBorderColor: string,
public barUnitNameColor: string,
Expand Down
2 changes: 1 addition & 1 deletion src/WindRoseCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {CardConfig} from "./CardConfig";

/* eslint no-console: 0 */
console.info(
`%c WINROSE-CARD %c Version 0.10.0 `,
`%c WINROSE-CARD %c Version 0.11.0 `,
'color: orange; font-weight: bold; background: black',
'color: white; font-weight: bold; background: dimgray',
);
Expand Down
2 changes: 2 additions & 0 deletions src/WindRoseConfigFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class WindRoseConfigFactory {
this.cardConfig.windspeedBarFull,
this.cardConfig.inputSpeedUnit,
this.cardConfig.outputSpeedUnit,
this.cardConfig.outputSpeedUnitLabel,
this.cardConfig.cardColor.barBorder,
this.cardConfig.cardColor.barUnitName,
this.cardConfig.cardColor.barName,
Expand All @@ -74,6 +75,7 @@ export class WindRoseConfigFactory {
this.cardConfig.windspeedBarFull,
this.cardConfig.inputSpeedUnit,
this.cardConfig.outputSpeedUnit,
this.cardConfig.outputSpeedUnitLabel,
this.cardConfig.cardColor.barBorder,
this.cardConfig.cardColor.barUnitName,
this.cardConfig.cardColor.barName,
Expand Down

0 comments on commit 01ba1b5

Please sign in to comment.