kbn.ts 40 KB

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