kbn.ts 38 KB

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