kbn.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. define([
  2. 'jquery',
  3. 'lodash',
  4. 'moment'
  5. ],
  6. function($, _, moment) {
  7. 'use strict';
  8. var kbn = {};
  9. kbn.valueFormats = {};
  10. kbn.round_interval = function(interval) {
  11. switch (true) {
  12. // 0.5s
  13. case (interval <= 500):
  14. return 100; // 0.1s
  15. // 5s
  16. case (interval <= 5000):
  17. return 1000; // 1s
  18. // 7.5s
  19. case (interval <= 7500):
  20. return 5000; // 5s
  21. // 15s
  22. case (interval <= 15000):
  23. return 10000; // 10s
  24. // 45s
  25. case (interval <= 45000):
  26. return 30000; // 30s
  27. // 3m
  28. case (interval <= 180000):
  29. return 60000; // 1m
  30. // 9m
  31. case (interval <= 450000):
  32. return 300000; // 5m
  33. // 20m
  34. case (interval <= 1200000):
  35. return 600000; // 10m
  36. // 45m
  37. case (interval <= 2700000):
  38. return 1800000; // 30m
  39. // 2h
  40. case (interval <= 7200000):
  41. return 3600000; // 1h
  42. // 6h
  43. case (interval <= 21600000):
  44. return 10800000; // 3h
  45. // 24h
  46. case (interval <= 86400000):
  47. return 43200000; // 12h
  48. // 48h
  49. case (interval <= 172800000):
  50. return 86400000; // 24h
  51. // 1w
  52. case (interval <= 604800000):
  53. return 86400000; // 24h
  54. // 3w
  55. case (interval <= 1814400000):
  56. return 604800000; // 1w
  57. // 2y
  58. case (interval < 3628800000):
  59. return 2592000000; // 30d
  60. default:
  61. return 31536000000; // 1y
  62. }
  63. };
  64. kbn.secondsToHms = function(seconds) {
  65. var numyears = Math.floor(seconds / 31536000);
  66. if(numyears){
  67. return numyears + 'y';
  68. }
  69. var numdays = Math.floor((seconds % 31536000) / 86400);
  70. if(numdays){
  71. return numdays + 'd';
  72. }
  73. var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
  74. if(numhours){
  75. return numhours + 'h';
  76. }
  77. var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
  78. if(numminutes){
  79. return numminutes + 'm';
  80. }
  81. var numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60);
  82. if(numseconds){
  83. return numseconds + 's';
  84. }
  85. var nummilliseconds = Math.floor(seconds * 1000.0);
  86. if(nummilliseconds){
  87. return nummilliseconds + 'ms';
  88. }
  89. return 'less then a millisecond'; //'just now' //or other string you like;
  90. };
  91. kbn.to_percent = function(number,outof) {
  92. return Math.floor((number/outof)*10000)/100 + "%";
  93. };
  94. kbn.addslashes = function(str) {
  95. str = str.replace(/\\/g, '\\\\');
  96. str = str.replace(/\'/g, '\\\'');
  97. str = str.replace(/\"/g, '\\"');
  98. str = str.replace(/\0/g, '\\0');
  99. return str;
  100. };
  101. kbn.interval_regex = /(\d+(?:\.\d+)?)([Mwdhmsy])/;
  102. // histogram & trends
  103. kbn.intervals_in_seconds = {
  104. y: 31536000,
  105. M: 2592000,
  106. w: 604800,
  107. d: 86400,
  108. h: 3600,
  109. m: 60,
  110. s: 1
  111. };
  112. kbn.calculateInterval = function(range, resolution, userInterval) {
  113. var lowLimitMs = 1; // 1 millisecond default low limit
  114. var intervalMs, lowLimitInterval;
  115. if (userInterval) {
  116. if (userInterval[0] === '>') {
  117. lowLimitInterval = userInterval.slice(1);
  118. lowLimitMs = kbn.interval_to_ms(lowLimitInterval);
  119. }
  120. else {
  121. return userInterval;
  122. }
  123. }
  124. intervalMs = kbn.round_interval((range.to.valueOf() - range.from.valueOf()) / resolution);
  125. if (lowLimitMs > intervalMs) {
  126. intervalMs = lowLimitMs;
  127. }
  128. return kbn.secondsToHms(intervalMs / 1000);
  129. };
  130. kbn.describe_interval = function (string) {
  131. var matches = string.match(kbn.interval_regex);
  132. if (!matches || !_.has(kbn.intervals_in_seconds, matches[2])) {
  133. throw new Error('Invalid interval string, expexcting a number followed by one of "Mwdhmsy"');
  134. } else {
  135. return {
  136. sec: kbn.intervals_in_seconds[matches[2]],
  137. type: matches[2],
  138. count: parseInt(matches[1], 10)
  139. };
  140. }
  141. };
  142. kbn.interval_to_ms = function(string) {
  143. var info = kbn.describe_interval(string);
  144. return info.sec * 1000 * info.count;
  145. };
  146. kbn.interval_to_seconds = function (string) {
  147. var info = kbn.describe_interval(string);
  148. return info.sec * info.count;
  149. };
  150. /* This is a simplified version of elasticsearch's date parser */
  151. kbn.parseDate = function(text) {
  152. if(_.isDate(text)) {
  153. return text;
  154. }
  155. var time;
  156. var mathString = "";
  157. var index;
  158. var parseString;
  159. if (text.substring(0,3) === "now") {
  160. time = new Date();
  161. mathString = text.substring(3);
  162. }
  163. else if (text.substring(0,5) === 'today') {
  164. time = new Date();
  165. time.setHours(0,0,0,0);
  166. mathString = text.substring(5);
  167. }
  168. else {
  169. index = text.indexOf("||");
  170. parseString;
  171. if (index === -1) {
  172. parseString = text;
  173. mathString = ""; // nothing else
  174. } else {
  175. parseString = text.substring(0, index);
  176. mathString = text.substring(index + 2);
  177. }
  178. // We're going to just require ISO8601 timestamps, k?
  179. time = new Date(parseString);
  180. }
  181. if (!mathString.length) {
  182. return time;
  183. }
  184. //return [time,parseString,mathString];
  185. return kbn.parseDateMath(mathString, time);
  186. };
  187. kbn._timespanRegex = /^\d+[h,m,M,w,s,H,d]$/;
  188. kbn.isValidTimeSpan = function(str) {
  189. return kbn._timespanRegex.test(str);
  190. };
  191. kbn.parseDateMath = function(mathString, time, roundUp) {
  192. var dateTime = moment(time);
  193. for (var i = 0; i < mathString.length;) {
  194. var c = mathString.charAt(i++),
  195. type,
  196. num,
  197. unit;
  198. if (c === '/') {
  199. type = 0;
  200. } else if (c === '+') {
  201. type = 1;
  202. } else if (c === '-') {
  203. type = 2;
  204. } else {
  205. return false;
  206. }
  207. if (isNaN(mathString.charAt(i))) {
  208. num = 1;
  209. } else {
  210. var numFrom = i;
  211. while (!isNaN(mathString.charAt(i))) {
  212. i++;
  213. }
  214. num = parseInt(mathString.substring(numFrom, i),10);
  215. }
  216. if (type === 0) {
  217. // rounding is only allowed on whole numbers
  218. if (num !== 1) {
  219. return false;
  220. }
  221. }
  222. unit = mathString.charAt(i++);
  223. switch (unit) {
  224. case 'y':
  225. if (type === 0) {
  226. roundUp ? dateTime.endOf('year') : dateTime.startOf('year');
  227. } else if (type === 1) {
  228. dateTime.add(num, 'years');
  229. } else if (type === 2) {
  230. dateTime.subtract(num, 'years');
  231. }
  232. break;
  233. case 'M':
  234. if (type === 0) {
  235. roundUp ? dateTime.endOf('month') : dateTime.startOf('month');
  236. } else if (type === 1) {
  237. dateTime.add(num, 'months');
  238. } else if (type === 2) {
  239. dateTime.subtract(num, 'months');
  240. }
  241. break;
  242. case 'w':
  243. if (type === 0) {
  244. roundUp ? dateTime.endOf('week') : dateTime.startOf('week');
  245. } else if (type === 1) {
  246. dateTime.add(num, 'weeks');
  247. } else if (type === 2) {
  248. dateTime.subtract(num, 'weeks');
  249. }
  250. break;
  251. case 'd':
  252. if (type === 0) {
  253. roundUp ? dateTime.endOf('day') : dateTime.startOf('day');
  254. } else if (type === 1) {
  255. dateTime.add(num, 'days');
  256. } else if (type === 2) {
  257. dateTime.subtract(num, 'days');
  258. }
  259. break;
  260. case 'h':
  261. case 'H':
  262. if (type === 0) {
  263. roundUp ? dateTime.endOf('hour') : dateTime.startOf('hour');
  264. } else if (type === 1) {
  265. dateTime.add(num, 'hours');
  266. } else if (type === 2) {
  267. dateTime.subtract(num,'hours');
  268. }
  269. break;
  270. case 'm':
  271. if (type === 0) {
  272. roundUp ? dateTime.endOf('minute') : dateTime.startOf('minute');
  273. } else if (type === 1) {
  274. dateTime.add(num, 'minutes');
  275. } else if (type === 2) {
  276. dateTime.subtract(num, 'minutes');
  277. }
  278. break;
  279. case 's':
  280. if (type === 0) {
  281. roundUp ? dateTime.endOf('second') : dateTime.startOf('second');
  282. } else if (type === 1) {
  283. dateTime.add(num, 'seconds');
  284. } else if (type === 2) {
  285. dateTime.subtract(num, 'seconds');
  286. }
  287. break;
  288. default:
  289. return false;
  290. }
  291. }
  292. return dateTime.toDate();
  293. };
  294. kbn.query_color_dot = function (color, diameter) {
  295. return '<div class="icon-circle" style="' + [
  296. 'display:inline-block',
  297. 'color:' + color,
  298. 'font-size:' + diameter + 'px',
  299. ].join(';') + '"></div>';
  300. };
  301. kbn.valueFormats.percent = function(size, decimals) {
  302. return kbn.toFixed(size, decimals) + '%';
  303. };
  304. kbn.formatFuncCreator = function(factor, extArray) {
  305. return function(size, decimals, scaledDecimals) {
  306. if (size === null) {
  307. return "";
  308. }
  309. var steps = 0;
  310. var limit = extArray.length;
  311. while (Math.abs(size) >= factor) {
  312. steps++;
  313. size /= factor;
  314. if (steps >= limit) { return "NA"; }
  315. }
  316. if (steps > 0 && scaledDecimals !== null) {
  317. decimals = scaledDecimals + (3 * steps);
  318. }
  319. return kbn.toFixed(size, decimals) + extArray[steps];
  320. };
  321. };
  322. kbn.toFixed = function(value, decimals) {
  323. if (value === null) {
  324. return "";
  325. }
  326. var factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
  327. var formatted = String(Math.round(value * factor) / factor);
  328. // if exponent return directly
  329. if (formatted.indexOf('e') !== -1 || value === 0) {
  330. return formatted;
  331. }
  332. // If tickDecimals was specified, ensure that we have exactly that
  333. // much precision; otherwise default to the value's own precision.
  334. if (decimals != null) {
  335. var decimalPos = formatted.indexOf(".");
  336. var precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1;
  337. if (precision < decimals) {
  338. return (precision ? formatted : formatted + ".") + (String(factor)).substr(1, decimals - precision);
  339. }
  340. }
  341. return formatted;
  342. };
  343. kbn.valueFormats.bits = kbn.formatFuncCreator(1024, [' b', ' Kib', ' Mib', ' Gib', ' Tib', ' Pib', ' Eib', ' Zib', ' Yib']);
  344. kbn.valueFormats.bytes = kbn.formatFuncCreator(1024, [' B', ' KiB', ' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']);
  345. kbn.valueFormats.kbytes = kbn.formatFuncCreator(1024, [' KiB', ' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']);
  346. kbn.valueFormats.mbytes = kbn.formatFuncCreator(1024, [' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']);
  347. kbn.valueFormats.gbytes = kbn.formatFuncCreator(1024, [' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']);
  348. kbn.valueFormats.bps = kbn.formatFuncCreator(1000, [' bps', ' Kbps', ' Mbps', ' Gbps', ' Tbps', ' Pbps', ' Ebps', ' Zbps', ' Ybps']);
  349. kbn.valueFormats.pps = kbn.formatFuncCreator(1000, [' pps', ' Kpps', ' Mpps', ' Gpps', ' Tpps', ' Ppps', ' Epps', ' Zpps', ' Ypps']);
  350. kbn.valueFormats.Bps = kbn.formatFuncCreator(1000, [' Bps', ' KBps', ' MBps', ' GBps', ' TBps', ' PBps', ' EBps', ' ZBps', ' YBps']);
  351. kbn.valueFormats.short = kbn.formatFuncCreator(1000, ['', ' K', ' Mil', ' Bil', ' Tri', ' Quadr', ' Quint', ' Sext', ' Sept']);
  352. kbn.valueFormats.joule = kbn.formatFuncCreator(1000, [' J', ' kJ', ' MJ', ' GJ', ' TJ', ' PJ', ' EJ', ' ZJ', ' YJ']);
  353. kbn.valueFormats.amp = kbn.formatFuncCreator(1000, [' A', ' kA', ' MA', ' GA', ' TA', ' PA', ' EA', ' ZA', ' YA']);
  354. kbn.valueFormats.volt = kbn.formatFuncCreator(1000, [' V', ' kV', ' MV', ' GV', ' TV', ' PV', ' EV', ' ZV', ' YV']);
  355. kbn.valueFormats.hertz = kbn.formatFuncCreator(1000, [' Hz', ' kHz', ' MHz', ' GHz', ' THz', ' PHz', ' EHz', ' ZHz', ' YHz']);
  356. kbn.valueFormats.watt = kbn.formatFuncCreator(1000, [' W', ' kW', ' MW', ' GW', ' TW', ' PW', ' EW', ' ZW', ' YW']);
  357. kbn.valueFormats.kwatt = kbn.formatFuncCreator(1000, [' kW', ' MW', ' GW', ' TW', ' PW', ' EW', ' ZW', ' YW']);
  358. kbn.valueFormats.watth = kbn.formatFuncCreator(1000, [' Wh', ' kWh', ' MWh', ' GWh', ' TWh', ' PWh', ' EWh', ' ZWh', ' YWh']);
  359. kbn.valueFormats.kwatth = kbn.formatFuncCreator(1000, [' kWh', ' MWh', ' GWh', ' TWh', ' PWh', ' EWh', ' ZWh', ' YWh']);
  360. kbn.valueFormats.ev = kbn.formatFuncCreator(1000, [' eV', ' keV', ' MeV', 'GeV', 'TeV', 'PeV', 'EeV', 'ZeV', 'YeV']);
  361. kbn.valueFormats.none = kbn.toFixed;
  362. kbn.valueFormats.celsius = function(value, decimals) { return kbn.toFixed(value, decimals) + ' °C'; };
  363. kbn.valueFormats.farenheit = function(value, decimals) { return kbn.toFixed(value, decimals) + ' °F'; };
  364. kbn.valueFormats.humidity = function(value, decimals) { return kbn.toFixed(value, decimals) + ' %H'; };
  365. kbn.valueFormats.pressurembar = function(value, decimals) { return kbn.toFixed(value, decimals) + ' mbar'; };
  366. kbn.valueFormats.pressurehpa = function(value, decimals) { return kbn.toFixed(value, decimals) + ' hPa'; };
  367. kbn.valueFormats.ppm = function(value, decimals) { return kbn.toFixed(value, decimals) + ' ppm'; };
  368. kbn.valueFormats.velocityms = function(value, decimals) { return kbn.toFixed(value, decimals) + ' m/s'; };
  369. kbn.valueFormats.velocitykmh = function(value, decimals) { return kbn.toFixed(value, decimals) + ' km/h'; };
  370. kbn.valueFormats.velocitymph = function(value, decimals) { return kbn.toFixed(value, decimals) + ' mph'; };
  371. kbn.valueFormats.velocityknot = function(value, decimals) { return kbn.toFixed(value, decimals) + ' kn'; };
  372. kbn.roundValue = function (num, decimals) {
  373. if (num === null) { return null; }
  374. var n = Math.pow(10, decimals);
  375. return Math.round((n * num).toFixed(decimals)) / n;
  376. };
  377. kbn.toFixedScaled = function(value, decimals, scaledDecimals, additionalDecimals, ext) {
  378. if (scaledDecimals === null) {
  379. return kbn.toFixed(value, decimals) + ext;
  380. } else {
  381. return kbn.toFixed(value, scaledDecimals + additionalDecimals) + ext;
  382. }
  383. };
  384. kbn.valueFormats.ms = function(size, decimals, scaledDecimals) {
  385. if (size === null) { return ""; }
  386. if (Math.abs(size) < 1000) {
  387. return kbn.toFixed(size, decimals) + " ms";
  388. }
  389. // Less than 1 min
  390. else if (Math.abs(size) < 60000) {
  391. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, " s");
  392. }
  393. // Less than 1 hour, devide in minutes
  394. else if (Math.abs(size) < 3600000) {
  395. return kbn.toFixedScaled(size / 60000, decimals, scaledDecimals, 5, " min");
  396. }
  397. // Less than one day, devide in hours
  398. else if (Math.abs(size) < 86400000) {
  399. return kbn.toFixedScaled(size / 3600000, decimals, scaledDecimals, 7, " hour");
  400. }
  401. // Less than one year, devide in days
  402. else if (Math.abs(size) < 31536000000) {
  403. return kbn.toFixedScaled(size / 86400000, decimals, scaledDecimals, 8, " day");
  404. }
  405. return kbn.toFixedScaled(size / 31536000000, decimals, scaledDecimals, 10, " year");
  406. };
  407. kbn.valueFormats.s = function(size, decimals, scaledDecimals) {
  408. if (size === null) { return ""; }
  409. if (Math.abs(size) < 600) {
  410. return kbn.toFixed(size, decimals) + " s";
  411. }
  412. // Less than 1 hour, devide in minutes
  413. else if (Math.abs(size) < 3600) {
  414. return kbn.toFixedScaled(size / 60, decimals, scaledDecimals, 1, " min");
  415. }
  416. // Less than one day, devide in hours
  417. else if (Math.abs(size) < 86400) {
  418. return kbn.toFixedScaled(size / 3600, decimals, scaledDecimals, 4, " hour");
  419. }
  420. // Less than one week, devide in days
  421. else if (Math.abs(size) < 604800) {
  422. return kbn.toFixedScaled(size / 86400, decimals, scaledDecimals, 5, " day");
  423. }
  424. // Less than one year, devide in week
  425. else if (Math.abs(size) < 31536000) {
  426. return kbn.toFixedScaled(size / 604800, decimals, scaledDecimals, 6, " week");
  427. }
  428. return kbn.toFixedScaled(size / 3.15569e7, decimals, scaledDecimals, 7, " year");
  429. };
  430. kbn.valueFormats['µs'] = function(size, decimals, scaledDecimals) {
  431. if (size === null) { return ""; }
  432. if (Math.abs(size) < 1000) {
  433. return kbn.toFixed(size, decimals) + " µs";
  434. }
  435. else if (Math.abs(size) < 1000000) {
  436. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, " ms");
  437. }
  438. else {
  439. return kbn.toFixedScaled(size / 1000000, decimals, scaledDecimals, 6, " s");
  440. }
  441. };
  442. kbn.valueFormats.ns = function(size, decimals, scaledDecimals) {
  443. if (size === null) { return ""; }
  444. if (Math.abs(size) < 1000) {
  445. return kbn.toFixed(size, decimals) + " ns";
  446. }
  447. else if (Math.abs(size) < 1000000) {
  448. return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, " µs");
  449. }
  450. else if (Math.abs(size) < 1000000000) {
  451. return kbn.toFixedScaled(size / 1000000, decimals, scaledDecimals, 6, " ms");
  452. }
  453. else if (Math.abs(size) < 60000000000){
  454. return kbn.toFixedScaled(size / 1000000000, decimals, scaledDecimals, 9, " s");
  455. }
  456. else {
  457. return kbn.toFixedScaled(size / 60000000000, decimals, scaledDecimals, 12, " min");
  458. }
  459. };
  460. kbn.slugifyForUrl = function(str) {
  461. return str
  462. .toLowerCase()
  463. .replace(/[^\w ]+/g,'')
  464. .replace(/ +/g,'-');
  465. };
  466. kbn.exportSeriesListToCsv = function(seriesList) {
  467. var text = 'Series;Time;Value\n';
  468. _.each(seriesList, function(series) {
  469. _.each(series.datapoints, function(dp) {
  470. text += series.alias + ';' + new Date(dp[1]).toISOString() + ';' + dp[0] + '\n';
  471. });
  472. });
  473. var blob = new Blob([text], { type: "text/csv;charset=utf-8" });
  474. window.saveAs(blob, 'grafana_data_export.csv');
  475. };
  476. kbn.stringToJsRegex = function(str) {
  477. if (str[0] !== '/') {
  478. return new RegExp(str);
  479. }
  480. var match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
  481. return new RegExp(match[1], match[2]);
  482. };
  483. kbn.getUnitFormats = function() {
  484. return [
  485. {
  486. text: 'none',
  487. submenu: [
  488. {text: 'none' , value: 'none'},
  489. {text: 'short', value: 'short'},
  490. {text: 'percent', value: 'percent'},
  491. {text: 'ppm', value: 'ppm'},
  492. {text: 'dB', value: 'dB'},
  493. ]
  494. },
  495. {
  496. text: 'duration',
  497. submenu: [
  498. {text: 'nanoseconds (ns)' , value: 'ns'},
  499. {text: 'microseconds (µs)', value: 'µs'},
  500. {text: 'milliseconds (ms)', value: 'ms'},
  501. {text: 'seconds (s)', value: 's'},
  502. {text: 'Hertz (1/s)', value: 'hertz'},
  503. ]
  504. },
  505. {
  506. text: 'data',
  507. submenu: [
  508. {text: 'bits', value: 'bits'},
  509. {text: 'bytes', value: 'bytes'},
  510. {text: 'kilobytes', value: 'kbytes'},
  511. {text: 'megabytes', value: 'mbytes'},
  512. {text: 'gigabytes', value: 'gbytes'},
  513. ]
  514. },
  515. {
  516. text: 'data rate',
  517. submenu: [
  518. {text: 'packets/sec', value: 'pps'},
  519. {text: 'bits/sec', value: 'bps'},
  520. {text: 'bytes/sec', value: 'Bps'},
  521. ]
  522. },
  523. {
  524. text: 'energy',
  525. submenu: [
  526. {text: 'watt (W)', value: 'watt'},
  527. {text: 'kilowatt (kW)', value: 'kwatt'},
  528. {text: 'watt-hour (Wh)', value: 'watth'},
  529. {text: 'kilowatt-hour (kWh)', value: 'kwatth'},
  530. {text: 'joule (J)', value: 'joule'},
  531. {text: 'electron volt (eV)', value: 'ev'},
  532. {text: 'Ampere (A)', value: 'amp'},
  533. {text: 'Volt (V)', value: 'volt'},
  534. ]
  535. },
  536. {
  537. text: 'weather',
  538. submenu: [
  539. {text: 'Celcius (°C)', value: 'celsius' },
  540. {text: 'Farenheit (°F)', value: 'farenheit'},
  541. {text: 'Humidity (%H)', value: 'humidity' },
  542. {text: 'Pressure (mbar)', value: 'pressurembar' },
  543. {text: 'Pressure (hPa)', value: 'pressurehpa' },
  544. ]
  545. },
  546. {
  547. text: 'velocity',
  548. submenu: [
  549. {text: 'm/s', value: 'velocityms' },
  550. {text: 'km/h', value: 'velocitykmh' },
  551. {text: 'mph', value: 'velocitymph' },
  552. {text: 'knot (kn)', value: 'velocityknot' },
  553. ]
  554. },
  555. ];
  556. };
  557. return kbn;
  558. });