@windy/Metric
Major Windy class for conversion of units, that are used in Windy.com.
Enjoy methods like convertValue
, convertNumber
, listMetrics
, howManyMetrics
Never ever, change users selected metric without their consent.
Type parameters
Name | Type |
---|---|
T | extends string | number = string | number |
Table of contents
Constructors
Properties
Methods
- convertNumber
- convertValue
- cycleMetric
- getDefault
- howManyMetrics
- initProperties
- listMetrics
- na
- onMetricChanged
- renderDiscreteLegend
- renderGradientLegend
- renderLegend
- setDefault
- setMetric
Constructors
constructor
• new Metric<T
>(params
): Metric
<T
>
Colors used to render discrete legend
Type parameters
Name | Type |
---|---|
T | extends string | number = string | number |
Parameters
Name | Type |
---|---|
params | MetricInitParams |
Returns
Metric
<T
>
Properties
cohesion
• Optional
cohesion: Object
Keeps cohesion in between multiple metric instances. For example setting in
in rain will set in
in snow also
Type declaration
conv
• conv: ConvObj
Conversion functions
defaults
• defaults: MetricItem
[]
Default metric for start-up [ metric, imperial, ??? ]
description
• description: LegendDescription
Legend description
discreteLegend
• Optional
discreteLegend: Object
Some metrics have discrete legend. If so, these labels define it, where NumValue is numerical value, to grab color from color table
Type declaration
Name | Type | Description |
---|---|---|
hasEqualItemsWidth? | boolean | Should all items in legend have same width? |
labels | [keyof MainLangFile | keyof PluginTranslations, string ][] | Array of trans strings and clored string. For simplicity of sloution, the legned colors are hardcoded thus they do not react on 'users' defined color. This will be know bug and we will not handle this case. |
ident
• ident: keyof MetricTypes
Identifies metric
key
• key: "metric_ptype"
| "metric_drought"
| "metric_fwi"
| "metric_uvindex"
| "metric_radar"
| "metric_satellite"
| "metric_wind"
| "metric_turbulence"
| "metric_icing"
| "metric_rain"
| "metric_temp"
| "metric_rh"
| "metric_solarpower"
| "metric_clouds"
| "metric_fog"
| "metric_visibility"
| "metric_cape"
| "metric_waves"
| "metric_currents"
| "metric_no2"
| "metric_pm2p5"
| "metric_aod550"
| "metric_gtco3"
| "metric_tcso2"
| "metric_go3"
| "metric_cosc"
| "metric_pressure"
| "metric_efiTemp"
| "metric_efiWind"
| "metric_efiRain"
| "metric_capAlerts"
| "metric_moistureAnom40"
| "metric_moistureAnom100"
| "metric_dfm10h"
| "metric_gh"
| "metric_distance"
| "metric_elevation"
| "metric_snow"
| "metric_altitude"
| "metric_speed"
| "metric_visibilityNoRules"
| "metric_so2"
| "metric_dust"
| "metric_lightDensity"
| "metric_area"
Store key
lines
• lines: LegendLines
Array defining how the legend will look like
metric
• metric: MetricItem
Actually selected metric
nativeSync
• nativeSync: boolean
Sync the metric to native iOS/Android apps
separator
• separator: ""
| " "
number ' ' metric separator
Methods
convertNumber
▸ convertNumber(value
, forcedPrecision?
, metric?
): T
produces converted number value without label
Parameters
Name | Type |
---|---|
value | number |
forcedPrecision? | number |
metric? | MetricItem |
Returns
T
convertValue
▸ convertValue(value
, separator?
, suffix?
): string
get value + label on a basis of user selected metric
Parameters
Name | Type |
---|---|
value | number |
separator? | string |
suffix? | string |
Returns
string
cycleMetric
▸ cycleMetric(uiIdent?
): void
Cycles throu different metrics (for example after clicking on a legend)
Parameters
Name | Type |
---|---|
uiIdent? | string |
Returns
void
getDefault
▸ getDefault(): MetricItem
Returns
howManyMetrics
▸ howManyMetrics(): number
How many metrics we have
Returns
number
initProperties
▸ initProperties(): void
Returns
void
listMetrics
▸ listMetrics(): MetricItem
[]
List all avail metrics
Returns
na
▸ na(): string
Not available
Returns
string
onMetricChanged
▸ onMetricChanged(metric
): void
Parameters
Name | Type |
---|---|
metric | MetricItem |
Returns
void
renderDiscreteLegend
▸ renderDiscreteLegend(): Object
Returns
Object
Name | Type |
---|---|
background | "" |
content | string |
renderGradientLegend
▸ renderGradientLegend(col
, el
, legend
): Object
Renders colorfull legent onto the el
Parameters
Name | Type |
---|---|
col | Color |
el | HTMLDivElement |
legend | Legend |
Returns
Object
Name | Type |
---|---|
background | string |
content | string |
renderLegend
▸ renderLegend(col
, el
, legend
): void
color object is required for classic gradient metrics, discrete ones do not need it as colors are hardcoded for them
Parameters
Name | Type |
---|---|
col | Color |
el | HTMLDivElement |
legend | Legend |
Returns
void
setDefault
▸ setDefault(): void
Returns
void
setMetric
▸ setMetric(metric
, uiIdent?
): void
Stores required metric into storage
Parameters
Name | Type |
---|---|
metric | MetricItem |
uiIdent? | string |
Returns
void