kbn.ts 37 KB

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