kbn.ts 37 KB

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