kbn.ts 39 KB

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