You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

647 lines
17 KiB

  1. (function () {
  2. 'use strict';
  3. function __$styleInject(css, ref) {
  4. if ( ref === void 0 ) ref = {};
  5. var insertAt = ref.insertAt;
  6. if (!css || typeof document === 'undefined') { return; }
  7. var head = document.head || document.getElementsByTagName('head')[0];
  8. var style = document.createElement('style');
  9. style.type = 'text/css';
  10. if (insertAt === 'top') {
  11. if (head.firstChild) {
  12. head.insertBefore(style, head.firstChild);
  13. } else {
  14. head.appendChild(style);
  15. }
  16. } else {
  17. head.appendChild(style);
  18. }
  19. if (style.styleSheet) {
  20. style.styleSheet.cssText = css;
  21. } else {
  22. style.appendChild(document.createTextNode(css));
  23. }
  24. }
  25. // Fixed 5-color theme,
  26. // More colors are difficult to parse visually
  27. var HEATMAP_COLORS_BLUE = ['#ebedf0', '#c0ddf9', '#73b3f3', '#3886e1', '#17459e'];
  28. var HEATMAP_COLORS_YELLOW = ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c'];
  29. // Universal constants
  30. /**
  31. * Returns the value of a number upto 2 decimal places.
  32. * @param {Number} d Any number
  33. */
  34. /**
  35. * Returns whether or not two given arrays are equal.
  36. * @param {Array} arr1 First array
  37. * @param {Array} arr2 Second array
  38. */
  39. /**
  40. * Shuffles array in place. ES6 version
  41. * @param {Array} array An array containing the items.
  42. */
  43. function shuffle(array) {
  44. // Awesomeness: https://bost.ocks.org/mike/shuffle/
  45. // https://stackoverflow.com/a/2450976/6495043
  46. // https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array?noredirect=1&lq=1
  47. for (var i = array.length - 1; i > 0; i--) {
  48. var j = Math.floor(Math.random() * (i + 1));
  49. var _ref = [array[j], array[i]];
  50. array[i] = _ref[0];
  51. array[j] = _ref[1];
  52. }
  53. return array;
  54. }
  55. /**
  56. * Fill an array with extra points
  57. * @param {Array} array Array
  58. * @param {Number} count number of filler elements
  59. * @param {Object} element element to fill with
  60. * @param {Boolean} start fill at start?
  61. */
  62. /**
  63. * Returns pixel width of string.
  64. * @param {String} string
  65. * @param {Number} charWidth Width of single char in pixels
  66. */
  67. // https://stackoverflow.com/a/29325222
  68. function getRandomBias(min, max, bias, influence) {
  69. var range = max - min;
  70. var biasValue = range * bias + min;
  71. var rnd = Math.random() * range + min,
  72. // random in range
  73. mix = Math.random() * influence; // random mixer
  74. return rnd * (1 - mix) + biasValue * mix; // mix full range and bias
  75. }
  76. // Playing around with dates
  77. var NO_OF_MILLIS = 1000;
  78. var SEC_IN_DAY = 86400;
  79. var MONTH_NAMES_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  80. function clone(date) {
  81. return new Date(date.getTime());
  82. }
  83. function timestampSec(date) {
  84. return date.getTime() / NO_OF_MILLIS;
  85. }
  86. function timestampToMidnight(timestamp) {
  87. var roundAhead = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  88. var midnightTs = Math.floor(timestamp - timestamp % SEC_IN_DAY);
  89. if (roundAhead) {
  90. return midnightTs + SEC_IN_DAY;
  91. }
  92. return midnightTs;
  93. }
  94. // export function getMonthsBetween(startDate, endDate) {}
  95. // mutates
  96. // mutates
  97. function addDays(date, numberOfDays) {
  98. date.setDate(date.getDate() + numberOfDays);
  99. }
  100. // Composite Chart
  101. // ================================================================================
  102. var reportCountList = [152, 222, 199, 287, 534, 709, 1179, 1256, 1632, 1856, 1850];
  103. var lineCompositeData = {
  104. labels: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017"],
  105. yMarkers: [{
  106. label: "Average 100 reports/month",
  107. value: 1200
  108. }],
  109. datasets: [{
  110. "name": "Events",
  111. "values": reportCountList
  112. }]
  113. };
  114. var fireball_5_25 = [[4, 0, 3, 1, 1, 2, 1, 1, 1, 0, 1, 1], [2, 3, 3, 2, 1, 3, 0, 1, 2, 7, 10, 4], [5, 6, 2, 4, 0, 1, 4, 3, 0, 2, 0, 1], [0, 2, 6, 2, 1, 1, 2, 3, 6, 3, 7, 8], [6, 8, 7, 7, 4, 5, 6, 5, 22, 12, 10, 11], [7, 10, 11, 7, 3, 2, 7, 7, 11, 15, 22, 20], [13, 16, 21, 18, 19, 17, 12, 17, 31, 28, 25, 29], [24, 14, 21, 14, 11, 15, 19, 21, 41, 22, 32, 18], [31, 20, 30, 22, 14, 17, 21, 35, 27, 50, 117, 24], [32, 24, 21, 27, 11, 27, 43, 37, 44, 40, 48, 32], [31, 38, 36, 26, 23, 23, 25, 29, 26, 47, 61, 50]];
  115. var fireball_2_5 = [[22, 6, 6, 9, 7, 8, 6, 14, 19, 10, 8, 20], [11, 13, 12, 8, 9, 11, 9, 13, 10, 22, 40, 24], [20, 13, 13, 19, 13, 10, 14, 13, 20, 18, 5, 9], [7, 13, 16, 19, 12, 11, 21, 27, 27, 24, 33, 33], [38, 25, 28, 22, 31, 21, 35, 42, 37, 32, 46, 53], [50, 33, 36, 34, 35, 28, 27, 52, 58, 59, 75, 69], [54, 67, 67, 45, 66, 51, 38, 64, 90, 113, 116, 87], [84, 52, 56, 51, 55, 46, 50, 87, 114, 83, 152, 93], [73, 58, 59, 63, 56, 51, 83, 140, 103, 115, 265, 89], [106, 95, 94, 71, 77, 75, 99, 136, 129, 154, 168, 156], [81, 102, 95, 72, 58, 91, 89, 122, 124, 135, 183, 171]];
  116. var fireballOver25 = [
  117. // [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  118. [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0], [1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2], [3, 2, 1, 3, 2, 0, 2, 2, 2, 3, 0, 1], [2, 3, 5, 2, 1, 3, 0, 2, 3, 5, 1, 4], [7, 4, 6, 1, 9, 2, 2, 2, 20, 9, 4, 9], [5, 6, 1, 2, 5, 4, 5, 5, 16, 9, 14, 9], [5, 4, 7, 5, 1, 5, 3, 3, 5, 7, 22, 2], [5, 13, 11, 6, 1, 7, 9, 8, 14, 17, 16, 3], [8, 9, 8, 6, 4, 8, 5, 6, 14, 11, 21, 12]];
  119. var barCompositeData = {
  120. labels: MONTH_NAMES_SHORT,
  121. datasets: [{
  122. name: "Over 25 reports",
  123. values: fireballOver25[9]
  124. }, {
  125. name: "5 to 25 reports",
  126. values: fireball_5_25[9]
  127. }, {
  128. name: "2 to 5 reports",
  129. values: fireball_2_5[9]
  130. }]
  131. };
  132. // Demo Chart multitype Chart
  133. // ================================================================================
  134. var typeData = {
  135. labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm", "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"],
  136. yMarkers: [{
  137. label: "Marker",
  138. value: 43,
  139. options: { labelPos: 'left'
  140. // type: 'dashed'
  141. } }],
  142. yRegions: [{
  143. label: "Region",
  144. start: -10,
  145. end: 50,
  146. options: { labelPos: 'right' }
  147. }],
  148. datasets: [{
  149. name: "Some Data",
  150. values: [18, 40, 30, 35, 8, 52, 17, -4],
  151. axisPosition: 'right',
  152. chartType: 'bar'
  153. }, {
  154. name: "Another Set",
  155. values: [30, 50, -10, 15, 18, 32, 27, 14],
  156. axisPosition: 'right',
  157. chartType: 'bar'
  158. }, {
  159. name: "Yet Another",
  160. values: [15, 20, -3, -15, 58, 12, -17, 37],
  161. chartType: 'line'
  162. }]
  163. };
  164. var trendsData = {
  165. labels: [1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016],
  166. datasets: [{
  167. values: [132.9, 150.0, 149.4, 148.0, 94.4, 97.6, 54.1, 49.2, 22.5, 18.4, 39.3, 131.0, 220.1, 218.9, 198.9, 162.4, 91.0, 60.5, 20.6, 14.8, 33.9, 123.0, 211.1, 191.8, 203.3, 133.0, 76.1, 44.9, 25.1, 11.6, 28.9, 88.3, 136.3, 173.9, 170.4, 163.6, 99.3, 65.3, 45.8, 24.7, 12.6, 4.2, 4.8, 24.9, 80.8, 84.5, 94.0, 113.3, 69.8, 39.8]
  168. }]
  169. };
  170. var moonData = {
  171. names: ["Ganymede", "Callisto", "Io", "Europa"],
  172. masses: [14819000, 10759000, 8931900, 4800000],
  173. distances: [1070.412, 1882.709, 421.700, 671.034],
  174. diameters: [5262.4, 4820.6, 3637.4, 3121.6]
  175. };
  176. // const jupiterMoons = {
  177. // 'Ganymede': {
  178. // mass: '14819000 x 10^16 kg',
  179. // 'semi-major-axis': '1070412 km',
  180. // 'diameter': '5262.4 km'
  181. // },
  182. // 'Callisto': {
  183. // mass: '10759000 x 10^16 kg',
  184. // 'semi-major-axis': '1882709 km',
  185. // 'diameter': '4820.6 km'
  186. // },
  187. // 'Io': {
  188. // mass: '8931900 x 10^16 kg',
  189. // 'semi-major-axis': '421700 km',
  190. // 'diameter': '3637.4 km'
  191. // },
  192. // 'Europa': {
  193. // mass: '4800000 x 10^16 kg',
  194. // 'semi-major-axis': '671034 km',
  195. // 'diameter': '3121.6 km'
  196. // },
  197. // };
  198. // ================================================================================
  199. var today = new Date();
  200. var start = clone(today);
  201. addDays(start, 4);
  202. var end = clone(start);
  203. start.setFullYear(start.getFullYear() - 2);
  204. end.setFullYear(end.getFullYear() - 1);
  205. var dataPoints = {};
  206. var startTs = timestampSec(start);
  207. var endTs = timestampSec(end);
  208. startTs = timestampToMidnight(startTs);
  209. endTs = timestampToMidnight(endTs, true);
  210. while (startTs < endTs) {
  211. dataPoints[parseInt(startTs)] = Math.floor(getRandomBias(0, 5, 0.2, 1));
  212. startTs += SEC_IN_DAY;
  213. }
  214. var heatmapData = {
  215. dataPoints: dataPoints,
  216. start: start,
  217. end: end
  218. };
  219. // ================================================================================
  220. var c1 = document.querySelector("#chart-composite-1");
  221. var c2 = document.querySelector("#chart-composite-2");
  222. var Chart = frappe.Chart; // eslint-disable-line no-undef
  223. var lineCompositeChart = new Chart(c1, {
  224. title: "Fireball/Bolide Events - Yearly (reported)",
  225. data: lineCompositeData,
  226. type: 'line',
  227. height: 190,
  228. colors: ['green'],
  229. isNavigable: 1,
  230. valuesOverPoints: 1,
  231. lineOptions: {
  232. dotSize: 8
  233. }
  234. // yAxisMode: 'tick'
  235. // regionFill: 1
  236. });
  237. var barCompositeChart = new Chart(c2, {
  238. data: barCompositeData,
  239. type: 'bar',
  240. height: 210,
  241. colors: ['violet', 'light-blue', '#46a9f9'],
  242. valuesOverPoints: 1,
  243. axisOptions: {
  244. xAxisMode: 'tick'
  245. },
  246. barOptions: {
  247. stacked: 1
  248. }
  249. });
  250. lineCompositeChart.parent.addEventListener('data-select', function (e) {
  251. var i = e.index;
  252. barCompositeChart.updateDatasets([fireballOver25[i], fireball_5_25[i], fireball_2_5[i]]);
  253. });
  254. // ================================================================================
  255. var customColors = ['purple', 'magenta', 'light-blue'];
  256. var typeChartArgs = {
  257. title: "My Awesome Chart",
  258. data: typeData,
  259. type: 'axis-mixed',
  260. height: 300,
  261. colors: customColors,
  262. maxLegendPoints: 6,
  263. maxSlices: 10,
  264. tooltipOptions: {
  265. formatTooltipX: function formatTooltipX(d) {
  266. return (d + '').toUpperCase();
  267. },
  268. formatTooltipY: function formatTooltipY(d) {
  269. return d + ' pts';
  270. }
  271. }
  272. };
  273. var aggrChart = new Chart("#chart-aggr", typeChartArgs);
  274. Array.prototype.slice.call(document.querySelectorAll('.aggr-type-buttons button')).map(function (el) {
  275. el.addEventListener('click', function (e) {
  276. var btn = e.target;
  277. var type = btn.getAttribute('data-type');
  278. typeChartArgs.type = type;
  279. if (type !== 'axis-mixed') {
  280. typeChartArgs.colors = undefined;
  281. } else {
  282. typeChartArgs.colors = customColors;
  283. }
  284. var newChart = new Chart("#chart-aggr", typeChartArgs);
  285. if (newChart) {
  286. aggrChart = newChart;
  287. }
  288. Array.prototype.slice.call(btn.parentNode.querySelectorAll('button')).map(function (el) {
  289. el.classList.remove('active');
  290. });
  291. btn.classList.add('active');
  292. });
  293. });
  294. document.querySelector('.export-aggr').addEventListener('click', function () {
  295. aggrChart.export();
  296. });
  297. // Update values chart
  298. // ================================================================================
  299. var updateDataAllLabels = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon"];
  300. var getRandom = function getRandom() {
  301. return Math.floor(getRandomBias(-40, 60, 0.8, 1));
  302. };
  303. var updateDataAllValues = Array.from({ length: 30 }, getRandom);
  304. // We're gonna be shuffling this
  305. var updateDataAllIndices = updateDataAllLabels.map(function (d, i) {
  306. return i;
  307. });
  308. var getUpdateData = function getUpdateData(source_array) {
  309. var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
  310. var indices = updateDataAllIndices.slice(0, length);
  311. return indices.map(function (index) {
  312. return source_array[index];
  313. });
  314. };
  315. var updateData = {
  316. labels: getUpdateData(updateDataAllLabels),
  317. datasets: [{
  318. "values": getUpdateData(updateDataAllValues)
  319. }],
  320. yMarkers: [{
  321. label: "Altitude",
  322. value: 25,
  323. type: 'dashed'
  324. }],
  325. yRegions: [{
  326. label: "Range",
  327. start: 10,
  328. end: 45
  329. }]
  330. };
  331. var updateChart = new Chart("#chart-update", {
  332. data: updateData,
  333. type: 'line',
  334. height: 300,
  335. colors: ['#ff6c03'],
  336. lineOptions: {
  337. // hideLine: 1,
  338. regionFill: 1
  339. }
  340. });
  341. var chartUpdateButtons = document.querySelector('.chart-update-buttons');
  342. chartUpdateButtons.querySelector('[data-update="random"]').addEventListener("click", function () {
  343. shuffle(updateDataAllIndices);
  344. var value = getRandom();
  345. var start = getRandom();
  346. var end = getRandom();
  347. var data = {
  348. labels: updateDataAllLabels.slice(0, 10),
  349. datasets: [{ values: getUpdateData(updateDataAllValues) }],
  350. yMarkers: [{
  351. label: "Altitude",
  352. value: value,
  353. type: 'dashed'
  354. }],
  355. yRegions: [{
  356. label: "Range",
  357. start: start,
  358. end: end
  359. }]
  360. };
  361. updateChart.update(data);
  362. });
  363. chartUpdateButtons.querySelector('[data-update="add"]').addEventListener("click", function () {
  364. var index = updateChart.state.datasetLength; // last index to add
  365. if (index >= updateDataAllIndices.length) return;
  366. updateChart.addDataPoint(updateDataAllLabels[index], [updateDataAllValues[index]]);
  367. });
  368. chartUpdateButtons.querySelector('[data-update="remove"]').addEventListener("click", function () {
  369. updateChart.removeDataPoint();
  370. });
  371. document.querySelector('.export-update').addEventListener('click', function () {
  372. updateChart.export();
  373. });
  374. // Trends Chart
  375. // ================================================================================
  376. var plotChartArgs = {
  377. title: "Mean Total Sunspot Count - Yearly",
  378. data: trendsData,
  379. type: 'line',
  380. height: 300,
  381. colors: ['#238e38'],
  382. lineOptions: {
  383. hideDots: 1,
  384. heatline: 1
  385. },
  386. axisOptions: {
  387. xAxisMode: 'tick',
  388. yAxisMode: 'span',
  389. xIsSeries: 1
  390. }
  391. };
  392. var trendsChart = new Chart("#chart-trends", plotChartArgs);
  393. Array.prototype.slice.call(document.querySelectorAll('.chart-plot-buttons button')).map(function (el) {
  394. el.addEventListener('click', function (e) {
  395. var btn = e.target;
  396. var type = btn.getAttribute('data-type');
  397. var config = {};
  398. config[type] = 1;
  399. if (['regionFill', 'heatline'].includes(type)) {
  400. config.hideDots = 1;
  401. }
  402. // plotChartArgs.init = false;
  403. plotChartArgs.lineOptions = config;
  404. new Chart("#chart-trends", plotChartArgs);
  405. Array.prototype.slice.call(btn.parentNode.querySelectorAll('button')).map(function (el) {
  406. el.classList.remove('active');
  407. });
  408. btn.classList.add('active');
  409. });
  410. });
  411. document.querySelector('.export-trends').addEventListener('click', function () {
  412. trendsChart.export();
  413. });
  414. // Event chart
  415. // ================================================================================
  416. var eventsData = {
  417. labels: ["Ganymede", "Callisto", "Io", "Europa"],
  418. datasets: [{
  419. "values": moonData.distances,
  420. "formatted": moonData.distances.map(function (d) {
  421. return d * 1000 + " km";
  422. })
  423. }]
  424. };
  425. var eventsChart = new Chart("#chart-events", {
  426. title: "Jupiter's Moons: Semi-major Axis (1000 km)",
  427. data: eventsData,
  428. type: 'bar',
  429. height: 330,
  430. colors: ['grey'],
  431. isNavigable: 1
  432. });
  433. var dataDiv = document.querySelector('.chart-events-data');
  434. eventsChart.parent.addEventListener('data-select', function (e) {
  435. var name = moonData.names[e.index];
  436. dataDiv.querySelector('.moon-name').innerHTML = name;
  437. dataDiv.querySelector('.semi-major-axis').innerHTML = moonData.distances[e.index] * 1000;
  438. dataDiv.querySelector('.mass').innerHTML = moonData.masses[e.index];
  439. dataDiv.querySelector('.diameter').innerHTML = moonData.diameters[e.index];
  440. dataDiv.querySelector('img').src = "./assets/img/" + name.toLowerCase() + ".jpg";
  441. });
  442. // Heatmap
  443. // ================================================================================
  444. var heatmapArgs = {
  445. title: "Monthly Distribution",
  446. data: heatmapData,
  447. type: 'heatmap',
  448. discreteDomains: 1,
  449. countLabel: 'Level',
  450. colors: HEATMAP_COLORS_BLUE,
  451. legendScale: [0, 1, 2, 4, 5]
  452. };
  453. var heatmapChart = new Chart("#chart-heatmap", heatmapArgs);
  454. Array.prototype.slice.call(document.querySelectorAll('.heatmap-mode-buttons button')).map(function (el) {
  455. el.addEventListener('click', function (e) {
  456. var btn = e.target;
  457. var mode = btn.getAttribute('data-mode');
  458. var discreteDomains = 0;
  459. if (mode === 'discrete') {
  460. discreteDomains = 1;
  461. }
  462. var colors = [];
  463. var colors_mode = document.querySelector('.heatmap-color-buttons .active').getAttribute('data-color');
  464. if (colors_mode === 'halloween') {
  465. colors = HEATMAP_COLORS_YELLOW;
  466. } else if (colors_mode === 'blue') {
  467. colors = HEATMAP_COLORS_BLUE;
  468. }
  469. heatmapArgs.discreteDomains = discreteDomains;
  470. heatmapArgs.colors = colors;
  471. new Chart("#chart-heatmap", heatmapArgs);
  472. Array.prototype.slice.call(btn.parentNode.querySelectorAll('button')).map(function (el) {
  473. el.classList.remove('active');
  474. });
  475. btn.classList.add('active');
  476. });
  477. });
  478. Array.prototype.slice.call(document.querySelectorAll('.heatmap-color-buttons button')).map(function (el) {
  479. el.addEventListener('click', function (e) {
  480. var btn = e.target;
  481. var colors_mode = btn.getAttribute('data-color');
  482. var colors = [];
  483. if (colors_mode === 'halloween') {
  484. colors = HEATMAP_COLORS_YELLOW;
  485. } else if (colors_mode === 'blue') {
  486. colors = HEATMAP_COLORS_BLUE;
  487. }
  488. var discreteDomains = 1;
  489. var view_mode = document.querySelector('.heatmap-mode-buttons .active').getAttribute('data-mode');
  490. if (view_mode === 'continuous') {
  491. discreteDomains = 0;
  492. }
  493. heatmapArgs.discreteDomains = discreteDomains;
  494. heatmapArgs.colors = colors;
  495. new Chart("#chart-heatmap", heatmapArgs);
  496. Array.prototype.slice.call(btn.parentNode.querySelectorAll('button')).map(function (el) {
  497. el.classList.remove('active');
  498. });
  499. btn.classList.add('active');
  500. });
  501. });
  502. document.querySelector('.export-heatmap').addEventListener('click', function () {
  503. heatmapChart.export();
  504. });
  505. }());
  506. //# sourceMappingURL=index.min.js.map