UI: Add unit definitions
This commit is contained in:
parent
d0e56d860c
commit
8c3f56da25
@ -26,6 +26,8 @@ import energy, { EnergyUnits } from '@core/services/unit/definitions/energy';
|
|||||||
import force, { ForceUnits } from '@core/services/unit/definitions/force';
|
import force, { ForceUnits } from '@core/services/unit/definitions/force';
|
||||||
import frequency, { FrequencyUnits } from '@core/services/unit/definitions/frequency';
|
import frequency, { FrequencyUnits } from '@core/services/unit/definitions/frequency';
|
||||||
import illuminance,{ IlluminanceUnits } from '@core/services/unit/definitions/illuminance';
|
import illuminance,{ IlluminanceUnits } from '@core/services/unit/definitions/illuminance';
|
||||||
|
import length, { LengthUnits } from '@core/services/unit/definitions/length';
|
||||||
|
import mass, { MassUnits } from '@core/services/unit/definitions/mass';
|
||||||
import temperature, { TemperatureUnits } from './temperature';
|
import temperature, { TemperatureUnits } from './temperature';
|
||||||
import time, { TimeUnits } from './time';
|
import time, { TimeUnits } from './time';
|
||||||
|
|
||||||
@ -41,6 +43,8 @@ export type AllMeasuresUnits =
|
|||||||
| ForceUnits
|
| ForceUnits
|
||||||
| FrequencyUnits
|
| FrequencyUnits
|
||||||
| IlluminanceUnits
|
| IlluminanceUnits
|
||||||
|
| LengthUnits
|
||||||
|
| MassUnits
|
||||||
| TemperatureUnits
|
| TemperatureUnits
|
||||||
| TimeUnits;
|
| TimeUnits;
|
||||||
|
|
||||||
@ -56,6 +60,8 @@ export type AllMeasures =
|
|||||||
| 'force'
|
| 'force'
|
||||||
| 'frequency'
|
| 'frequency'
|
||||||
| 'illuminance'
|
| 'illuminance'
|
||||||
|
| 'length'
|
||||||
|
| 'mass'
|
||||||
| 'temperature'
|
| 'temperature'
|
||||||
| 'time';
|
| 'time';
|
||||||
|
|
||||||
@ -74,6 +80,8 @@ const allMeasures: Record<
|
|||||||
force,
|
force,
|
||||||
frequency,
|
frequency,
|
||||||
illuminance,
|
illuminance,
|
||||||
|
length,
|
||||||
|
mass,
|
||||||
temperature,
|
temperature,
|
||||||
time,
|
time,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import { TbMeasure, TbMeasureUnits } from '@shared/models/unit.models';
|
|||||||
|
|
||||||
export type AngleUnits = AngleMetricUnits;
|
export type AngleUnits = AngleMetricUnits;
|
||||||
|
|
||||||
export type AngleMetricUnits = 'rad' | 'deg' | 'grad' | 'arcmin' | 'arcsec' | 'mil' | 'rev';
|
export type AngleMetricUnits = 'rad' | 'deg' | 'grad' | 'arcmin' | 'arcsec' | 'mrad' | 'rev';
|
||||||
|
|
||||||
const METRIC: TbMeasureUnits<AngleMetricUnits> = {
|
const METRIC: TbMeasureUnits<AngleMetricUnits> = {
|
||||||
units: {
|
units: {
|
||||||
@ -47,8 +47,8 @@ const METRIC: TbMeasureUnits<AngleMetricUnits> = {
|
|||||||
tags: ['angle', 'arcsecond', 'arcseconds', 'arcsec'],
|
tags: ['angle', 'arcsecond', 'arcseconds', 'arcsec'],
|
||||||
to_anchor: 1 / 3600
|
to_anchor: 1 / 3600
|
||||||
},
|
},
|
||||||
mil: {
|
mrad: {
|
||||||
name: 'unit.mil',
|
name: 'unit.milliradian',
|
||||||
tags: ['angle', 'military angle', 'angular mil', 'mil'],
|
tags: ['angle', 'military angle', 'angular mil', 'mil'],
|
||||||
to_anchor: 9 / (50 * Math.PI),
|
to_anchor: 9 / (50 * Math.PI),
|
||||||
},
|
},
|
||||||
|
|||||||
183
ui-ngx/src/app/core/services/unit/definitions/length.ts
Normal file
183
ui-ngx/src/app/core/services/unit/definitions/length.ts
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
///
|
||||||
|
/// Copyright © 2016-2025 The Thingsboard Authors
|
||||||
|
///
|
||||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
/// you may not use this file except in compliance with the License.
|
||||||
|
/// You may obtain a copy of the License at
|
||||||
|
///
|
||||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
///
|
||||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
/// See the License for the specific language governing permissions and
|
||||||
|
/// limitations under the License.
|
||||||
|
///
|
||||||
|
|
||||||
|
import { TbMeasure, TbMeasureUnits } from '@shared/models/unit.models';
|
||||||
|
|
||||||
|
export type LengthUnits = LengthMetricUnits | LengthImperialUnits;
|
||||||
|
|
||||||
|
export type LengthMetricUnits = 'nm' | 'μm' | 'mm' | 'cm' | 'dm' | 'm' | 'km' | 'angstrom';
|
||||||
|
export type LengthImperialUnits =
|
||||||
|
| 'in'
|
||||||
|
| 'yd'
|
||||||
|
| 'ft-us'
|
||||||
|
| 'ft'
|
||||||
|
| 'fathom'
|
||||||
|
| 'mi'
|
||||||
|
| 'nmi'
|
||||||
|
| 'thou'
|
||||||
|
| 'barleycorn'
|
||||||
|
| 'hand'
|
||||||
|
| 'ch'
|
||||||
|
| 'fur'
|
||||||
|
| 'league'
|
||||||
|
| 'link'
|
||||||
|
| 'rod'
|
||||||
|
| 'cable'
|
||||||
|
| 'AU';
|
||||||
|
|
||||||
|
const METRIC: TbMeasureUnits<LengthMetricUnits> = {
|
||||||
|
ratio: 3.28084,
|
||||||
|
units: {
|
||||||
|
nm: {
|
||||||
|
name: 'unit.nanometer',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'nanoscale', 'atomic scale', 'molecular scale', 'nanometer', 'nanometers', 'nm'],
|
||||||
|
to_anchor: 1e-9,
|
||||||
|
},
|
||||||
|
μm: {
|
||||||
|
name: 'unit.micrometer',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'microns', 'micrometer', 'micrometers', 'µm'],
|
||||||
|
to_anchor: 1e-6,
|
||||||
|
},
|
||||||
|
mm: {
|
||||||
|
name: 'unit.millimeter',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'millimeter', 'millimeters', 'rainfall', 'precipitation', 'displacement', 'position', 'movement', 'transition', 'mm'],
|
||||||
|
to_anchor: 1e-3,
|
||||||
|
},
|
||||||
|
cm: {
|
||||||
|
name: 'unit.centimeter',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'centimeter', 'centimeters', 'rainfall', 'precipitation', 'displacement', 'position', 'movement', 'transition', 'cm'],
|
||||||
|
to_anchor: 1e-2,
|
||||||
|
},
|
||||||
|
dm: {
|
||||||
|
name: 'unit.decimeter',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'decimeter', 'decimeters', 'dm'],
|
||||||
|
to_anchor: 1e-1,
|
||||||
|
},
|
||||||
|
m: {
|
||||||
|
name: 'unit.meter',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'meter', 'meters', 'm'],
|
||||||
|
to_anchor: 1,
|
||||||
|
},
|
||||||
|
km: {
|
||||||
|
name: 'unit.kilometer',
|
||||||
|
tags: ['distance', 'height', 'length', 'width', 'gap', 'depth', 'kilometer', 'kilometers', 'km'],
|
||||||
|
to_anchor: 1e3,
|
||||||
|
},
|
||||||
|
angstrom: {
|
||||||
|
name: 'unit.angstrom',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'atomic scale', 'atomic distance', 'nanoscale', 'angstrom', 'angstroms', 'Å'],
|
||||||
|
to_anchor: 1e-10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const IMPERIAL: TbMeasureUnits<LengthImperialUnits> = {
|
||||||
|
ratio: 1 / 3.28084,
|
||||||
|
units: {
|
||||||
|
in: {
|
||||||
|
name: 'unit.inch',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'inch', 'inches', 'in'],
|
||||||
|
to_anchor: 1 / 12,
|
||||||
|
},
|
||||||
|
yd: {
|
||||||
|
name: 'unit.yard',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'yard', 'yards', 'yd'],
|
||||||
|
to_anchor: 3,
|
||||||
|
},
|
||||||
|
'ft-us': {
|
||||||
|
name: 'unit.foot-us',
|
||||||
|
tags: ['length', 'us survey foot', 'us survey feet', 'ft-us', 'surveying'],
|
||||||
|
to_anchor: 1.000002,
|
||||||
|
},
|
||||||
|
ft: {
|
||||||
|
name: 'unit.foot',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'foot', 'feet', 'ft'],
|
||||||
|
to_anchor: 1,
|
||||||
|
},
|
||||||
|
fathom: {
|
||||||
|
name: 'unit.fathom',
|
||||||
|
tags: ['depth', 'nautical measurement', 'fathom'],
|
||||||
|
to_anchor: 6,
|
||||||
|
},
|
||||||
|
mi: {
|
||||||
|
name: 'unit.mile',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'mile', 'miles', 'mi'],
|
||||||
|
to_anchor: 5280,
|
||||||
|
},
|
||||||
|
nmi: {
|
||||||
|
name: 'unit.nautical-mile',
|
||||||
|
tags: ['level', 'height', 'distance', 'length', 'width', 'gap', 'depth', 'nautical mile', 'nmi'],
|
||||||
|
to_anchor: 6076.12,
|
||||||
|
},
|
||||||
|
thou: {
|
||||||
|
name: 'unit.thou',
|
||||||
|
tags: ['length', 'measurement', 'thou'],
|
||||||
|
to_anchor: 0.001 / 12,
|
||||||
|
},
|
||||||
|
barleycorn: {
|
||||||
|
name: 'unit.barleycorn',
|
||||||
|
tags: ['length', 'shoe size', 'barleycorn'],
|
||||||
|
to_anchor: 1 / 36,
|
||||||
|
},
|
||||||
|
hand: {
|
||||||
|
name: 'unit.hand',
|
||||||
|
tags: ['length', 'horse measurement', 'hand'],
|
||||||
|
to_anchor: 4 / 12,
|
||||||
|
},
|
||||||
|
ch: {
|
||||||
|
name: 'unit.chain',
|
||||||
|
tags: ['length', 'land surveying', 'ch'],
|
||||||
|
to_anchor: 66,
|
||||||
|
},
|
||||||
|
fur: {
|
||||||
|
name: 'unit.furlong',
|
||||||
|
tags: ['length', 'land surveying', 'fur'],
|
||||||
|
to_anchor: 660,
|
||||||
|
},
|
||||||
|
league: {
|
||||||
|
name: 'unit.league',
|
||||||
|
tags: ['length', 'historical measurement', 'league'],
|
||||||
|
to_anchor: 3 * 5280,
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
name: 'unit.link',
|
||||||
|
tags: ['length', 'land surveying', 'link'],
|
||||||
|
to_anchor: 0.66,
|
||||||
|
},
|
||||||
|
rod: {
|
||||||
|
name: 'unit.rod',
|
||||||
|
tags: ['length', 'land surveying', 'rod'],
|
||||||
|
to_anchor: 16.5,
|
||||||
|
},
|
||||||
|
cable: {
|
||||||
|
name: 'unit.cable',
|
||||||
|
tags: ['distance', 'nautical measurement', 'cable'],
|
||||||
|
to_anchor: 600,
|
||||||
|
},
|
||||||
|
AU: {
|
||||||
|
name: 'unit.astronomical-unit',
|
||||||
|
tags: ['distance', 'celestial bodies', 'solar system', 'AU'],
|
||||||
|
to_anchor: 149597870700 * 3.28084,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const measure: TbMeasure<LengthUnits> = {
|
||||||
|
METRIC,
|
||||||
|
IMPERIAL
|
||||||
|
};
|
||||||
|
|
||||||
|
export default measure;
|
||||||
121
ui-ngx/src/app/core/services/unit/definitions/mass.ts
Normal file
121
ui-ngx/src/app/core/services/unit/definitions/mass.ts
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
///
|
||||||
|
/// Copyright © 2016-2025 The Thingsboard Authors
|
||||||
|
///
|
||||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
/// you may not use this file except in compliance with the License.
|
||||||
|
/// You may obtain a copy of the License at
|
||||||
|
///
|
||||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
///
|
||||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
/// See the License for the specific language governing permissions and
|
||||||
|
/// limitations under the License.
|
||||||
|
///
|
||||||
|
|
||||||
|
import { TbMeasure, TbMeasureUnits } from '@shared/models/unit.models';
|
||||||
|
|
||||||
|
export type MassUnits = MassMetricUnits | MassImperialUnits;
|
||||||
|
|
||||||
|
export type MassMetricUnits = 'ng' | 'mcg' | 'mg' | 'g' | 'kg' | 't' | 'Da';
|
||||||
|
export type MassImperialUnits = 'oz' | 'lb' | 'st' | 'short tons' | 'gr' | 'dr' | 'qr' | 'cwt' | 'slug';
|
||||||
|
|
||||||
|
const METRIC: TbMeasureUnits<MassMetricUnits> = {
|
||||||
|
ratio: 1 / 453.59237,
|
||||||
|
units: {
|
||||||
|
ng: {
|
||||||
|
name: 'unit.nanogram',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'nanogram', 'nanograms', 'ng'],
|
||||||
|
to_anchor: 1e-9,
|
||||||
|
},
|
||||||
|
mcg: {
|
||||||
|
name: 'unit.microgram',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'μg', 'microgram'],
|
||||||
|
to_anchor: 1e-6,
|
||||||
|
},
|
||||||
|
mg: {
|
||||||
|
name: 'unit.milligram',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'milligram', 'miligrams', 'mg'],
|
||||||
|
to_anchor: 1e-3,
|
||||||
|
},
|
||||||
|
g: {
|
||||||
|
name: 'unit.gram',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'gram', 'grams', 'g'],
|
||||||
|
to_anchor: 1,
|
||||||
|
},
|
||||||
|
kg: {
|
||||||
|
name: 'unit.kilogram',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'kilogram', 'kilograms', 'kg'],
|
||||||
|
to_anchor: 1000, // 1 kg = 1000 g
|
||||||
|
},
|
||||||
|
t: {
|
||||||
|
name: 'unit.tonne',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'tonne', 'tons', 't'],
|
||||||
|
to_anchor: 1000000,
|
||||||
|
},
|
||||||
|
Da: {
|
||||||
|
name: 'unit.dalton',
|
||||||
|
tags: ['atomic mass unit', 'AMU', 'unified atomic mass unit', 'dalton', 'Da'],
|
||||||
|
to_anchor: 1.66053906660e-24,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const IMPERIAL: TbMeasureUnits<MassImperialUnits> = {
|
||||||
|
ratio: 453.59237,
|
||||||
|
units: {
|
||||||
|
oz: {
|
||||||
|
name: 'unit.ounce',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'ounce', 'ounces', 'oz'],
|
||||||
|
to_anchor: 1 / 16,
|
||||||
|
},
|
||||||
|
lb: {
|
||||||
|
name: 'unit.pound',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'pound', 'pounds', 'lb'],
|
||||||
|
to_anchor: 1,
|
||||||
|
},
|
||||||
|
st: {
|
||||||
|
name: 'unit.stone',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'stone', 'stones', 'st'],
|
||||||
|
to_anchor: 14,
|
||||||
|
},
|
||||||
|
'short tons': {
|
||||||
|
name: 'unit.short-tons',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'short ton', 'short tons'],
|
||||||
|
to_anchor: 2000,
|
||||||
|
},
|
||||||
|
gr: {
|
||||||
|
name: 'unit.grain',
|
||||||
|
tags: ['mass', 'measurement', 'grain', 'gr'],
|
||||||
|
to_anchor: 1 / 7000,
|
||||||
|
},
|
||||||
|
dr: {
|
||||||
|
name: 'unit.drachm',
|
||||||
|
tags: ['mass', 'measurement', 'drachm', 'dr'],
|
||||||
|
to_anchor: 1 / 256,
|
||||||
|
},
|
||||||
|
qr: {
|
||||||
|
name: 'unit.quarter',
|
||||||
|
tags: ['mass', 'measurement', 'quarter', 'qr'],
|
||||||
|
to_anchor: 28,
|
||||||
|
},
|
||||||
|
cwt: {
|
||||||
|
name: 'unit.hundredweight-countt',
|
||||||
|
tags: ['mass', 'weight', 'heaviness', 'load', 'hundredweight count', 'cwt'],
|
||||||
|
to_anchor: 100,
|
||||||
|
},
|
||||||
|
slug: {
|
||||||
|
name: 'unit.slug',
|
||||||
|
tags: ['mass', 'measurement', 'slug'],
|
||||||
|
to_anchor: 32.174,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const measure: TbMeasure<MassUnits> = {
|
||||||
|
METRIC,
|
||||||
|
IMPERIAL
|
||||||
|
};
|
||||||
|
|
||||||
|
export default measure;
|
||||||
@ -5876,11 +5876,14 @@
|
|||||||
"force": "Force",
|
"force": "Force",
|
||||||
"frequency": "Frequency",
|
"frequency": "Frequency",
|
||||||
"illuminance": "Illuminance",
|
"illuminance": "Illuminance",
|
||||||
|
"length": "Length",
|
||||||
|
"mass": "Mass",
|
||||||
"temperature": "Temperature",
|
"temperature": "Temperature",
|
||||||
"time": "Time"
|
"time": "Time"
|
||||||
},
|
},
|
||||||
"millimeter": "Millimeter",
|
"millimeter": "Millimeter",
|
||||||
"centimeter": "Centimeter",
|
"centimeter": "Centimeter",
|
||||||
|
"decimeter": "Decimeter",
|
||||||
"angstrom": "Angstrom",
|
"angstrom": "Angstrom",
|
||||||
"nanometer": "Nanometer",
|
"nanometer": "Nanometer",
|
||||||
"micrometer": "Micrometer",
|
"micrometer": "Micrometer",
|
||||||
@ -5888,6 +5891,7 @@
|
|||||||
"kilometer": "Kilometer",
|
"kilometer": "Kilometer",
|
||||||
"inch": "Inch",
|
"inch": "Inch",
|
||||||
"foot": "Foot",
|
"foot": "Foot",
|
||||||
|
"foot-us": "Foot (US survey)",
|
||||||
"yard": "Yard",
|
"yard": "Yard",
|
||||||
"mile": "Mile",
|
"mile": "Mile",
|
||||||
"nautical-mile": "Nautical Mile",
|
"nautical-mile": "Nautical Mile",
|
||||||
@ -6229,7 +6233,7 @@
|
|||||||
"gradian": "Gradian",
|
"gradian": "Gradian",
|
||||||
"arcminute": "Arcminute",
|
"arcminute": "Arcminute",
|
||||||
"arcsecond": "Arcsecond",
|
"arcsecond": "Arcsecond",
|
||||||
"mil": "Mil",
|
"milliradian": "Milliradian",
|
||||||
"revolution": "Revolution",
|
"revolution": "Revolution",
|
||||||
"siemens": "Siemens",
|
"siemens": "Siemens",
|
||||||
"millisiemens": "Millisiemens",
|
"millisiemens": "Millisiemens",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user