kbn.ts 37 KB

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