kbn.ts 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. import _ from 'lodash';
  2. import moment from 'moment';
  3. const kbn: any = {};
  4. kbn.valueFormats = {};
  5. kbn.regexEscape = value => {
  6. return value.replace(/[\\^$*+?.()|[\]{}\/]/g, '\\$&');
  7. };
  8. ///// HELPER FUNCTIONS /////
  9. kbn.round_interval = interval => {
  10. switch (true) {
  11. // 0.015s
  12. case interval < 15:
  13. return 10; // 0.01s
  14. // 0.035s
  15. case interval < 35:
  16. return 20; // 0.02s
  17. // 0.075s
  18. case interval < 75:
  19. return 50; // 0.05s
  20. // 0.15s
  21. case interval < 150:
  22. return 100; // 0.1s
  23. // 0.35s
  24. case interval < 350:
  25. return 200; // 0.2s
  26. // 0.75s
  27. case interval < 750:
  28. return 500; // 0.5s
  29. // 1.5s
  30. case interval < 1500:
  31. return 1000; // 1s
  32. // 3.5s
  33. case interval < 3500:
  34. return 2000; // 2s
  35. // 7.5s
  36. case interval < 7500:
  37. return 5000; // 5s
  38. // 12.5s
  39. case interval < 12500:
  40. return 10000; // 10s
  41. // 17.5s
  42. case interval < 17500:
  43. return 15000; // 15s
  44. // 25s
  45. case interval < 25000:
  46. return 20000; // 20s
  47. // 45s
  48. case interval < 45000:
  49. return 30000; // 30s
  50. // 1.5m
  51. case interval < 90000:
  52. return 60000; // 1m
  53. // 3.5m
  54. case interval < 210000:
  55. return 120000; // 2m
  56. // 7.5m
  57. case interval < 450000:
  58. return 300000; // 5m
  59. // 12.5m
  60. case interval < 750000:
  61. return 600000; // 10m
  62. // 12.5m
  63. case interval < 1050000:
  64. return 900000; // 15m
  65. // 25m
  66. case interval < 1500000:
  67. return 1200000; // 20m
  68. // 45m
  69. case interval < 2700000:
  70. return 1800000; // 30m
  71. // 1.5h
  72. case interval < 5400000:
  73. return 3600000; // 1h
  74. // 2.5h
  75. case interval < 9000000:
  76. return 7200000; // 2h
  77. // 4.5h
  78. case interval < 16200000:
  79. return 10800000; // 3h
  80. // 9h
  81. case interval < 32400000:
  82. return 21600000; // 6h
  83. // 1d
  84. case interval < 86400000:
  85. return 43200000; // 12h
  86. // 1w
  87. case interval < 604800000:
  88. return 86400000; // 1d
  89. // 3w
  90. case interval < 1814400000:
  91. return 604800000; // 1w
  92. // 6w
  93. case interval < 3628800000:
  94. return 2592000000; // 30d
  95. default:
  96. return 31536000000; // 1y
  97. }
  98. };
  99. kbn.secondsToHms = seconds => {
  100. const numyears = Math.floor(seconds / 31536000);
  101. if (numyears) {
  102. return numyears + 'y';
  103. }
  104. const numdays = Math.floor((seconds % 31536000) / 86400);
  105. if (numdays) {
  106. return numdays + 'd';
  107. }
  108. const numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
  109. if (numhours) {
  110. return numhours + 'h';
  111. }
  112. const numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
  113. if (numminutes) {
  114. return numminutes + 'm';
  115. }
  116. const numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60);
  117. if (numseconds) {
  118. return numseconds + 's';
  119. }
  120. const nummilliseconds = Math.floor(seconds * 1000.0);
  121. if (nummilliseconds) {
  122. return nummilliseconds + 'ms';
  123. }
  124. return 'less than a millisecond'; //'just now' //or other string you like;
  125. };
  126. kbn.secondsToHhmmss = seconds => {
  127. const strings = [];
  128. const numhours = Math.floor(seconds / 3600);
  129. const numminutes = Math.floor((seconds % 3600) / 60);
  130. const numseconds = Math.floor((seconds % 3600) % 60);
  131. numhours > 9 ? strings.push('' + numhours) : strings.push('0' + numhours);
  132. numminutes > 9 ? strings.push('' + numminutes) : strings.push('0' + numminutes);
  133. numseconds > 9 ? strings.push('' + numseconds) : strings.push('0' + numseconds);
  134. return strings.join(':');
  135. };
  136. kbn.to_percent = (nr, outof) => {
  137. return Math.floor(nr / outof * 10000) / 100 + '%';
  138. };
  139. kbn.addslashes = str => {
  140. str = str.replace(/\\/g, '\\\\');
  141. str = str.replace(/\'/g, "\\'");
  142. str = str.replace(/\"/g, '\\"');
  143. str = str.replace(/\0/g, '\\0');
  144. return str;
  145. };
  146. kbn.interval_regex = /(\d+(?:\.\d+)?)(ms|[Mwdhmsy])/;
  147. // histogram & trends
  148. kbn.intervals_in_seconds = {
  149. y: 31536000,
  150. M: 2592000,
  151. w: 604800,
  152. d: 86400,
  153. h: 3600,
  154. m: 60,
  155. s: 1,
  156. ms: 0.001,
  157. };
  158. kbn.calculateInterval = (range, resolution, lowLimitInterval) => {
  159. let lowLimitMs = 1; // 1 millisecond default low limit
  160. let intervalMs;
  161. if (lowLimitInterval) {
  162. if (lowLimitInterval[0] === '>') {
  163. lowLimitInterval = lowLimitInterval.slice(1);
  164. }
  165. lowLimitMs = kbn.interval_to_ms(lowLimitInterval);
  166. }
  167. intervalMs = kbn.round_interval((range.to.valueOf() - range.from.valueOf()) / resolution);
  168. if (lowLimitMs > intervalMs) {
  169. intervalMs = lowLimitMs;
  170. }
  171. return {
  172. intervalMs: intervalMs,
  173. interval: kbn.secondsToHms(intervalMs / 1000),
  174. };
  175. };
  176. kbn.describe_interval = str => {
  177. const matches = str.match(kbn.interval_regex);
  178. if (!matches || !_.has(kbn.intervals_in_seconds, matches[2])) {
  179. throw new Error('Invalid interval string, expecting a number followed by one of "Mwdhmsy"');
  180. } else {
  181. return {
  182. sec: kbn.intervals_in_seconds[matches[2]],
  183. type: matches[2],
  184. count: parseInt(matches[1], 10),
  185. };
  186. }
  187. };
  188. kbn.interval_to_ms = str => {
  189. const info = kbn.describe_interval(str);
  190. return info.sec * 1000 * info.count;
  191. };
  192. kbn.interval_to_seconds = str => {
  193. const info = kbn.describe_interval(str);
  194. return info.sec * info.count;
  195. };
  196. kbn.query_color_dot = (color, diameter) => {
  197. return (
  198. '<div class="icon-circle" style="' +
  199. ['display:inline-block', 'color:' + color, 'font-size:' + diameter + 'px'].join(';') +
  200. '"></div>'
  201. );
  202. };
  203. kbn.slugifyForUrl = str => {
  204. return str
  205. .toLowerCase()
  206. .replace(/[^\w ]+/g, '')
  207. .replace(/ +/g, '-');
  208. };
  209. kbn.stringToJsRegex = str => {
  210. if (str[0] !== '/') {
  211. return new RegExp('^' + str + '$');
  212. }
  213. const match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
  214. return new RegExp(match[1], match[2]);
  215. };
  216. kbn.toFixed = (value, decimals) => {
  217. if (value === null) {
  218. return '';
  219. }
  220. const factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
  221. const formatted = String(Math.round(value * factor) / factor);
  222. // if exponent return directly
  223. if (formatted.indexOf('e') !== -1 || value === 0) {
  224. return formatted;
  225. }
  226. // If tickDecimals was specified, ensure that we have exactly that
  227. // much precision; otherwise default to the value's own precision.
  228. if (decimals != null) {
  229. const decimalPos = formatted.indexOf('.');
  230. const precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1;
  231. if (precision < decimals) {
  232. return (precision ? formatted : formatted + '.') + String(factor).substr(1, decimals - precision);
  233. }
  234. }
  235. return formatted;
  236. };
  237. kbn.toFixedScaled = (value, decimals, scaledDecimals, additionalDecimals, ext) => {
  238. if (scaledDecimals === null) {
  239. return kbn.toFixed(value, decimals) + ext;
  240. } else {
  241. return kbn.toFixed(value, scaledDecimals + additionalDecimals) + ext;
  242. }
  243. };
  244. kbn.roundValue = (num, decimals) => {
  245. if (num === null) {
  246. return null;
  247. }
  248. const n = Math.pow(10, decimals);
  249. const formatted = (n * num).toFixed(decimals);
  250. return Math.round(parseFloat(formatted)) / n;
  251. };
  252. ///// FORMAT FUNCTION CONSTRUCTORS /////
  253. kbn.formatBuilders = {};
  254. // Formatter which always appends a fixed unit string to the value. No
  255. // scaling of the value is performed.
  256. kbn.formatBuilders.fixedUnit = unit => {
  257. return (size, decimals) => {
  258. if (size === null) {
  259. return '';
  260. }
  261. return kbn.toFixed(size, decimals) + ' ' + unit;
  262. };
  263. };
  264. // Formatter which scales the unit string geometrically according to the given
  265. // numeric factor. Repeatedly scales the value down by the factor until it is
  266. // less than the factor in magnitude, or the end of the array is reached.
  267. kbn.formatBuilders.scaledUnits = (factor, extArray) => {
  268. return (size, decimals, scaledDecimals) => {
  269. if (size === null) {
  270. return '';
  271. }
  272. let steps = 0;
  273. const limit = extArray.length;
  274. while (Math.abs(size) >= factor) {
  275. steps++;
  276. size /= factor;
  277. if (steps >= limit) {
  278. return 'NA';
  279. }
  280. }
  281. if (steps > 0 && scaledDecimals !== null) {
  282. decimals = scaledDecimals + 3 * steps;
  283. }
  284. return kbn.toFixed(size, decimals) + extArray[steps];
  285. };
  286. };
  287. // Extension of the scaledUnits builder which uses SI decimal prefixes. If an
  288. // offset is given, it adjusts the starting units at the given prefix; a value
  289. // of 0 starts at no scale; -3 drops to nano, +2 starts at mega, etc.
  290. kbn.formatBuilders.decimalSIPrefix = (unit, offset) => {
  291. let prefixes = ['n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
  292. prefixes = prefixes.slice(3 + (offset || 0));
  293. const units = prefixes.map(p => {
  294. return ' ' + p + unit;
  295. });
  296. return kbn.formatBuilders.scaledUnits(1000, units);
  297. };
  298. // Extension of the scaledUnits builder which uses SI binary prefixes. If
  299. // offset is given, it starts the units at the given prefix; otherwise, the
  300. // offset defaults to zero and the initial unit is not prefixed.
  301. kbn.formatBuilders.binarySIPrefix = (unit, offset) => {
  302. const prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'].slice(offset);
  303. const units = prefixes.map(p => {
  304. return ' ' + p + unit;
  305. });
  306. return kbn.formatBuilders.scaledUnits(1024, units);
  307. };
  308. // Currency formatter for prefixing a symbol onto a number. Supports scaling
  309. // up to the trillions.
  310. kbn.formatBuilders.currency = symbol => {
  311. const units = ['', 'K', 'M', 'B', 'T'];
  312. const scaler = kbn.formatBuilders.scaledUnits(1000, units);
  313. return (size, decimals, scaledDecimals) => {
  314. if (size === null) {
  315. return '';
  316. }
  317. const scaled = scaler(size, decimals, scaledDecimals);
  318. return symbol + scaled;
  319. };
  320. };
  321. kbn.formatBuilders.simpleCountUnit = symbol => {
  322. const units = ['', 'K', 'M', 'B', 'T'];
  323. const scaler = kbn.formatBuilders.scaledUnits(1000, units);
  324. return (size, decimals, scaledDecimals) => {
  325. if (size === null) {
  326. return '';
  327. }
  328. const scaled = scaler(size, decimals, scaledDecimals);
  329. return scaled + ' ' + symbol;
  330. };
  331. };
  332. ///// VALUE FORMATS /////
  333. // Dimensionless Units
  334. kbn.valueFormats.none = kbn.toFixed;
  335. kbn.valueFormats.short = kbn.formatBuilders.scaledUnits(1000, [
  336. '',
  337. ' K',
  338. ' Mil',
  339. ' Bil',
  340. ' Tri',
  341. ' Quadr',
  342. ' Quint',
  343. ' Sext',
  344. ' Sept',
  345. ]);
  346. kbn.valueFormats.dB = kbn.formatBuilders.fixedUnit('dB');
  347. kbn.valueFormats.percent = (size, decimals) => {
  348. if (size === null) {
  349. return '';
  350. }
  351. return kbn.toFixed(size, decimals) + '%';
  352. };
  353. kbn.valueFormats.percentunit = (size, decimals) => {
  354. if (size === null) {
  355. return '';
  356. }
  357. return kbn.toFixed(100 * size, decimals) + '%';
  358. };
  359. /* Formats the value to hex. Uses float if specified decimals are not 0.
  360. * There are two submenu
  361. * , one with 0x, and one without */
  362. kbn.valueFormats.hex = (value, decimals) => {
  363. if (value == null) {
  364. return '';
  365. }
  366. return parseFloat(kbn.toFixed(value, decimals))
  367. .toString(16)
  368. .toUpperCase();
  369. };
  370. kbn.valueFormats.hex0x = (value, decimals) => {
  371. if (value == null) {
  372. return '';
  373. }
  374. const hexString = kbn.valueFormats.hex(value, decimals);
  375. if (hexString.substring(0, 1) === '-') {
  376. return '-0x' + hexString.substring(1);
  377. }
  378. return '0x' + hexString;
  379. };
  380. kbn.valueFormats.sci = (value, decimals) => {
  381. return value.toExponential(decimals);
  382. };
  383. kbn.valueFormats.locale = (value, decimals) => {
  384. return value.toLocaleString(undefined, { maximumFractionDigits: decimals });
  385. };
  386. // Currencies
  387. kbn.valueFormats.currencyUSD = kbn.formatBuilders.currency('$');
  388. kbn.valueFormats.currencyGBP = kbn.formatBuilders.currency('£');
  389. kbn.valueFormats.currencyEUR = kbn.formatBuilders.currency('€');
  390. kbn.valueFormats.currencyJPY = kbn.formatBuilders.currency('¥');
  391. kbn.valueFormats.currencyRUB = kbn.formatBuilders.currency('₽');
  392. kbn.valueFormats.currencyUAH = kbn.formatBuilders.currency('₴');
  393. kbn.valueFormats.currencyBRL = kbn.formatBuilders.currency('R$');
  394. kbn.valueFormats.currencyDKK = kbn.formatBuilders.currency('kr');
  395. kbn.valueFormats.currencyISK = kbn.formatBuilders.currency('kr');
  396. kbn.valueFormats.currencyNOK = kbn.formatBuilders.currency('kr');
  397. kbn.valueFormats.currencySEK = kbn.formatBuilders.currency('kr');
  398. kbn.valueFormats.currencyCZK = kbn.formatBuilders.currency('czk');
  399. kbn.valueFormats.currencyCHF = kbn.formatBuilders.currency('CHF');
  400. kbn.valueFormats.currencyPLN = kbn.formatBuilders.currency('zł');
  401. kbn.valueFormats.currencyBTC = kbn.formatBuilders.currency('฿');
  402. // Data (Binary)
  403. kbn.valueFormats.bits = kbn.formatBuilders.binarySIPrefix('b');
  404. kbn.valueFormats.bytes = kbn.formatBuilders.binarySIPrefix('B');
  405. kbn.valueFormats.kbytes = kbn.formatBuilders.binarySIPrefix('B', 1);
  406. kbn.valueFormats.mbytes = kbn.formatBuilders.binarySIPrefix('B', 2);
  407. kbn.valueFormats.gbytes = kbn.formatBuilders.binarySIPrefix('B', 3);
  408. // Data (Decimal)
  409. kbn.valueFormats.decbits = kbn.formatBuilders.decimalSIPrefix('b');
  410. kbn.valueFormats.decbytes = kbn.formatBuilders.decimalSIPrefix('B');
  411. kbn.valueFormats.deckbytes = kbn.formatBuilders.decimalSIPrefix('B', 1);
  412. kbn.valueFormats.decmbytes = kbn.formatBuilders.decimalSIPrefix('B', 2);
  413. kbn.valueFormats.decgbytes = kbn.formatBuilders.decimalSIPrefix('B', 3);
  414. // Data Rate
  415. kbn.valueFormats.pps = kbn.formatBuilders.decimalSIPrefix('pps');
  416. kbn.valueFormats.bps = kbn.formatBuilders.decimalSIPrefix('bps');
  417. kbn.valueFormats.Bps = kbn.formatBuilders.decimalSIPrefix('B/s');
  418. kbn.valueFormats.KBs = kbn.formatBuilders.decimalSIPrefix('Bs', 1);
  419. kbn.valueFormats.Kbits = kbn.formatBuilders.decimalSIPrefix('bps', 1);
  420. kbn.valueFormats.MBs = kbn.formatBuilders.decimalSIPrefix('Bs', 2);
  421. kbn.valueFormats.Mbits = kbn.formatBuilders.decimalSIPrefix('bps', 2);
  422. kbn.valueFormats.GBs = kbn.formatBuilders.decimalSIPrefix('Bs', 3);
  423. kbn.valueFormats.Gbits = kbn.formatBuilders.decimalSIPrefix('bps', 3);
  424. // Hash Rate
  425. kbn.valueFormats.Hs = kbn.formatBuilders.decimalSIPrefix('H/s');
  426. kbn.valueFormats.KHs = kbn.formatBuilders.decimalSIPrefix('H/s', 1);
  427. kbn.valueFormats.MHs = kbn.formatBuilders.decimalSIPrefix('H/s', 2);
  428. kbn.valueFormats.GHs = kbn.formatBuilders.decimalSIPrefix('H/s', 3);
  429. kbn.valueFormats.THs = kbn.formatBuilders.decimalSIPrefix('H/s', 4);
  430. kbn.valueFormats.PHs = kbn.formatBuilders.decimalSIPrefix('H/s', 5);
  431. kbn.valueFormats.EHs = kbn.formatBuilders.decimalSIPrefix('H/s', 6);
  432. // Throughput
  433. kbn.valueFormats.ops = kbn.formatBuilders.simpleCountUnit('ops');
  434. kbn.valueFormats.reqps = kbn.formatBuilders.simpleCountUnit('reqps');
  435. kbn.valueFormats.rps = kbn.formatBuilders.simpleCountUnit('rps');
  436. kbn.valueFormats.wps = kbn.formatBuilders.simpleCountUnit('wps');
  437. kbn.valueFormats.iops = kbn.formatBuilders.simpleCountUnit('iops');
  438. kbn.valueFormats.opm = kbn.formatBuilders.simpleCountUnit('opm');
  439. kbn.valueFormats.rpm = kbn.formatBuilders.simpleCountUnit('rpm');
  440. kbn.valueFormats.wpm = kbn.formatBuilders.simpleCountUnit('wpm');
  441. // Energy
  442. kbn.valueFormats.watt = kbn.formatBuilders.decimalSIPrefix('W');
  443. kbn.valueFormats.kwatt = kbn.formatBuilders.decimalSIPrefix('W', 1);
  444. kbn.valueFormats.mwatt = kbn.formatBuilders.decimalSIPrefix('W', -1);
  445. kbn.valueFormats.kwattm = kbn.formatBuilders.decimalSIPrefix('W/Min', 1);
  446. kbn.valueFormats.Wm2 = kbn.formatBuilders.fixedUnit('W/m²');
  447. kbn.valueFormats.voltamp = kbn.formatBuilders.decimalSIPrefix('VA');
  448. kbn.valueFormats.kvoltamp = kbn.formatBuilders.decimalSIPrefix('VA', 1);
  449. kbn.valueFormats.voltampreact = kbn.formatBuilders.decimalSIPrefix('var');
  450. kbn.valueFormats.kvoltampreact = kbn.formatBuilders.decimalSIPrefix('var', 1);
  451. kbn.valueFormats.watth = kbn.formatBuilders.decimalSIPrefix('Wh');
  452. kbn.valueFormats.kwatth = kbn.formatBuilders.decimalSIPrefix('Wh', 1);
  453. kbn.valueFormats.joule = kbn.formatBuilders.decimalSIPrefix('J');
  454. kbn.valueFormats.ev = kbn.formatBuilders.decimalSIPrefix('eV');
  455. kbn.valueFormats.amp = kbn.formatBuilders.decimalSIPrefix('A');
  456. kbn.valueFormats.kamp = kbn.formatBuilders.decimalSIPrefix('A', 1);
  457. kbn.valueFormats.mamp = kbn.formatBuilders.decimalSIPrefix('A', -1);
  458. kbn.valueFormats.volt = kbn.formatBuilders.decimalSIPrefix('V');
  459. kbn.valueFormats.kvolt = kbn.formatBuilders.decimalSIPrefix('V', 1);
  460. kbn.valueFormats.mvolt = kbn.formatBuilders.decimalSIPrefix('V', -1);
  461. kbn.valueFormats.dBm = kbn.formatBuilders.decimalSIPrefix('dBm');
  462. kbn.valueFormats.ohm = kbn.formatBuilders.decimalSIPrefix('Ω');
  463. kbn.valueFormats.lumens = kbn.formatBuilders.decimalSIPrefix('Lm');
  464. // Temperature
  465. kbn.valueFormats.celsius = kbn.formatBuilders.fixedUnit('°C');
  466. kbn.valueFormats.farenheit = kbn.formatBuilders.fixedUnit('°F');
  467. kbn.valueFormats.kelvin = kbn.formatBuilders.fixedUnit('K');
  468. kbn.valueFormats.humidity = kbn.formatBuilders.fixedUnit('%H');
  469. // Pressure
  470. kbn.valueFormats.pressurebar = kbn.formatBuilders.decimalSIPrefix('bar');
  471. kbn.valueFormats.pressurembar = kbn.formatBuilders.decimalSIPrefix('bar', -1);
  472. kbn.valueFormats.pressurekbar = kbn.formatBuilders.decimalSIPrefix('bar', 1);
  473. kbn.valueFormats.pressurehpa = kbn.formatBuilders.fixedUnit('hPa');
  474. kbn.valueFormats.pressurekpa = kbn.formatBuilders.fixedUnit('kPa');
  475. kbn.valueFormats.pressurehg = kbn.formatBuilders.fixedUnit('"Hg');
  476. kbn.valueFormats.pressurepsi = kbn.formatBuilders.scaledUnits(1000, [' psi', ' ksi', ' Mpsi']);
  477. // Force
  478. kbn.valueFormats.forceNm = kbn.formatBuilders.decimalSIPrefix('Nm');
  479. kbn.valueFormats.forcekNm = kbn.formatBuilders.decimalSIPrefix('Nm', 1);
  480. kbn.valueFormats.forceN = kbn.formatBuilders.decimalSIPrefix('N');
  481. kbn.valueFormats.forcekN = kbn.formatBuilders.decimalSIPrefix('N', 1);
  482. // Length
  483. kbn.valueFormats.lengthm = kbn.formatBuilders.decimalSIPrefix('m');
  484. kbn.valueFormats.lengthmm = kbn.formatBuilders.decimalSIPrefix('m', -1);
  485. kbn.valueFormats.lengthkm = kbn.formatBuilders.decimalSIPrefix('m', 1);
  486. kbn.valueFormats.lengthmi = kbn.formatBuilders.fixedUnit('mi');
  487. kbn.valueFormats.lengthft = kbn.formatBuilders.fixedUnit('ft');
  488. // Area
  489. kbn.valueFormats.areaM2 = kbn.formatBuilders.fixedUnit('m²');
  490. kbn.valueFormats.areaF2 = kbn.formatBuilders.fixedUnit('ft²');
  491. kbn.valueFormats.areaMI2 = kbn.formatBuilders.fixedUnit('mi²');
  492. // Mass
  493. kbn.valueFormats.massmg = kbn.formatBuilders.decimalSIPrefix('g', -1);
  494. kbn.valueFormats.massg = kbn.formatBuilders.decimalSIPrefix('g');
  495. kbn.valueFormats.masskg = kbn.formatBuilders.decimalSIPrefix('g', 1);
  496. kbn.valueFormats.masst = kbn.formatBuilders.fixedUnit('t');
  497. // Velocity
  498. kbn.valueFormats.velocityms = kbn.formatBuilders.fixedUnit('m/s');
  499. kbn.valueFormats.velocitykmh = kbn.formatBuilders.fixedUnit('km/h');
  500. kbn.valueFormats.velocitymph = kbn.formatBuilders.fixedUnit('mph');
  501. kbn.valueFormats.velocityknot = kbn.formatBuilders.fixedUnit('kn');
  502. // Acceleration
  503. kbn.valueFormats.accMS2 = kbn.formatBuilders.fixedUnit('m/sec²');
  504. kbn.valueFormats.accFS2 = kbn.formatBuilders.fixedUnit('f/sec²');
  505. kbn.valueFormats.accG = kbn.formatBuilders.fixedUnit('g');
  506. // Volume
  507. kbn.valueFormats.litre = kbn.formatBuilders.decimalSIPrefix('L');
  508. kbn.valueFormats.mlitre = kbn.formatBuilders.decimalSIPrefix('L', -1);
  509. kbn.valueFormats.m3 = kbn.formatBuilders.fixedUnit('m³');
  510. kbn.valueFormats.Nm3 = kbn.formatBuilders.fixedUnit('Nm³');
  511. kbn.valueFormats.dm3 = kbn.formatBuilders.fixedUnit('dm³');
  512. kbn.valueFormats.gallons = kbn.formatBuilders.fixedUnit('gal');
  513. // Flow
  514. kbn.valueFormats.flowgpm = kbn.formatBuilders.fixedUnit('gpm');
  515. kbn.valueFormats.flowcms = kbn.formatBuilders.fixedUnit('cms');
  516. kbn.valueFormats.flowcfs = kbn.formatBuilders.fixedUnit('cfs');
  517. kbn.valueFormats.flowcfm = kbn.formatBuilders.fixedUnit('cfm');
  518. kbn.valueFormats.litreh = kbn.formatBuilders.fixedUnit('l/h');
  519. kbn.valueFormats.flowlpm = kbn.formatBuilders.decimalSIPrefix('L');
  520. kbn.valueFormats.flowmlpm = kbn.formatBuilders.decimalSIPrefix('L', -1);
  521. // Angle
  522. kbn.valueFormats.degree = kbn.formatBuilders.fixedUnit('°');
  523. kbn.valueFormats.radian = kbn.formatBuilders.fixedUnit('rad');
  524. kbn.valueFormats.grad = kbn.formatBuilders.fixedUnit('grad');
  525. // Radiation
  526. kbn.valueFormats.radbq = kbn.formatBuilders.decimalSIPrefix('Bq');
  527. kbn.valueFormats.radci = kbn.formatBuilders.decimalSIPrefix('Ci');
  528. kbn.valueFormats.radgy = kbn.formatBuilders.decimalSIPrefix('Gy');
  529. kbn.valueFormats.radrad = kbn.formatBuilders.decimalSIPrefix('rad');
  530. kbn.valueFormats.radsv = kbn.formatBuilders.decimalSIPrefix('Sv');
  531. kbn.valueFormats.radrem = kbn.formatBuilders.decimalSIPrefix('rem');
  532. kbn.valueFormats.radexpckg = kbn.formatBuilders.decimalSIPrefix('C/kg');
  533. kbn.valueFormats.radr = kbn.formatBuilders.decimalSIPrefix('R');
  534. kbn.valueFormats.radsvh = kbn.formatBuilders.decimalSIPrefix('Sv/h');
  535. // Concentration
  536. kbn.valueFormats.ppm = kbn.formatBuilders.fixedUnit('ppm');
  537. kbn.valueFormats.conppb = kbn.formatBuilders.fixedUnit('ppb');
  538. kbn.valueFormats.conngm3 = kbn.formatBuilders.fixedUnit('ng/m³');
  539. kbn.valueFormats.conngNm3 = kbn.formatBuilders.fixedUnit('ng/Nm³');
  540. kbn.valueFormats.conμgm3 = kbn.formatBuilders.fixedUnit('μg/m³');
  541. kbn.valueFormats.conμgNm3 = kbn.formatBuilders.fixedUnit('μg/Nm³');
  542. kbn.valueFormats.conmgm3 = kbn.formatBuilders.fixedUnit('mg/m³');
  543. kbn.valueFormats.conmgNm3 = kbn.formatBuilders.fixedUnit('mg/Nm³');
  544. kbn.valueFormats.congm3 = kbn.formatBuilders.fixedUnit('g/m³');
  545. kbn.valueFormats.congNm3 = kbn.formatBuilders.fixedUnit('g/Nm³');
  546. // Time
  547. kbn.valueFormats.hertz = kbn.formatBuilders.decimalSIPrefix('Hz');
  548. kbn.valueFormats.ms = (size, decimals, scaledDecimals) => {
  549. if (size === null) {
  550. return '';
  551. }
  552. if (Math.abs(size) < 1000) {
  553. return kbn.toFixed(size, decimals) + ' ms';
  554. } else if (Math.abs(size) < 60000) {
  555. // Less than 1 min
  556. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, ' s');
  557. } else if (Math.abs(size) < 3600000) {
  558. // Less than 1 hour, divide in minutes
  559. return kbn.toFixedScaled(size / 60000, decimals, scaledDecimals, 5, ' min');
  560. } else if (Math.abs(size) < 86400000) {
  561. // Less than one day, divide in hours
  562. return kbn.toFixedScaled(size / 3600000, decimals, scaledDecimals, 7, ' hour');
  563. } else if (Math.abs(size) < 31536000000) {
  564. // Less than one year, divide in days
  565. return kbn.toFixedScaled(size / 86400000, decimals, scaledDecimals, 8, ' day');
  566. }
  567. return kbn.toFixedScaled(size / 31536000000, decimals, scaledDecimals, 10, ' year');
  568. };
  569. kbn.valueFormats.s = (size, decimals, scaledDecimals) => {
  570. if (size === null) {
  571. return '';
  572. }
  573. // Less than 1 µs, divide in ns
  574. if (Math.abs(size) < 0.000001) {
  575. return kbn.toFixedScaled(size * 1e9, decimals, scaledDecimals - decimals, -9, ' ns');
  576. }
  577. // Less than 1 ms, divide in µs
  578. if (Math.abs(size) < 0.001) {
  579. return kbn.toFixedScaled(size * 1e6, decimals, scaledDecimals - decimals, -6, ' µs');
  580. }
  581. // Less than 1 second, divide in ms
  582. if (Math.abs(size) < 1) {
  583. return kbn.toFixedScaled(size * 1e3, decimals, scaledDecimals - decimals, -3, ' ms');
  584. }
  585. if (Math.abs(size) < 60) {
  586. return kbn.toFixed(size, decimals) + ' s';
  587. } else if (Math.abs(size) < 3600) {
  588. // Less than 1 hour, divide in minutes
  589. return kbn.toFixedScaled(size / 60, decimals, scaledDecimals, 1, ' min');
  590. } else if (Math.abs(size) < 86400) {
  591. // Less than one day, divide in hours
  592. return kbn.toFixedScaled(size / 3600, decimals, scaledDecimals, 4, ' hour');
  593. } else if (Math.abs(size) < 604800) {
  594. // Less than one week, divide in days
  595. return kbn.toFixedScaled(size / 86400, decimals, scaledDecimals, 5, ' day');
  596. } else if (Math.abs(size) < 31536000) {
  597. // Less than one year, divide in week
  598. return kbn.toFixedScaled(size / 604800, decimals, scaledDecimals, 6, ' week');
  599. }
  600. return kbn.toFixedScaled(size / 3.15569e7, decimals, scaledDecimals, 7, ' year');
  601. };
  602. kbn.valueFormats['µs'] = (size, decimals, scaledDecimals) => {
  603. if (size === null) {
  604. return '';
  605. }
  606. if (Math.abs(size) < 1000) {
  607. return kbn.toFixed(size, decimals) + ' µs';
  608. } else if (Math.abs(size) < 1000000) {
  609. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, ' ms');
  610. } else {
  611. return kbn.toFixedScaled(size / 1000000, decimals, scaledDecimals, 6, ' s');
  612. }
  613. };
  614. kbn.valueFormats.ns = (size, decimals, scaledDecimals) => {
  615. if (size === null) {
  616. return '';
  617. }
  618. if (Math.abs(size) < 1000) {
  619. return kbn.toFixed(size, decimals) + ' ns';
  620. } else if (Math.abs(size) < 1000000) {
  621. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, ' µs');
  622. } else if (Math.abs(size) < 1000000000) {
  623. return kbn.toFixedScaled(size / 1000000, decimals, scaledDecimals, 6, ' ms');
  624. } else if (Math.abs(size) < 60000000000) {
  625. return kbn.toFixedScaled(size / 1000000000, decimals, scaledDecimals, 9, ' s');
  626. } else {
  627. return kbn.toFixedScaled(size / 60000000000, decimals, scaledDecimals, 12, ' min');
  628. }
  629. };
  630. kbn.valueFormats.m = (size, decimals, scaledDecimals) => {
  631. if (size === null) {
  632. return '';
  633. }
  634. if (Math.abs(size) < 60) {
  635. return kbn.toFixed(size, decimals) + ' min';
  636. } else if (Math.abs(size) < 1440) {
  637. return kbn.toFixedScaled(size / 60, decimals, scaledDecimals, 2, ' hour');
  638. } else if (Math.abs(size) < 10080) {
  639. return kbn.toFixedScaled(size / 1440, decimals, scaledDecimals, 3, ' day');
  640. } else if (Math.abs(size) < 604800) {
  641. return kbn.toFixedScaled(size / 10080, decimals, scaledDecimals, 4, ' week');
  642. } else {
  643. return kbn.toFixedScaled(size / 5.25948e5, decimals, scaledDecimals, 5, ' year');
  644. }
  645. };
  646. kbn.valueFormats.h = (size, decimals, scaledDecimals) => {
  647. if (size === null) {
  648. return '';
  649. }
  650. if (Math.abs(size) < 24) {
  651. return kbn.toFixed(size, decimals) + ' hour';
  652. } else if (Math.abs(size) < 168) {
  653. return kbn.toFixedScaled(size / 24, decimals, scaledDecimals, 2, ' day');
  654. } else if (Math.abs(size) < 8760) {
  655. return kbn.toFixedScaled(size / 168, decimals, scaledDecimals, 3, ' week');
  656. } else {
  657. return kbn.toFixedScaled(size / 8760, decimals, scaledDecimals, 4, ' year');
  658. }
  659. };
  660. kbn.valueFormats.d = (size, decimals, scaledDecimals) => {
  661. if (size === null) {
  662. return '';
  663. }
  664. if (Math.abs(size) < 7) {
  665. return kbn.toFixed(size, decimals) + ' day';
  666. } else if (Math.abs(size) < 365) {
  667. return kbn.toFixedScaled(size / 7, decimals, scaledDecimals, 2, ' week');
  668. } else {
  669. return kbn.toFixedScaled(size / 365, decimals, scaledDecimals, 3, ' year');
  670. }
  671. };
  672. kbn.toDuration = (size, decimals, timeScale) => {
  673. if (size === null) {
  674. return '';
  675. }
  676. if (size === 0) {
  677. return '0 ' + timeScale + 's';
  678. }
  679. if (size < 0) {
  680. return kbn.toDuration(-size, decimals, timeScale) + ' ago';
  681. }
  682. const units = [
  683. { short: 'y', long: 'year' },
  684. { short: 'M', long: 'month' },
  685. { short: 'w', long: 'week' },
  686. { short: 'd', long: 'day' },
  687. { short: 'h', long: 'hour' },
  688. { short: 'm', long: 'minute' },
  689. { short: 's', long: 'second' },
  690. { short: 'ms', long: 'millisecond' },
  691. ];
  692. // convert $size to milliseconds
  693. // intervals_in_seconds uses seconds (duh), convert them to milliseconds here to minimize floating point errors
  694. size *=
  695. kbn.intervals_in_seconds[
  696. units.find(e => {
  697. return e.long === timeScale;
  698. }).short
  699. ] * 1000;
  700. const strings = [];
  701. // after first value >= 1 print only $decimals more
  702. let decrementDecimals = false;
  703. for (let i = 0; i < units.length && decimals >= 0; i++) {
  704. const interval = kbn.intervals_in_seconds[units[i].short] * 1000;
  705. const value = size / interval;
  706. if (value >= 1 || decrementDecimals) {
  707. decrementDecimals = true;
  708. const floor = Math.floor(value);
  709. const unit = units[i].long + (floor !== 1 ? 's' : '');
  710. strings.push(floor + ' ' + unit);
  711. size = size % interval;
  712. decimals--;
  713. }
  714. }
  715. return strings.join(', ');
  716. };
  717. kbn.toClock = (size, decimals) => {
  718. if (size === null) {
  719. return '';
  720. }
  721. // < 1 second
  722. if (size < 1000) {
  723. return moment.utc(size).format('SSS\\m\\s');
  724. }
  725. // < 1 minute
  726. if (size < 60000) {
  727. let format = 'ss\\s:SSS\\m\\s';
  728. if (decimals === 0) {
  729. format = 'ss\\s';
  730. }
  731. return moment.utc(size).format(format);
  732. }
  733. // < 1 hour
  734. if (size < 3600000) {
  735. let format = 'mm\\m:ss\\s:SSS\\m\\s';
  736. if (decimals === 0) {
  737. format = 'mm\\m';
  738. } else if (decimals === 1) {
  739. format = 'mm\\m:ss\\s';
  740. }
  741. return moment.utc(size).format(format);
  742. }
  743. let format = 'mm\\m:ss\\s:SSS\\m\\s';
  744. const hours = `${('0' + Math.floor(moment.duration(size, 'milliseconds').asHours())).slice(-2)}h`;
  745. if (decimals === 0) {
  746. format = '';
  747. } else if (decimals === 1) {
  748. format = 'mm\\m';
  749. } else if (decimals === 2) {
  750. format = 'mm\\m:ss\\s';
  751. }
  752. return format ? `${hours}:${moment.utc(size).format(format)}` : hours;
  753. };
  754. kbn.valueFormats.dtdurationms = (size, decimals) => {
  755. return kbn.toDuration(size, decimals, 'millisecond');
  756. };
  757. kbn.valueFormats.dtdurations = (size, decimals) => {
  758. return kbn.toDuration(size, decimals, 'second');
  759. };
  760. kbn.valueFormats.dthms = (size, decimals) => {
  761. return kbn.secondsToHhmmss(size);
  762. };
  763. kbn.valueFormats.timeticks = (size, decimals, scaledDecimals) => {
  764. return kbn.valueFormats.s(size / 100, decimals, scaledDecimals);
  765. };
  766. kbn.valueFormats.clockms = (size, decimals) => {
  767. return kbn.toClock(size, decimals);
  768. };
  769. kbn.valueFormats.clocks = (size, decimals) => {
  770. return kbn.toClock(size * 1000, decimals);
  771. };
  772. kbn.valueFormats.dateTimeAsIso = (epoch, isUtc) => {
  773. const time = isUtc ? moment.utc(epoch) : moment(epoch);
  774. if (moment().isSame(epoch, 'day')) {
  775. return time.format('HH:mm:ss');
  776. }
  777. return time.format('YYYY-MM-DD HH:mm:ss');
  778. };
  779. kbn.valueFormats.dateTimeAsUS = (epoch, isUtc) => {
  780. const time = isUtc ? moment.utc(epoch) : moment(epoch);
  781. if (moment().isSame(epoch, 'day')) {
  782. return time.format('h:mm:ss a');
  783. }
  784. return time.format('MM/DD/YYYY h:mm:ss a');
  785. };
  786. kbn.valueFormats.dateTimeFromNow = (epoch, isUtc) => {
  787. const time = isUtc ? moment.utc(epoch) : moment(epoch);
  788. return time.fromNow();
  789. };
  790. ///// FORMAT MENU /////
  791. kbn.getUnitFormats = () => {
  792. return [
  793. {
  794. text: 'none',
  795. submenu: [
  796. { text: 'none', value: 'none' },
  797. { text: 'short', value: 'short' },
  798. { text: 'percent (0-100)', value: 'percent' },
  799. { text: 'percent (0.0-1.0)', value: 'percentunit' },
  800. { text: 'Humidity (%H)', value: 'humidity' },
  801. { text: 'decibel', value: 'dB' },
  802. { text: 'hexadecimal (0x)', value: 'hex0x' },
  803. { text: 'hexadecimal', value: 'hex' },
  804. { text: 'scientific notation', value: 'sci' },
  805. { text: 'locale format', value: 'locale' },
  806. ],
  807. },
  808. {
  809. text: 'currency',
  810. submenu: [
  811. { text: 'Dollars ($)', value: 'currencyUSD' },
  812. { text: 'Pounds (£)', value: 'currencyGBP' },
  813. { text: 'Euro (€)', value: 'currencyEUR' },
  814. { text: 'Yen (¥)', value: 'currencyJPY' },
  815. { text: 'Rubles (₽)', value: 'currencyRUB' },
  816. { text: 'Hryvnias (₴)', value: 'currencyUAH' },
  817. { text: 'Real (R$)', value: 'currencyBRL' },
  818. { text: 'Danish Krone (kr)', value: 'currencyDKK' },
  819. { text: 'Icelandic Króna (kr)', value: 'currencyISK' },
  820. { text: 'Norwegian Krone (kr)', value: 'currencyNOK' },
  821. { text: 'Swedish Krona (kr)', value: 'currencySEK' },
  822. { text: 'Czech koruna (czk)', value: 'currencyCZK' },
  823. { text: 'Swiss franc (CHF)', value: 'currencyCHF' },
  824. { text: 'Polish Złoty (PLN)', value: 'currencyPLN' },
  825. { text: 'Bitcoin (฿)', value: 'currencyBTC' },
  826. ],
  827. },
  828. {
  829. text: 'time',
  830. submenu: [
  831. { text: 'Hertz (1/s)', value: 'hertz' },
  832. { text: 'nanoseconds (ns)', value: 'ns' },
  833. { text: 'microseconds (µs)', value: 'µs' },
  834. { text: 'milliseconds (ms)', value: 'ms' },
  835. { text: 'seconds (s)', value: 's' },
  836. { text: 'minutes (m)', value: 'm' },
  837. { text: 'hours (h)', value: 'h' },
  838. { text: 'days (d)', value: 'd' },
  839. { text: 'duration (ms)', value: 'dtdurationms' },
  840. { text: 'duration (s)', value: 'dtdurations' },
  841. { text: 'duration (hh:mm:ss)', value: 'dthms' },
  842. { text: 'Timeticks (s/100)', value: 'timeticks' },
  843. { text: 'clock (ms)', value: 'clockms' },
  844. { text: 'clock (s)', value: 'clocks' },
  845. ],
  846. },
  847. {
  848. text: 'date & time',
  849. submenu: [
  850. { text: 'YYYY-MM-DD HH:mm:ss', value: 'dateTimeAsIso' },
  851. { text: 'DD/MM/YYYY h:mm:ss a', value: 'dateTimeAsUS' },
  852. { text: 'From Now', value: 'dateTimeFromNow' },
  853. ],
  854. },
  855. {
  856. text: 'data (IEC)',
  857. submenu: [
  858. { text: 'bits', value: 'bits' },
  859. { text: 'bytes', value: 'bytes' },
  860. { text: 'kibibytes', value: 'kbytes' },
  861. { text: 'mebibytes', value: 'mbytes' },
  862. { text: 'gibibytes', value: 'gbytes' },
  863. ],
  864. },
  865. {
  866. text: 'data (Metric)',
  867. submenu: [
  868. { text: 'bits', value: 'decbits' },
  869. { text: 'bytes', value: 'decbytes' },
  870. { text: 'kilobytes', value: 'deckbytes' },
  871. { text: 'megabytes', value: 'decmbytes' },
  872. { text: 'gigabytes', value: 'decgbytes' },
  873. ],
  874. },
  875. {
  876. text: 'data rate',
  877. submenu: [
  878. { text: 'packets/sec', value: 'pps' },
  879. { text: 'bits/sec', value: 'bps' },
  880. { text: 'bytes/sec', value: 'Bps' },
  881. { text: 'kilobits/sec', value: 'Kbits' },
  882. { text: 'kilobytes/sec', value: 'KBs' },
  883. { text: 'megabits/sec', value: 'Mbits' },
  884. { text: 'megabytes/sec', value: 'MBs' },
  885. { text: 'gigabytes/sec', value: 'GBs' },
  886. { text: 'gigabits/sec', value: 'Gbits' },
  887. ],
  888. },
  889. {
  890. text: 'hash rate',
  891. submenu: [
  892. { text: 'hashes/sec', value: 'Hs' },
  893. { text: 'kilohashes/sec', value: 'KHs' },
  894. { text: 'megahashes/sec', value: 'MHs' },
  895. { text: 'gigahashes/sec', value: 'GHs' },
  896. { text: 'terahashes/sec', value: 'THs' },
  897. { text: 'petahashes/sec', value: 'PHs' },
  898. { text: 'exahashes/sec', value: 'EHs' },
  899. ],
  900. },
  901. {
  902. text: 'throughput',
  903. submenu: [
  904. { text: 'ops/sec (ops)', value: 'ops' },
  905. { text: 'requests/sec (rps)', value: 'reqps' },
  906. { text: 'reads/sec (rps)', value: 'rps' },
  907. { text: 'writes/sec (wps)', value: 'wps' },
  908. { text: 'I/O ops/sec (iops)', value: 'iops' },
  909. { text: 'ops/min (opm)', value: 'opm' },
  910. { text: 'reads/min (rpm)', value: 'rpm' },
  911. { text: 'writes/min (wpm)', value: 'wpm' },
  912. ],
  913. },
  914. {
  915. text: 'length',
  916. submenu: [
  917. { text: 'millimetre (mm)', value: 'lengthmm' },
  918. { text: 'meter (m)', value: 'lengthm' },
  919. { text: 'feet (ft)', value: 'lengthft' },
  920. { text: 'kilometer (km)', value: 'lengthkm' },
  921. { text: 'mile (mi)', value: 'lengthmi' },
  922. ],
  923. },
  924. {
  925. text: 'area',
  926. submenu: [
  927. { text: 'Square Meters (m²)', value: 'areaM2' },
  928. { text: 'Square Feet (ft²)', value: 'areaF2' },
  929. { text: 'Square Miles (mi²)', value: 'areaMI2' },
  930. ],
  931. },
  932. {
  933. text: 'mass',
  934. submenu: [
  935. { text: 'milligram (mg)', value: 'massmg' },
  936. { text: 'gram (g)', value: 'massg' },
  937. { text: 'kilogram (kg)', value: 'masskg' },
  938. { text: 'metric ton (t)', value: 'masst' },
  939. ],
  940. },
  941. {
  942. text: 'velocity',
  943. submenu: [
  944. { text: 'metres/second (m/s)', value: 'velocityms' },
  945. { text: 'kilometers/hour (km/h)', value: 'velocitykmh' },
  946. { text: 'miles/hour (mph)', value: 'velocitymph' },
  947. { text: 'knot (kn)', value: 'velocityknot' },
  948. ],
  949. },
  950. {
  951. text: 'volume',
  952. submenu: [
  953. { text: 'millilitre (mL)', value: 'mlitre' },
  954. { text: 'litre (L)', value: 'litre' },
  955. { text: 'cubic metre', value: 'm3' },
  956. { text: 'Normal cubic metre', value: 'Nm3' },
  957. { text: 'cubic decimetre', value: 'dm3' },
  958. { text: 'gallons', value: 'gallons' },
  959. ],
  960. },
  961. {
  962. text: 'energy',
  963. submenu: [
  964. { text: 'Watt (W)', value: 'watt' },
  965. { text: 'Kilowatt (kW)', value: 'kwatt' },
  966. { text: 'Milliwatt (mW)', value: 'mwatt' },
  967. { text: 'Watt per square metre (W/m²)', value: 'Wm2' },
  968. { text: 'Volt-ampere (VA)', value: 'voltamp' },
  969. { text: 'Kilovolt-ampere (kVA)', value: 'kvoltamp' },
  970. { text: 'Volt-ampere reactive (var)', value: 'voltampreact' },
  971. { text: 'Kilovolt-ampere reactive (kvar)', value: 'kvoltampreact' },
  972. { text: 'Watt-hour (Wh)', value: 'watth' },
  973. { text: 'Kilowatt-hour (kWh)', value: 'kwatth' },
  974. { text: 'Kilowatt-min (kWm)', value: 'kwattm' },
  975. { text: 'Joule (J)', value: 'joule' },
  976. { text: 'Electron volt (eV)', value: 'ev' },
  977. { text: 'Ampere (A)', value: 'amp' },
  978. { text: 'Kiloampere (kA)', value: 'kamp' },
  979. { text: 'Milliampere (mA)', value: 'mamp' },
  980. { text: 'Volt (V)', value: 'volt' },
  981. { text: 'Kilovolt (kV)', value: 'kvolt' },
  982. { text: 'Millivolt (mV)', value: 'mvolt' },
  983. { text: 'Decibel-milliwatt (dBm)', value: 'dBm' },
  984. { text: 'Ohm (Ω)', value: 'ohm' },
  985. { text: 'Lumens (Lm)', value: 'lumens' },
  986. ],
  987. },
  988. {
  989. text: 'temperature',
  990. submenu: [
  991. { text: 'Celsius (°C)', value: 'celsius' },
  992. { text: 'Farenheit (°F)', value: 'farenheit' },
  993. { text: 'Kelvin (K)', value: 'kelvin' },
  994. ],
  995. },
  996. {
  997. text: 'pressure',
  998. submenu: [
  999. { text: 'Millibars', value: 'pressurembar' },
  1000. { text: 'Bars', value: 'pressurebar' },
  1001. { text: 'Kilobars', value: 'pressurekbar' },
  1002. { text: 'Hectopascals', value: 'pressurehpa' },
  1003. { text: 'Kilopascals', value: 'pressurekpa' },
  1004. { text: 'Inches of mercury', value: 'pressurehg' },
  1005. { text: 'PSI', value: 'pressurepsi' },
  1006. ],
  1007. },
  1008. {
  1009. text: 'force',
  1010. submenu: [
  1011. { text: 'Newton-meters (Nm)', value: 'forceNm' },
  1012. { text: 'Kilonewton-meters (kNm)', value: 'forcekNm' },
  1013. { text: 'Newtons (N)', value: 'forceN' },
  1014. { text: 'Kilonewtons (kN)', value: 'forcekN' },
  1015. ],
  1016. },
  1017. {
  1018. text: 'flow',
  1019. submenu: [
  1020. { text: 'Gallons/min (gpm)', value: 'flowgpm' },
  1021. { text: 'Cubic meters/sec (cms)', value: 'flowcms' },
  1022. { text: 'Cubic feet/sec (cfs)', value: 'flowcfs' },
  1023. { text: 'Cubic feet/min (cfm)', value: 'flowcfm' },
  1024. { text: 'Litre/hour', value: 'litreh' },
  1025. { text: 'Litre/min (l/min)', value: 'flowlpm' },
  1026. { text: 'milliLitre/min (mL/min)', value: 'flowmlpm' },
  1027. ],
  1028. },
  1029. {
  1030. text: 'angle',
  1031. submenu: [
  1032. { text: 'Degrees (°)', value: 'degree' },
  1033. { text: 'Radians', value: 'radian' },
  1034. { text: 'Gradian', value: 'grad' },
  1035. ],
  1036. },
  1037. {
  1038. text: 'acceleration',
  1039. submenu: [
  1040. { text: 'Meters/sec²', value: 'accMS2' },
  1041. { text: 'Feet/sec²', value: 'accFS2' },
  1042. { text: 'G unit', value: 'accG' },
  1043. ],
  1044. },
  1045. {
  1046. text: 'radiation',
  1047. submenu: [
  1048. { text: 'Becquerel (Bq)', value: 'radbq' },
  1049. { text: 'curie (Ci)', value: 'radci' },
  1050. { text: 'Gray (Gy)', value: 'radgy' },
  1051. { text: 'rad', value: 'radrad' },
  1052. { text: 'Sievert (Sv)', value: 'radsv' },
  1053. { text: 'rem', value: 'radrem' },
  1054. { text: 'Exposure (C/kg)', value: 'radexpckg' },
  1055. { text: 'roentgen (R)', value: 'radr' },
  1056. { text: 'Sievert/hour (Sv/h)', value: 'radsvh' },
  1057. ],
  1058. },
  1059. {
  1060. text: 'concentration',
  1061. submenu: [
  1062. { text: 'parts-per-million (ppm)', value: 'ppm' },
  1063. { text: 'parts-per-billion (ppb)', value: 'conppb' },
  1064. { text: 'nanogram per cubic metre (ng/m³)', value: 'conngm3' },
  1065. { text: 'nanogram per normal cubic metre (ng/Nm³)', value: 'conngNm3' },
  1066. { text: 'microgram per cubic metre (μg/m³)', value: 'conμgm3' },
  1067. { text: 'microgram per normal cubic metre (μg/Nm³)', value: 'conμgNm3' },
  1068. { text: 'milligram per cubic metre (mg/m³)', value: 'conmgm3' },
  1069. { text: 'milligram per normal cubic metre (mg/Nm³)', value: 'conmgNm3' },
  1070. { text: 'gram per cubic metre (g/m³)', value: 'congm3' },
  1071. { text: 'gram per normal cubic metre (g/Nm³)', value: 'congNm3' },
  1072. ],
  1073. },
  1074. ];
  1075. };
  1076. export default kbn;