kbn.ts 38 KB

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