kbn.ts 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. import _ from 'lodash';
  2. import moment from 'moment';
  3. var kbn: any = {};
  4. kbn.valueFormats = {};
  5. kbn.regexEscape = function(value) {
  6. return value.replace(/[\\^$*+?.()|[\]{}\/]/g, '\\$&');
  7. };
  8. ///// HELPER FUNCTIONS /////
  9. kbn.round_interval = function(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 = function(seconds) {
  100. var numyears = Math.floor(seconds / 31536000);
  101. if (numyears) {
  102. return numyears + 'y';
  103. }
  104. var numdays = Math.floor((seconds % 31536000) / 86400);
  105. if (numdays) {
  106. return numdays + 'd';
  107. }
  108. var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
  109. if (numhours) {
  110. return numhours + 'h';
  111. }
  112. var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
  113. if (numminutes) {
  114. return numminutes + 'm';
  115. }
  116. var numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60);
  117. if (numseconds) {
  118. return numseconds + 's';
  119. }
  120. var 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 = function(seconds) {
  127. var strings = [];
  128. var numhours = Math.floor(seconds / 3600);
  129. var numminutes = Math.floor((seconds % 3600) / 60);
  130. var 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 = function(nr, outof) {
  137. return Math.floor(nr / outof * 10000) / 100 + '%';
  138. };
  139. kbn.addslashes = function(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 = function(range, resolution, lowLimitInterval) {
  159. var lowLimitMs = 1; // 1 millisecond default low limit
  160. var 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 = function(str) {
  177. var 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 = function(str) {
  189. var info = kbn.describe_interval(str);
  190. return info.sec * 1000 * info.count;
  191. };
  192. kbn.interval_to_seconds = function(str) {
  193. var info = kbn.describe_interval(str);
  194. return info.sec * info.count;
  195. };
  196. kbn.query_color_dot = function(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 = function(str) {
  204. return str
  205. .toLowerCase()
  206. .replace(/[^\w ]+/g, '')
  207. .replace(/ +/g, '-');
  208. };
  209. kbn.stringToJsRegex = function(str) {
  210. if (str[0] !== '/') {
  211. return new RegExp('^' + str + '$');
  212. }
  213. var match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
  214. return new RegExp(match[1], match[2]);
  215. };
  216. kbn.toFixed = function(value, decimals) {
  217. if (value === null) {
  218. return '';
  219. }
  220. var factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
  221. var 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. var decimalPos = formatted.indexOf('.');
  230. var 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 = function(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 = function(num, decimals) {
  245. if (num === null) {
  246. return null;
  247. }
  248. var n = Math.pow(10, decimals);
  249. var 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 = function(unit) {
  257. return function(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 = function(factor, extArray) {
  268. return function(size, decimals, scaledDecimals) {
  269. if (size === null) {
  270. return '';
  271. }
  272. var steps = 0;
  273. var 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 = function(unit, offset) {
  291. var prefixes = ['n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
  292. prefixes = prefixes.slice(3 + (offset || 0));
  293. var units = prefixes.map(function(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 = function(unit, offset) {
  302. var prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'].slice(offset);
  303. var units = prefixes.map(function(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 = function(symbol) {
  311. var units = ['', 'K', 'M', 'B', 'T'];
  312. var scaler = kbn.formatBuilders.scaledUnits(1000, units);
  313. return function(size, decimals, scaledDecimals) {
  314. if (size === null) {
  315. return '';
  316. }
  317. var scaled = scaler(size, decimals, scaledDecimals);
  318. return symbol + scaled;
  319. };
  320. };
  321. kbn.formatBuilders.simpleCountUnit = function(symbol) {
  322. var units = ['', 'K', 'M', 'B', 'T'];
  323. var scaler = kbn.formatBuilders.scaledUnits(1000, units);
  324. return function(size, decimals, scaledDecimals) {
  325. if (size === null) {
  326. return '';
  327. }
  328. var 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 = function(size, decimals) {
  348. if (size === null) {
  349. return '';
  350. }
  351. return kbn.toFixed(size, decimals) + '%';
  352. };
  353. kbn.valueFormats.percentunit = function(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 options, one with 0x, and one without */
  361. kbn.valueFormats.hex = function(value, decimals) {
  362. if (value == null) {
  363. return '';
  364. }
  365. return parseFloat(kbn.toFixed(value, decimals))
  366. .toString(16)
  367. .toUpperCase();
  368. };
  369. kbn.valueFormats.hex0x = function(value, decimals) {
  370. if (value == null) {
  371. return '';
  372. }
  373. var hexString = kbn.valueFormats.hex(value, decimals);
  374. if (hexString.substring(0, 1) === '-') {
  375. return '-0x' + hexString.substring(1);
  376. }
  377. return '0x' + hexString;
  378. };
  379. kbn.valueFormats.sci = function(value, decimals) {
  380. return value.toExponential(decimals);
  381. };
  382. kbn.valueFormats.locale = function(value, decimals) {
  383. return value.toLocaleString(undefined, { maximumFractionDigits: decimals });
  384. };
  385. // Currencies
  386. kbn.valueFormats.currencyUSD = kbn.formatBuilders.currency('$');
  387. kbn.valueFormats.currencyGBP = kbn.formatBuilders.currency('£');
  388. kbn.valueFormats.currencyEUR = kbn.formatBuilders.currency('€');
  389. kbn.valueFormats.currencyJPY = kbn.formatBuilders.currency('¥');
  390. kbn.valueFormats.currencyRUB = kbn.formatBuilders.currency('₽');
  391. kbn.valueFormats.currencyUAH = kbn.formatBuilders.currency('₴');
  392. kbn.valueFormats.currencyBRL = kbn.formatBuilders.currency('R$');
  393. kbn.valueFormats.currencyDKK = kbn.formatBuilders.currency('kr');
  394. kbn.valueFormats.currencyISK = kbn.formatBuilders.currency('kr');
  395. kbn.valueFormats.currencyNOK = kbn.formatBuilders.currency('kr');
  396. kbn.valueFormats.currencySEK = kbn.formatBuilders.currency('kr');
  397. kbn.valueFormats.currencyCZK = kbn.formatBuilders.currency('czk');
  398. kbn.valueFormats.currencyCHF = kbn.formatBuilders.currency('CHF');
  399. // Data (Binary)
  400. kbn.valueFormats.bits = kbn.formatBuilders.binarySIPrefix('b');
  401. kbn.valueFormats.bytes = kbn.formatBuilders.binarySIPrefix('B');
  402. kbn.valueFormats.kbytes = kbn.formatBuilders.binarySIPrefix('B', 1);
  403. kbn.valueFormats.mbytes = kbn.formatBuilders.binarySIPrefix('B', 2);
  404. kbn.valueFormats.gbytes = kbn.formatBuilders.binarySIPrefix('B', 3);
  405. // Data (Decimal)
  406. kbn.valueFormats.decbits = kbn.formatBuilders.decimalSIPrefix('b');
  407. kbn.valueFormats.decbytes = kbn.formatBuilders.decimalSIPrefix('B');
  408. kbn.valueFormats.deckbytes = kbn.formatBuilders.decimalSIPrefix('B', 1);
  409. kbn.valueFormats.decmbytes = kbn.formatBuilders.decimalSIPrefix('B', 2);
  410. kbn.valueFormats.decgbytes = kbn.formatBuilders.decimalSIPrefix('B', 3);
  411. // Data Rate
  412. kbn.valueFormats.pps = kbn.formatBuilders.decimalSIPrefix('pps');
  413. kbn.valueFormats.bps = kbn.formatBuilders.decimalSIPrefix('bps');
  414. kbn.valueFormats.Bps = kbn.formatBuilders.decimalSIPrefix('B/s');
  415. kbn.valueFormats.KBs = kbn.formatBuilders.decimalSIPrefix('Bs', 1);
  416. kbn.valueFormats.Kbits = kbn.formatBuilders.decimalSIPrefix('bps', 1);
  417. kbn.valueFormats.MBs = kbn.formatBuilders.decimalSIPrefix('Bs', 2);
  418. kbn.valueFormats.Mbits = kbn.formatBuilders.decimalSIPrefix('bps', 2);
  419. kbn.valueFormats.GBs = kbn.formatBuilders.decimalSIPrefix('Bs', 3);
  420. kbn.valueFormats.Gbits = kbn.formatBuilders.decimalSIPrefix('bps', 3);
  421. // Hash Rate
  422. kbn.valueFormats.Hs = kbn.formatBuilders.decimalSIPrefix('H/s');
  423. kbn.valueFormats.KHs = kbn.formatBuilders.decimalSIPrefix('H/s', 1);
  424. kbn.valueFormats.MHs = kbn.formatBuilders.decimalSIPrefix('H/s', 2);
  425. kbn.valueFormats.GHs = kbn.formatBuilders.decimalSIPrefix('H/s', 3);
  426. kbn.valueFormats.THs = kbn.formatBuilders.decimalSIPrefix('H/s', 4);
  427. kbn.valueFormats.PHs = kbn.formatBuilders.decimalSIPrefix('H/s', 5);
  428. kbn.valueFormats.EHs = kbn.formatBuilders.decimalSIPrefix('H/s', 6);
  429. // Throughput
  430. kbn.valueFormats.ops = kbn.formatBuilders.simpleCountUnit('ops');
  431. kbn.valueFormats.reqps = kbn.formatBuilders.simpleCountUnit('reqps');
  432. kbn.valueFormats.rps = kbn.formatBuilders.simpleCountUnit('rps');
  433. kbn.valueFormats.wps = kbn.formatBuilders.simpleCountUnit('wps');
  434. kbn.valueFormats.iops = kbn.formatBuilders.simpleCountUnit('iops');
  435. kbn.valueFormats.opm = kbn.formatBuilders.simpleCountUnit('opm');
  436. kbn.valueFormats.rpm = kbn.formatBuilders.simpleCountUnit('rpm');
  437. kbn.valueFormats.wpm = kbn.formatBuilders.simpleCountUnit('wpm');
  438. // Energy
  439. kbn.valueFormats.watt = kbn.formatBuilders.decimalSIPrefix('W');
  440. kbn.valueFormats.kwatt = kbn.formatBuilders.decimalSIPrefix('W', 1);
  441. kbn.valueFormats.mwatt = kbn.formatBuilders.decimalSIPrefix('W', -1);
  442. kbn.valueFormats.kwattm = kbn.formatBuilders.decimalSIPrefix('W/Min', 1);
  443. kbn.valueFormats.Wm2 = kbn.formatBuilders.fixedUnit('W/m2');
  444. kbn.valueFormats.voltamp = kbn.formatBuilders.decimalSIPrefix('VA');
  445. kbn.valueFormats.kvoltamp = kbn.formatBuilders.decimalSIPrefix('VA', 1);
  446. kbn.valueFormats.voltampreact = kbn.formatBuilders.decimalSIPrefix('var');
  447. kbn.valueFormats.kvoltampreact = kbn.formatBuilders.decimalSIPrefix('var', 1);
  448. kbn.valueFormats.watth = kbn.formatBuilders.decimalSIPrefix('Wh');
  449. kbn.valueFormats.kwatth = kbn.formatBuilders.decimalSIPrefix('Wh', 1);
  450. kbn.valueFormats.joule = kbn.formatBuilders.decimalSIPrefix('J');
  451. kbn.valueFormats.ev = kbn.formatBuilders.decimalSIPrefix('eV');
  452. kbn.valueFormats.amp = kbn.formatBuilders.decimalSIPrefix('A');
  453. kbn.valueFormats.kamp = kbn.formatBuilders.decimalSIPrefix('A', 1);
  454. kbn.valueFormats.mamp = kbn.formatBuilders.decimalSIPrefix('A', -1);
  455. kbn.valueFormats.volt = kbn.formatBuilders.decimalSIPrefix('V');
  456. kbn.valueFormats.kvolt = kbn.formatBuilders.decimalSIPrefix('V', 1);
  457. kbn.valueFormats.mvolt = kbn.formatBuilders.decimalSIPrefix('V', -1);
  458. kbn.valueFormats.dBm = kbn.formatBuilders.decimalSIPrefix('dBm');
  459. kbn.valueFormats.ohm = kbn.formatBuilders.decimalSIPrefix('Ω');
  460. kbn.valueFormats.lumens = kbn.formatBuilders.decimalSIPrefix('Lm');
  461. // Temperature
  462. kbn.valueFormats.celsius = kbn.formatBuilders.fixedUnit('°C');
  463. kbn.valueFormats.farenheit = kbn.formatBuilders.fixedUnit('°F');
  464. kbn.valueFormats.kelvin = kbn.formatBuilders.fixedUnit('K');
  465. kbn.valueFormats.humidity = kbn.formatBuilders.fixedUnit('%H');
  466. // Pressure
  467. kbn.valueFormats.pressurebar = kbn.formatBuilders.decimalSIPrefix('bar');
  468. kbn.valueFormats.pressurembar = kbn.formatBuilders.decimalSIPrefix('bar', -1);
  469. kbn.valueFormats.pressurekbar = kbn.formatBuilders.decimalSIPrefix('bar', 1);
  470. kbn.valueFormats.pressurehpa = kbn.formatBuilders.fixedUnit('hPa');
  471. kbn.valueFormats.pressurekpa = kbn.formatBuilders.fixedUnit('kPa');
  472. kbn.valueFormats.pressurehg = kbn.formatBuilders.fixedUnit('"Hg');
  473. kbn.valueFormats.pressurepsi = kbn.formatBuilders.scaledUnits(1000, [' psi', ' ksi', ' Mpsi']);
  474. // Force
  475. kbn.valueFormats.forceNm = kbn.formatBuilders.decimalSIPrefix('Nm');
  476. kbn.valueFormats.forcekNm = kbn.formatBuilders.decimalSIPrefix('Nm', 1);
  477. kbn.valueFormats.forceN = kbn.formatBuilders.decimalSIPrefix('N');
  478. kbn.valueFormats.forcekN = kbn.formatBuilders.decimalSIPrefix('N', 1);
  479. // Length
  480. kbn.valueFormats.lengthm = kbn.formatBuilders.decimalSIPrefix('m');
  481. kbn.valueFormats.lengthmm = kbn.formatBuilders.decimalSIPrefix('m', -1);
  482. kbn.valueFormats.lengthkm = kbn.formatBuilders.decimalSIPrefix('m', 1);
  483. kbn.valueFormats.lengthmi = kbn.formatBuilders.fixedUnit('mi');
  484. kbn.valueFormats.lengthft = kbn.formatBuilders.fixedUnit('ft');
  485. // Area
  486. kbn.valueFormats.areaM2 = kbn.formatBuilders.fixedUnit('m²');
  487. kbn.valueFormats.areaF2 = kbn.formatBuilders.fixedUnit('ft²');
  488. kbn.valueFormats.areaMI2 = kbn.formatBuilders.fixedUnit('mi²');
  489. // Mass
  490. kbn.valueFormats.massmg = kbn.formatBuilders.decimalSIPrefix('g', -1);
  491. kbn.valueFormats.massg = kbn.formatBuilders.decimalSIPrefix('g');
  492. kbn.valueFormats.masskg = kbn.formatBuilders.decimalSIPrefix('g', 1);
  493. kbn.valueFormats.masst = kbn.formatBuilders.fixedUnit('t');
  494. // Velocity
  495. kbn.valueFormats.velocityms = kbn.formatBuilders.fixedUnit('m/s');
  496. kbn.valueFormats.velocitykmh = kbn.formatBuilders.fixedUnit('km/h');
  497. kbn.valueFormats.velocitymph = kbn.formatBuilders.fixedUnit('mph');
  498. kbn.valueFormats.velocityknot = kbn.formatBuilders.fixedUnit('kn');
  499. // Acceleration
  500. kbn.valueFormats.accMS2 = kbn.formatBuilders.fixedUnit('m/sec²');
  501. kbn.valueFormats.accFS2 = kbn.formatBuilders.fixedUnit('f/sec²');
  502. kbn.valueFormats.accG = kbn.formatBuilders.fixedUnit('g');
  503. // Volume
  504. kbn.valueFormats.litre = kbn.formatBuilders.decimalSIPrefix('L');
  505. kbn.valueFormats.mlitre = kbn.formatBuilders.decimalSIPrefix('L', -1);
  506. kbn.valueFormats.m3 = kbn.formatBuilders.fixedUnit('m3');
  507. kbn.valueFormats.Nm3 = kbn.formatBuilders.fixedUnit('Nm3');
  508. kbn.valueFormats.dm3 = kbn.formatBuilders.fixedUnit('dm3');
  509. kbn.valueFormats.gallons = kbn.formatBuilders.fixedUnit('gal');
  510. // Flow
  511. kbn.valueFormats.flowgpm = kbn.formatBuilders.fixedUnit('gpm');
  512. kbn.valueFormats.flowcms = kbn.formatBuilders.fixedUnit('cms');
  513. kbn.valueFormats.flowcfs = kbn.formatBuilders.fixedUnit('cfs');
  514. kbn.valueFormats.flowcfm = kbn.formatBuilders.fixedUnit('cfm');
  515. kbn.valueFormats.litreh = kbn.formatBuilders.fixedUnit('l/h');
  516. kbn.valueFormats.flowlpm = kbn.formatBuilders.decimalSIPrefix('L');
  517. kbn.valueFormats.flowmlpm = kbn.formatBuilders.decimalSIPrefix('L', -1);
  518. // Angle
  519. kbn.valueFormats.degree = kbn.formatBuilders.fixedUnit('°');
  520. kbn.valueFormats.radian = kbn.formatBuilders.fixedUnit('rad');
  521. kbn.valueFormats.grad = kbn.formatBuilders.fixedUnit('grad');
  522. // Radiation
  523. kbn.valueFormats.radbq = kbn.formatBuilders.decimalSIPrefix('Bq');
  524. kbn.valueFormats.radci = kbn.formatBuilders.decimalSIPrefix('Ci');
  525. kbn.valueFormats.radgy = kbn.formatBuilders.decimalSIPrefix('Gy');
  526. kbn.valueFormats.radrad = kbn.formatBuilders.decimalSIPrefix('rad');
  527. kbn.valueFormats.radsv = kbn.formatBuilders.decimalSIPrefix('Sv');
  528. kbn.valueFormats.radrem = kbn.formatBuilders.decimalSIPrefix('rem');
  529. kbn.valueFormats.radexpckg = kbn.formatBuilders.decimalSIPrefix('C/kg');
  530. kbn.valueFormats.radr = kbn.formatBuilders.decimalSIPrefix('R');
  531. kbn.valueFormats.radsvh = kbn.formatBuilders.decimalSIPrefix('Sv/h');
  532. // Concentration
  533. kbn.valueFormats.ppm = kbn.formatBuilders.fixedUnit('ppm');
  534. kbn.valueFormats.conppb = kbn.formatBuilders.fixedUnit('ppb');
  535. kbn.valueFormats.conngm3 = kbn.formatBuilders.fixedUnit('ng/m3');
  536. kbn.valueFormats.conngNm3 = kbn.formatBuilders.fixedUnit('ng/Nm3');
  537. kbn.valueFormats.conμgm3 = kbn.formatBuilders.fixedUnit('μg/m3');
  538. kbn.valueFormats.conμgNm3 = kbn.formatBuilders.fixedUnit('μg/Nm3');
  539. kbn.valueFormats.conmgm3 = kbn.formatBuilders.fixedUnit('mg/m3');
  540. kbn.valueFormats.conmgNm3 = kbn.formatBuilders.fixedUnit('mg/Nm3');
  541. kbn.valueFormats.congm3 = kbn.formatBuilders.fixedUnit('g/m3');
  542. kbn.valueFormats.congNm3 = kbn.formatBuilders.fixedUnit('g/Nm3');
  543. // Time
  544. kbn.valueFormats.hertz = kbn.formatBuilders.decimalSIPrefix('Hz');
  545. kbn.valueFormats.ms = function(size, decimals, scaledDecimals) {
  546. if (size === null) {
  547. return '';
  548. }
  549. if (Math.abs(size) < 1000) {
  550. return kbn.toFixed(size, decimals) + ' ms';
  551. } else if (Math.abs(size) < 60000) {
  552. // Less than 1 min
  553. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, ' s');
  554. } else if (Math.abs(size) < 3600000) {
  555. // Less than 1 hour, divide in minutes
  556. return kbn.toFixedScaled(size / 60000, decimals, scaledDecimals, 5, ' min');
  557. } else if (Math.abs(size) < 86400000) {
  558. // Less than one day, divide in hours
  559. return kbn.toFixedScaled(size / 3600000, decimals, scaledDecimals, 7, ' hour');
  560. } else if (Math.abs(size) < 31536000000) {
  561. // Less than one year, divide in days
  562. return kbn.toFixedScaled(size / 86400000, decimals, scaledDecimals, 8, ' day');
  563. }
  564. return kbn.toFixedScaled(size / 31536000000, decimals, scaledDecimals, 10, ' year');
  565. };
  566. kbn.valueFormats.s = function(size, decimals, scaledDecimals) {
  567. if (size === null) {
  568. return '';
  569. }
  570. // Less than 1 µs, divide in ns
  571. if (Math.abs(size) < 0.000001) {
  572. return kbn.toFixedScaled(size * 1e9, decimals, scaledDecimals - decimals, -9, ' ns');
  573. }
  574. // Less than 1 ms, divide in µs
  575. if (Math.abs(size) < 0.001) {
  576. return kbn.toFixedScaled(size * 1e6, decimals, scaledDecimals - decimals, -6, ' µs');
  577. }
  578. // Less than 1 second, divide in ms
  579. if (Math.abs(size) < 1) {
  580. return kbn.toFixedScaled(size * 1e3, decimals, scaledDecimals - decimals, -3, ' ms');
  581. }
  582. if (Math.abs(size) < 60) {
  583. return kbn.toFixed(size, decimals) + ' s';
  584. } else if (Math.abs(size) < 3600) {
  585. // Less than 1 hour, divide in minutes
  586. return kbn.toFixedScaled(size / 60, decimals, scaledDecimals, 1, ' min');
  587. } else if (Math.abs(size) < 86400) {
  588. // Less than one day, divide in hours
  589. return kbn.toFixedScaled(size / 3600, decimals, scaledDecimals, 4, ' hour');
  590. } else if (Math.abs(size) < 604800) {
  591. // Less than one week, divide in days
  592. return kbn.toFixedScaled(size / 86400, decimals, scaledDecimals, 5, ' day');
  593. } else if (Math.abs(size) < 31536000) {
  594. // Less than one year, divide in week
  595. return kbn.toFixedScaled(size / 604800, decimals, scaledDecimals, 6, ' week');
  596. }
  597. return kbn.toFixedScaled(size / 3.15569e7, decimals, scaledDecimals, 7, ' year');
  598. };
  599. kbn.valueFormats['µs'] = function(size, decimals, scaledDecimals) {
  600. if (size === null) {
  601. return '';
  602. }
  603. if (Math.abs(size) < 1000) {
  604. return kbn.toFixed(size, decimals) + ' µs';
  605. } else if (Math.abs(size) < 1000000) {
  606. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, ' ms');
  607. } else {
  608. return kbn.toFixedScaled(size / 1000000, decimals, scaledDecimals, 6, ' s');
  609. }
  610. };
  611. kbn.valueFormats.ns = function(size, decimals, scaledDecimals) {
  612. if (size === null) {
  613. return '';
  614. }
  615. if (Math.abs(size) < 1000) {
  616. return kbn.toFixed(size, decimals) + ' ns';
  617. } else if (Math.abs(size) < 1000000) {
  618. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, ' µs');
  619. } else if (Math.abs(size) < 1000000000) {
  620. return kbn.toFixedScaled(size / 1000000, decimals, scaledDecimals, 6, ' ms');
  621. } else if (Math.abs(size) < 60000000000) {
  622. return kbn.toFixedScaled(size / 1000000000, decimals, scaledDecimals, 9, ' s');
  623. } else {
  624. return kbn.toFixedScaled(size / 60000000000, decimals, scaledDecimals, 12, ' min');
  625. }
  626. };
  627. kbn.valueFormats.m = function(size, decimals, scaledDecimals) {
  628. if (size === null) {
  629. return '';
  630. }
  631. if (Math.abs(size) < 60) {
  632. return kbn.toFixed(size, decimals) + ' min';
  633. } else if (Math.abs(size) < 1440) {
  634. return kbn.toFixedScaled(size / 60, decimals, scaledDecimals, 2, ' hour');
  635. } else if (Math.abs(size) < 10080) {
  636. return kbn.toFixedScaled(size / 1440, decimals, scaledDecimals, 3, ' day');
  637. } else if (Math.abs(size) < 604800) {
  638. return kbn.toFixedScaled(size / 10080, decimals, scaledDecimals, 4, ' week');
  639. } else {
  640. return kbn.toFixedScaled(size / 5.25948e5, decimals, scaledDecimals, 5, ' year');
  641. }
  642. };
  643. kbn.valueFormats.h = function(size, decimals, scaledDecimals) {
  644. if (size === null) {
  645. return '';
  646. }
  647. if (Math.abs(size) < 24) {
  648. return kbn.toFixed(size, decimals) + ' hour';
  649. } else if (Math.abs(size) < 168) {
  650. return kbn.toFixedScaled(size / 24, decimals, scaledDecimals, 2, ' day');
  651. } else if (Math.abs(size) < 8760) {
  652. return kbn.toFixedScaled(size / 168, decimals, scaledDecimals, 3, ' week');
  653. } else {
  654. return kbn.toFixedScaled(size / 8760, decimals, scaledDecimals, 4, ' year');
  655. }
  656. };
  657. kbn.valueFormats.d = function(size, decimals, scaledDecimals) {
  658. if (size === null) {
  659. return '';
  660. }
  661. if (Math.abs(size) < 7) {
  662. return kbn.toFixed(size, decimals) + ' day';
  663. } else if (Math.abs(size) < 365) {
  664. return kbn.toFixedScaled(size / 7, decimals, scaledDecimals, 2, ' week');
  665. } else {
  666. return kbn.toFixedScaled(size / 365, decimals, scaledDecimals, 3, ' year');
  667. }
  668. };
  669. kbn.toDuration = function(size, decimals, timeScale) {
  670. if (size === null) {
  671. return '';
  672. }
  673. if (size === 0) {
  674. return '0 ' + timeScale + 's';
  675. }
  676. if (size < 0) {
  677. return kbn.toDuration(-size, decimals, timeScale) + ' ago';
  678. }
  679. var units = [
  680. { short: 'y', long: 'year' },
  681. { short: 'M', long: 'month' },
  682. { short: 'w', long: 'week' },
  683. { short: 'd', long: 'day' },
  684. { short: 'h', long: 'hour' },
  685. { short: 'm', long: 'minute' },
  686. { short: 's', long: 'second' },
  687. { short: 'ms', long: 'millisecond' },
  688. ];
  689. // convert $size to milliseconds
  690. // intervals_in_seconds uses seconds (duh), convert them to milliseconds here to minimize floating point errors
  691. size *=
  692. kbn.intervals_in_seconds[
  693. units.find(function(e) {
  694. return e.long === timeScale;
  695. }).short
  696. ] * 1000;
  697. var strings = [];
  698. // after first value >= 1 print only $decimals more
  699. var decrementDecimals = false;
  700. for (var i = 0; i < units.length && decimals >= 0; i++) {
  701. var interval = kbn.intervals_in_seconds[units[i].short] * 1000;
  702. var value = size / interval;
  703. if (value >= 1 || decrementDecimals) {
  704. decrementDecimals = true;
  705. var floor = Math.floor(value);
  706. var unit = units[i].long + (floor !== 1 ? 's' : '');
  707. strings.push(floor + ' ' + unit);
  708. size = size % interval;
  709. decimals--;
  710. }
  711. }
  712. return strings.join(', ');
  713. };
  714. kbn.valueFormats.dtdurationms = function(size, decimals) {
  715. return kbn.toDuration(size, decimals, 'millisecond');
  716. };
  717. kbn.valueFormats.dtdurations = function(size, decimals) {
  718. return kbn.toDuration(size, decimals, 'second');
  719. };
  720. kbn.valueFormats.dthms = function(size, decimals) {
  721. return kbn.secondsToHhmmss(size);
  722. };
  723. kbn.valueFormats.timeticks = function(size, decimals, scaledDecimals) {
  724. return kbn.valueFormats.s(size / 100, decimals, scaledDecimals);
  725. };
  726. kbn.valueFormats.dateTimeAsIso = function(epoch, isUtc) {
  727. var time = isUtc ? moment.utc(epoch) : moment(epoch);
  728. if (moment().isSame(epoch, 'day')) {
  729. return time.format('HH:mm:ss');
  730. }
  731. return time.format('YYYY-MM-DD HH:mm:ss');
  732. };
  733. kbn.valueFormats.dateTimeAsUS = function(epoch, isUtc) {
  734. var time = isUtc ? moment.utc(epoch) : moment(epoch);
  735. if (moment().isSame(epoch, 'day')) {
  736. return time.format('h:mm:ss a');
  737. }
  738. return time.format('MM/DD/YYYY h:mm:ss a');
  739. };
  740. kbn.valueFormats.dateTimeFromNow = function(epoch, isUtc) {
  741. var time = isUtc ? moment.utc(epoch) : moment(epoch);
  742. return time.fromNow();
  743. };
  744. ///// FORMAT MENU /////
  745. kbn.getUnitFormats = function() {
  746. return [
  747. {
  748. text: 'none',
  749. submenu: [
  750. { text: 'none', value: 'none' },
  751. { text: 'short', value: 'short' },
  752. { text: 'percent (0-100)', value: 'percent' },
  753. { text: 'percent (0.0-1.0)', value: 'percentunit' },
  754. { text: 'Humidity (%H)', value: 'humidity' },
  755. { text: 'decibel', value: 'dB' },
  756. { text: 'hexadecimal (0x)', value: 'hex0x' },
  757. { text: 'hexadecimal', value: 'hex' },
  758. { text: 'scientific notation', value: 'sci' },
  759. { text: 'locale format', value: 'locale' },
  760. ],
  761. },
  762. {
  763. text: 'currency',
  764. submenu: [
  765. { text: 'Dollars ($)', value: 'currencyUSD' },
  766. { text: 'Pounds (£)', value: 'currencyGBP' },
  767. { text: 'Euro (€)', value: 'currencyEUR' },
  768. { text: 'Yen (¥)', value: 'currencyJPY' },
  769. { text: 'Rubles (₽)', value: 'currencyRUB' },
  770. { text: 'Hryvnias (₴)', value: 'currencyUAH' },
  771. { text: 'Real (R$)', value: 'currencyBRL' },
  772. { text: 'Danish Krone (kr)', value: 'currencyDKK' },
  773. { text: 'Icelandic Króna (kr)', value: 'currencyISK' },
  774. { text: 'Norwegian Krone (kr)', value: 'currencyNOK' },
  775. { text: 'Swedish Krona (kr)', value: 'currencySEK' },
  776. { text: 'Czech koruna (czk)', value: 'currencyCZK' },
  777. { text: 'Swiss franc (CHF)', value: 'currencyCHF' },
  778. ],
  779. },
  780. {
  781. text: 'time',
  782. submenu: [
  783. { text: 'Hertz (1/s)', value: 'hertz' },
  784. { text: 'nanoseconds (ns)', value: 'ns' },
  785. { text: 'microseconds (µs)', value: 'µs' },
  786. { text: 'milliseconds (ms)', value: 'ms' },
  787. { text: 'seconds (s)', value: 's' },
  788. { text: 'minutes (m)', value: 'm' },
  789. { text: 'hours (h)', value: 'h' },
  790. { text: 'days (d)', value: 'd' },
  791. { text: 'duration (ms)', value: 'dtdurationms' },
  792. { text: 'duration (s)', value: 'dtdurations' },
  793. { text: 'duration (hh:mm:ss)', value: 'dthms' },
  794. { text: 'Timeticks (s/100)', value: 'timeticks' },
  795. ],
  796. },
  797. {
  798. text: 'date & time',
  799. submenu: [
  800. { text: 'YYYY-MM-DD HH:mm:ss', value: 'dateTimeAsIso' },
  801. { text: 'DD/MM/YYYY h:mm:ss a', value: 'dateTimeAsUS' },
  802. { text: 'From Now', value: 'dateTimeFromNow' },
  803. ],
  804. },
  805. {
  806. text: 'data (IEC)',
  807. submenu: [
  808. { text: 'bits', value: 'bits' },
  809. { text: 'bytes', value: 'bytes' },
  810. { text: 'kibibytes', value: 'kbytes' },
  811. { text: 'mebibytes', value: 'mbytes' },
  812. { text: 'gibibytes', value: 'gbytes' },
  813. ],
  814. },
  815. {
  816. text: 'data (Metric)',
  817. submenu: [
  818. { text: 'bits', value: 'decbits' },
  819. { text: 'bytes', value: 'decbytes' },
  820. { text: 'kilobytes', value: 'deckbytes' },
  821. { text: 'megabytes', value: 'decmbytes' },
  822. { text: 'gigabytes', value: 'decgbytes' },
  823. ],
  824. },
  825. {
  826. text: 'data rate',
  827. submenu: [
  828. { text: 'packets/sec', value: 'pps' },
  829. { text: 'bits/sec', value: 'bps' },
  830. { text: 'bytes/sec', value: 'Bps' },
  831. { text: 'kilobits/sec', value: 'Kbits' },
  832. { text: 'kilobytes/sec', value: 'KBs' },
  833. { text: 'megabits/sec', value: 'Mbits' },
  834. { text: 'megabytes/sec', value: 'MBs' },
  835. { text: 'gigabytes/sec', value: 'GBs' },
  836. { text: 'gigabits/sec', value: 'Gbits' },
  837. ],
  838. },
  839. {
  840. text: 'hash rate',
  841. submenu: [
  842. { text: 'hashes/sec', value: 'Hs' },
  843. { text: 'kilohashes/sec', value: 'KHs' },
  844. { text: 'megahashes/sec', value: 'MHs' },
  845. { text: 'gigahashes/sec', value: 'GHs' },
  846. { text: 'terahashes/sec', value: 'THs' },
  847. { text: 'petahashes/sec', value: 'PHs' },
  848. { text: 'exahashes/sec', value: 'EHs' },
  849. ],
  850. },
  851. {
  852. text: 'throughput',
  853. submenu: [
  854. { text: 'ops/sec (ops)', value: 'ops' },
  855. { text: 'requests/sec (rps)', value: 'reqps' },
  856. { text: 'reads/sec (rps)', value: 'rps' },
  857. { text: 'writes/sec (wps)', value: 'wps' },
  858. { text: 'I/O ops/sec (iops)', value: 'iops' },
  859. { text: 'ops/min (opm)', value: 'opm' },
  860. { text: 'reads/min (rpm)', value: 'rpm' },
  861. { text: 'writes/min (wpm)', value: 'wpm' },
  862. ],
  863. },
  864. {
  865. text: 'length',
  866. submenu: [
  867. { text: 'millimetre (mm)', value: 'lengthmm' },
  868. { text: 'meter (m)', value: 'lengthm' },
  869. { text: 'feet (ft)', value: 'lengthft' },
  870. { text: 'kilometer (km)', value: 'lengthkm' },
  871. { text: 'mile (mi)', value: 'lengthmi' },
  872. ],
  873. },
  874. {
  875. text: 'area',
  876. submenu: [
  877. { text: 'Square Meters (m²)', value: 'areaM2' },
  878. { text: 'Square Feet (ft²)', value: 'areaF2' },
  879. { text: 'Square Miles (mi²)', value: 'areaMI2' },
  880. ],
  881. },
  882. {
  883. text: 'mass',
  884. submenu: [
  885. { text: 'milligram (mg)', value: 'massmg' },
  886. { text: 'gram (g)', value: 'massg' },
  887. { text: 'kilogram (kg)', value: 'masskg' },
  888. { text: 'metric ton (t)', value: 'masst' },
  889. ],
  890. },
  891. {
  892. text: 'velocity',
  893. submenu: [
  894. { text: 'metres/second (m/s)', value: 'velocityms' },
  895. { text: 'kilometers/hour (km/h)', value: 'velocitykmh' },
  896. { text: 'miles/hour (mph)', value: 'velocitymph' },
  897. { text: 'knot (kn)', value: 'velocityknot' },
  898. ],
  899. },
  900. {
  901. text: 'volume',
  902. submenu: [
  903. { text: 'millilitre (mL)', value: 'mlitre' },
  904. { text: 'litre (L)', value: 'litre' },
  905. { text: 'cubic metre', value: 'm3' },
  906. { text: 'Normal cubic metre', value: 'Nm3' },
  907. { text: 'cubic decimetre', value: 'dm3' },
  908. { text: 'gallons', value: 'gallons' },
  909. ],
  910. },
  911. {
  912. text: 'energy',
  913. submenu: [
  914. { text: 'Watt (W)', value: 'watt' },
  915. { text: 'Kilowatt (kW)', value: 'kwatt' },
  916. { text: 'Milliwatt (mW)', value: 'mwatt' },
  917. { text: 'Watt per square metre (W/m2)', value: 'Wm2' },
  918. { text: 'Volt-ampere (VA)', value: 'voltamp' },
  919. { text: 'Kilovolt-ampere (kVA)', value: 'kvoltamp' },
  920. { text: 'Volt-ampere reactive (var)', value: 'voltampreact' },
  921. { text: 'Kilovolt-ampere reactive (kvar)', value: 'kvoltampreact' },
  922. { text: 'Watt-hour (Wh)', value: 'watth' },
  923. { text: 'Kilowatt-hour (kWh)', value: 'kwatth' },
  924. { text: 'Kilowatt-min (kWm)', value: 'kwattm' },
  925. { text: 'Joule (J)', value: 'joule' },
  926. { text: 'Electron volt (eV)', value: 'ev' },
  927. { text: 'Ampere (A)', value: 'amp' },
  928. { text: 'Kiloampere (kA)', value: 'kamp' },
  929. { text: 'Milliampere (mA)', value: 'mamp' },
  930. { text: 'Volt (V)', value: 'volt' },
  931. { text: 'Kilovolt (kV)', value: 'kvolt' },
  932. { text: 'Millivolt (mV)', value: 'mvolt' },
  933. { text: 'Decibel-milliwatt (dBm)', value: 'dBm' },
  934. { text: 'Ohm (Ω)', value: 'ohm' },
  935. { text: 'Lumens (Lm)', value: 'lumens' },
  936. ],
  937. },
  938. {
  939. text: 'temperature',
  940. submenu: [
  941. { text: 'Celsius (°C)', value: 'celsius' },
  942. { text: 'Farenheit (°F)', value: 'farenheit' },
  943. { text: 'Kelvin (K)', value: 'kelvin' },
  944. ],
  945. },
  946. {
  947. text: 'pressure',
  948. submenu: [
  949. { text: 'Millibars', value: 'pressurembar' },
  950. { text: 'Bars', value: 'pressurebar' },
  951. { text: 'Kilobars', value: 'pressurekbar' },
  952. { text: 'Hectopascals', value: 'pressurehpa' },
  953. { text: 'Kilopascals', value: 'pressurekpa' },
  954. { text: 'Inches of mercury', value: 'pressurehg' },
  955. { text: 'PSI', value: 'pressurepsi' },
  956. ],
  957. },
  958. {
  959. text: 'force',
  960. submenu: [
  961. { text: 'Newton-meters (Nm)', value: 'forceNm' },
  962. { text: 'Kilonewton-meters (kNm)', value: 'forcekNm' },
  963. { text: 'Newtons (N)', value: 'forceN' },
  964. { text: 'Kilonewtons (kN)', value: 'forcekN' },
  965. ],
  966. },
  967. {
  968. text: 'flow',
  969. submenu: [
  970. { text: 'Gallons/min (gpm)', value: 'flowgpm' },
  971. { text: 'Cubic meters/sec (cms)', value: 'flowcms' },
  972. { text: 'Cubic feet/sec (cfs)', value: 'flowcfs' },
  973. { text: 'Cubic feet/min (cfm)', value: 'flowcfm' },
  974. { text: 'Litre/hour', value: 'litreh' },
  975. { text: 'Litre/min (l/min)', value: 'flowlpm' },
  976. { text: 'milliLitre/min (mL/min)', value: 'flowmlpm' },
  977. ],
  978. },
  979. {
  980. text: 'angle',
  981. submenu: [
  982. { text: 'Degrees (°)', value: 'degree' },
  983. { text: 'Radians', value: 'radian' },
  984. { text: 'Gradian', value: 'grad' },
  985. ],
  986. },
  987. {
  988. text: 'acceleration',
  989. submenu: [
  990. { text: 'Meters/sec²', value: 'accMS2' },
  991. { text: 'Feet/sec²', value: 'accFS2' },
  992. { text: 'G unit', value: 'accG' },
  993. ],
  994. },
  995. {
  996. text: 'radiation',
  997. submenu: [
  998. { text: 'Becquerel (Bq)', value: 'radbq' },
  999. { text: 'curie (Ci)', value: 'radci' },
  1000. { text: 'Gray (Gy)', value: 'radgy' },
  1001. { text: 'rad', value: 'radrad' },
  1002. { text: 'Sievert (Sv)', value: 'radsv' },
  1003. { text: 'rem', value: 'radrem' },
  1004. { text: 'Exposure (C/kg)', value: 'radexpckg' },
  1005. { text: 'roentgen (R)', value: 'radr' },
  1006. { text: 'Sievert/hour (Sv/h)', value: 'radsvh' },
  1007. ],
  1008. },
  1009. {
  1010. text: 'concentration',
  1011. submenu: [
  1012. { text: 'parts-per-million (ppm)', value: 'ppm' },
  1013. { text: 'parts-per-billion (ppb)', value: 'conppb' },
  1014. { text: 'nanogram per cubic metre (ng/m3)', value: 'conngm3' },
  1015. { text: 'nanogram per normal cubic metre (ng/Nm3)', value: 'conngNm3' },
  1016. { text: 'microgram per cubic metre (μg/m3)', value: 'conμgm3' },
  1017. { text: 'microgram per normal cubic metre (μg/Nm3)', value: 'conμgNm3' },
  1018. { text: 'milligram per cubic metre (mg/m3)', value: 'conmgm3' },
  1019. { text: 'milligram per normal cubic metre (mg/Nm3)', value: 'conmgNm3' },
  1020. { text: 'gram per cubic metre (g/m3)', value: 'congm3' },
  1021. { text: 'gram per normal cubic metre (g/Nm3)', value: 'congNm3' },
  1022. ],
  1023. },
  1024. ];
  1025. };
  1026. export default kbn;