Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

1226 řádky
37 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. var asyncGenerator = function () {
  26. function AwaitValue(value) {
  27. this.value = value;
  28. }
  29. function AsyncGenerator(gen) {
  30. var front, back;
  31. function send(key, arg) {
  32. return new Promise(function (resolve, reject) {
  33. var request = {
  34. key: key,
  35. arg: arg,
  36. resolve: resolve,
  37. reject: reject,
  38. next: null
  39. };
  40. if (back) {
  41. back = back.next = request;
  42. } else {
  43. front = back = request;
  44. resume(key, arg);
  45. }
  46. });
  47. }
  48. function resume(key, arg) {
  49. try {
  50. var result = gen[key](arg);
  51. var value = result.value;
  52. if (value instanceof AwaitValue) {
  53. Promise.resolve(value.value).then(function (arg) {
  54. resume("next", arg);
  55. }, function (arg) {
  56. resume("throw", arg);
  57. });
  58. } else {
  59. settle(result.done ? "return" : "normal", result.value);
  60. }
  61. } catch (err) {
  62. settle("throw", err);
  63. }
  64. }
  65. function settle(type, value) {
  66. switch (type) {
  67. case "return":
  68. front.resolve({
  69. value: value,
  70. done: true
  71. });
  72. break;
  73. case "throw":
  74. front.reject(value);
  75. break;
  76. default:
  77. front.resolve({
  78. value: value,
  79. done: false
  80. });
  81. break;
  82. }
  83. front = front.next;
  84. if (front) {
  85. resume(front.key, front.arg);
  86. } else {
  87. back = null;
  88. }
  89. }
  90. this._invoke = send;
  91. if (typeof gen.return !== "function") {
  92. this.return = undefined;
  93. }
  94. }
  95. if (typeof Symbol === "function" && Symbol.asyncIterator) {
  96. AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
  97. return this;
  98. };
  99. }
  100. AsyncGenerator.prototype.next = function (arg) {
  101. return this._invoke("next", arg);
  102. };
  103. AsyncGenerator.prototype.throw = function (arg) {
  104. return this._invoke("throw", arg);
  105. };
  106. AsyncGenerator.prototype.return = function (arg) {
  107. return this._invoke("return", arg);
  108. };
  109. return {
  110. wrap: function (fn) {
  111. return function () {
  112. return new AsyncGenerator(fn.apply(this, arguments));
  113. };
  114. },
  115. await: function (value) {
  116. return new AwaitValue(value);
  117. }
  118. };
  119. }();
  120. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  121. function $(expr, con) {
  122. return typeof expr === "string" ? (con || document).querySelector(expr) : expr || null;
  123. }
  124. $.create = function (tag, o) {
  125. var element = document.createElement(tag);
  126. for (var i in o) {
  127. var val = o[i];
  128. if (i === "inside") {
  129. $(val).appendChild(element);
  130. } else if (i === "around") {
  131. var ref = $(val);
  132. ref.parentNode.insertBefore(element, ref);
  133. element.appendChild(ref);
  134. } else if (i === "onClick") {
  135. element.addEventListener('click', val);
  136. } else if (i === "styles") {
  137. if ((typeof val === "undefined" ? "undefined" : _typeof(val)) === "object") {
  138. Object.keys(val).map(function (prop) {
  139. element.style[prop] = val[prop];
  140. });
  141. }
  142. } else if (i in element) {
  143. element[i] = val;
  144. } else {
  145. element.setAttribute(i, val);
  146. }
  147. }
  148. return element;
  149. };
  150. // https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
  151. function insertAfter(newNode, referenceNode) {
  152. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  153. }
  154. // Playing around with dates
  155. var NO_OF_MILLIS = 1000;
  156. var SEC_IN_DAY = 86400;
  157. var MONTH_NAMES_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  158. // https://stackoverflow.com/a/11252167/6495043
  159. function clone(date) {
  160. return new Date(date.getTime());
  161. }
  162. function timestampSec(date) {
  163. return date.getTime() / NO_OF_MILLIS;
  164. }
  165. function timestampToMidnight(timestamp) {
  166. var roundAhead = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  167. var midnightTs = Math.floor(timestamp - timestamp % SEC_IN_DAY);
  168. if (roundAhead) {
  169. return midnightTs + SEC_IN_DAY;
  170. }
  171. return midnightTs;
  172. }
  173. // export function getMonthsBetween(startDate, endDate) {}
  174. // mutates
  175. // mutates
  176. function addDays(date, numberOfDays) {
  177. date.setDate(date.getDate() + numberOfDays);
  178. }
  179. // Fixed 5-color theme,
  180. // More colors are difficult to parse visually
  181. var HEATMAP_COLORS_BLUE = ['#ebedf0', '#c0ddf9', '#73b3f3', '#3886e1', '#17459e'];
  182. var HEATMAP_COLORS_YELLOW = ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c'];
  183. // Universal constants
  184. /**
  185. * Returns whether or not two given arrays are equal.
  186. * @param {Array} arr1 First array
  187. * @param {Array} arr2 Second array
  188. */
  189. /**
  190. * Shuffles array in place. ES6 version
  191. * @param {Array} array An array containing the items.
  192. */
  193. function shuffle(array) {
  194. // Awesomeness: https://bost.ocks.org/mike/shuffle/
  195. // https://stackoverflow.com/a/2450976/6495043
  196. // https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array?noredirect=1&lq=1
  197. for (var i = array.length - 1; i > 0; i--) {
  198. var j = Math.floor(Math.random() * (i + 1));
  199. var _ref = [array[j], array[i]];
  200. array[i] = _ref[0];
  201. array[j] = _ref[1];
  202. }
  203. return array;
  204. }
  205. /**
  206. * Fill an array with extra points
  207. * @param {Array} array Array
  208. * @param {Number} count number of filler elements
  209. * @param {Object} element element to fill with
  210. * @param {Boolean} start fill at start?
  211. */
  212. /**
  213. * Returns pixel width of string.
  214. * @param {String} string
  215. * @param {Number} charWidth Width of single char in pixels
  216. */
  217. // https://stackoverflow.com/a/29325222
  218. function getRandomBias(min, max, bias, influence) {
  219. var range = max - min;
  220. var biasValue = range * bias + min;
  221. var rnd = Math.random() * range + min,
  222. // random in range
  223. mix = Math.random() * influence; // random mixer
  224. return rnd * (1 - mix) + biasValue * mix; // mix full range and bias
  225. }
  226. function toTitleCase(str) {
  227. return str.replace(/\w*/g, function (txt) {
  228. return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  229. });
  230. }
  231. var reportCountList = [152, 222, 199, 287, 534, 709, 1179, 1256, 1632, 1856, 1850];
  232. var lineCompositeData = {
  233. labels: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017"],
  234. yMarkers: [{
  235. label: "Average 100 reports/month",
  236. value: 1200,
  237. options: { labelPos: 'left' }
  238. }],
  239. datasets: [{
  240. "name": "Events",
  241. "values": reportCountList
  242. }]
  243. };
  244. 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]];
  245. 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]];
  246. var fireballOver25 = [
  247. // [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  248. [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]];
  249. var barCompositeData = {
  250. labels: MONTH_NAMES_SHORT,
  251. datasets: [{
  252. name: "Over 25 reports",
  253. values: fireballOver25[9]
  254. }, {
  255. name: "5 to 25 reports",
  256. values: fireball_5_25[9]
  257. }, {
  258. name: "2 to 5 reports",
  259. values: fireball_2_5[9]
  260. }]
  261. };
  262. // Demo Chart multitype Chart
  263. // ================================================================================
  264. var typeData = {
  265. labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm", "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"],
  266. yMarkers: [{
  267. label: "Marker",
  268. value: 43,
  269. options: { labelPos: 'left'
  270. // type: 'dashed'
  271. } }],
  272. yRegions: [{
  273. label: "Region",
  274. start: -10,
  275. end: 50,
  276. options: { labelPos: 'right' }
  277. }],
  278. datasets: [{
  279. name: "Some Data",
  280. values: [18, 40, 30, 35, 8, 52, 17, -4],
  281. axisPosition: 'right',
  282. chartType: 'bar'
  283. }, {
  284. name: "Another Set",
  285. values: [30, 50, -10, 15, 18, 32, 27, 14],
  286. axisPosition: 'right',
  287. chartType: 'bar'
  288. }, {
  289. name: "Yet Another",
  290. values: [15, 20, -3, -15, 58, 12, -17, 37],
  291. chartType: 'line'
  292. }]
  293. };
  294. 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"];
  295. var baseLength = 10;
  296. var fullLength = 30;
  297. var getRandom = function getRandom() {
  298. return Math.floor(getRandomBias(-40, 60, 0.8, 1));
  299. };
  300. var updateDataAllValues = Array.from({ length: fullLength }, getRandom);
  301. // We're gonna be shuffling this
  302. var updateDataAllIndices = updateDataAllLabels.map(function (d, i) {
  303. return i;
  304. });
  305. var getUpdateArray = function getUpdateArray(sourceArray) {
  306. var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
  307. var indices = updateDataAllIndices.slice(0, length);
  308. return indices.map(function (index) {
  309. return sourceArray[index];
  310. });
  311. };
  312. var currentLastIndex = baseLength;
  313. function getUpdateData() {
  314. shuffle(updateDataAllIndices);
  315. var value = getRandom();
  316. var start = getRandom();
  317. var end = getRandom();
  318. currentLastIndex = baseLength;
  319. return {
  320. labels: updateDataAllLabels.slice(0, baseLength),
  321. datasets: [{
  322. values: getUpdateArray(updateDataAllValues)
  323. }],
  324. yMarkers: [{
  325. label: "Altitude",
  326. value: value,
  327. type: 'dashed'
  328. }],
  329. yRegions: [{
  330. label: "Range",
  331. start: start,
  332. end: end
  333. }]
  334. };
  335. }
  336. function getAddUpdateData() {
  337. if (currentLastIndex >= fullLength) return;
  338. // TODO: Fix update on removal
  339. currentLastIndex++;
  340. var c = currentLastIndex - 1;
  341. return [updateDataAllLabels[c], [updateDataAllValues[c]]];
  342. // updateChart.addDataPoint(
  343. // updateDataAllLabels[index], [updateDataAllValues[index]]
  344. // );
  345. }
  346. var trendsData = {
  347. 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],
  348. datasets: [{
  349. 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]
  350. }]
  351. };
  352. var moonData = {
  353. names: ["Ganymede", "Callisto", "Io", "Europa"],
  354. masses: [14819000, 10759000, 8931900, 4800000],
  355. distances: [1070.412, 1882.709, 421.700, 671.034],
  356. diameters: [5262.4, 4820.6, 3637.4, 3121.6]
  357. };
  358. var eventsData = {
  359. labels: ["Ganymede", "Callisto", "Io", "Europa"],
  360. datasets: [{
  361. "values": moonData.distances,
  362. "formatted": moonData.distances.map(function (d) {
  363. return d * 1000 + " km";
  364. })
  365. }]
  366. };
  367. // const jupiterMoons = {
  368. // 'Ganymede': {
  369. // mass: '14819000 x 10^16 kg',
  370. // 'semi-major-axis': '1070412 km',
  371. // 'diameter': '5262.4 km'
  372. // },
  373. // 'Callisto': {
  374. // mass: '10759000 x 10^16 kg',
  375. // 'semi-major-axis': '1882709 km',
  376. // 'diameter': '4820.6 km'
  377. // },
  378. // 'Io': {
  379. // mass: '8931900 x 10^16 kg',
  380. // 'semi-major-axis': '421700 km',
  381. // 'diameter': '3637.4 km'
  382. // },
  383. // 'Europa': {
  384. // mass: '4800000 x 10^16 kg',
  385. // 'semi-major-axis': '671034 km',
  386. // 'diameter': '3121.6 km'
  387. // },
  388. // };
  389. // ================================================================================
  390. var today = new Date();
  391. var start = clone(today);
  392. addDays(start, 4);
  393. var end = clone(start);
  394. start.setFullYear(start.getFullYear() - 2);
  395. end.setFullYear(end.getFullYear() - 1);
  396. var dataPoints = {};
  397. var startTs = timestampSec(start);
  398. var endTs = timestampSec(end);
  399. startTs = timestampToMidnight(startTs);
  400. endTs = timestampToMidnight(endTs, true);
  401. while (startTs < endTs) {
  402. dataPoints[parseInt(startTs)] = Math.floor(getRandomBias(0, 5, 0.2, 1));
  403. startTs += SEC_IN_DAY;
  404. }
  405. var heatmapData = {
  406. dataPoints: dataPoints,
  407. start: start,
  408. end: end
  409. };
  410. var sampleData = {
  411. 0: {
  412. labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  413. datasets: [{ values: [18, 40, 30, 35, 8, 52, 17, -4] }]
  414. },
  415. 1: {
  416. labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  417. datasets: [{ name: "Dataset 1", values: [18, 40, 30, 35, 8, 52, 17, -4] }, { name: "Dataset 2", values: [30, 50, -10, 15, 18, 32, 27, 14] }]
  418. },
  419. 2: {
  420. labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon"],
  421. datasets: [{ values: [300, 250, 720, 560, 370, 610, 690, 410, 370, 480, 620, 260, 170, 510, 630, 710] }]
  422. },
  423. 3: {
  424. labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  425. datasets: [{ values: [300, 250, 720, 560, 370, 610, 690, 410, 370, 480, 620, 260, 170, 510, 630, 710, 560, 370, 610, 260, 170] }]
  426. }
  427. };
  428. var lineComposite = {
  429. config: {
  430. title: "Fireball/Bolide Events - Yearly (reported)",
  431. data: lineCompositeData,
  432. type: "line",
  433. height: 190,
  434. colors: ["green"],
  435. isNavigable: 1,
  436. valuesOverPoints: 1,
  437. lineOptions: {
  438. dotSize: 8
  439. }
  440. }
  441. };
  442. var barComposite = {
  443. config: {
  444. data: barCompositeData,
  445. type: "bar",
  446. height: 210,
  447. colors: ["violet", "light-blue", "#46a9f9"],
  448. valuesOverPoints: 1,
  449. axisOptions: {
  450. xAxisMode: "tick"
  451. },
  452. barOptions: {
  453. stacked: 1
  454. }
  455. }
  456. };
  457. var demoSections = [{
  458. title: "Create a Chart",
  459. name: "demo-main",
  460. contentBlocks: [{
  461. type: "code",
  462. lang: "html",
  463. content: ' &lt!--HTML--&gt;\n &lt;figure id="frost-chart"&gt;&lt;/figure&gt;'
  464. }, {
  465. type: "code",
  466. lang: "javascript",
  467. content: ' // Javascript\n let chart = new frappe.Chart( "#frost-chart", { // or DOM element\n data: {\n labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm",\n "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"],\n\n datasets: [\n {\n name: "Some Data", chartType: \'bar\',\n values: [25, 40, 30, 35, 8, 52, 17, -4]\n },\n {\n name: "Another Set", chartType: \'bar\',\n values: [25, 50, -10, 15, 18, 32, 27, 14]\n },\n {\n name: "Yet Another", chartType: \'line\',\n values: [15, 20, -3, -15, 58, 12, -17, 37]\n }\n ],\n\n yMarkers: [{ label: "Marker", value: 70,\n options: { labelPos: \'left\' }}],\n yRegions: [{ label: "Region", start: -10, end: 50,\n options: { labelPos: \'right\' }}]\n },\n\n title: "My Awesome Chart",\n type: \'axis-mixed\', // or \'bar\', \'line\', \'pie\', \'percentage\'\n height: 300,\n colors: [\'purple\', \'#ffa3ef\', \'light-blue\'],\n\n tooltipOptions: {\n formatTooltipX: d => (d + \'\').toUpperCase(),\n formatTooltipY: d => d + \' pts\',\n }\n });\n\n chart.export();'
  468. }, {
  469. type: "demo",
  470. config: {
  471. title: "My Awesome Chart",
  472. data: typeData,
  473. type: "axis-mixed",
  474. height: 300,
  475. colors: ["purple", "magenta", "light-blue"],
  476. maxSlices: 10,
  477. tooltipOptions: {
  478. formatTooltipX: function formatTooltipX(d) {
  479. return (d + '').toUpperCase();
  480. },
  481. formatTooltipY: function formatTooltipY(d) {
  482. return d + ' pts';
  483. }
  484. }
  485. },
  486. options: [{
  487. name: "type",
  488. path: ["type"],
  489. type: "string",
  490. states: {
  491. "Mixed": 'axis-mixed',
  492. "Line": 'line',
  493. "Bar": 'bar',
  494. "Pie Chart": 'pie',
  495. "Percentage Chart": 'percentage'
  496. },
  497. activeState: "Mixed"
  498. }],
  499. actions: [{ name: "Export ...", fn: "export", args: [] }]
  500. }]
  501. }, {
  502. title: "Update Values",
  503. name: "updates-chart",
  504. contentBlocks: [{
  505. type: "demo",
  506. config: {
  507. data: getUpdateData(),
  508. type: 'line',
  509. height: 300,
  510. colors: ['#ff6c03'],
  511. lineOptions: {
  512. regionFill: 1
  513. }
  514. },
  515. actions: [{
  516. name: "Random Data",
  517. fn: "update",
  518. args: [getUpdateData()]
  519. }, {
  520. name: "Add Value",
  521. fn: "addDataPoint",
  522. args: getAddUpdateData()
  523. }, {
  524. name: "Remove Value",
  525. fn: "removeDataPoint",
  526. args: []
  527. }, {
  528. name: "Export ...",
  529. fn: "export",
  530. args: []
  531. }]
  532. }]
  533. }, {
  534. title: "Plot Trends",
  535. name: "trends-plot",
  536. contentBlocks: [{
  537. type: "demo",
  538. config: {
  539. title: "Mean Total Sunspot Count - Yearly",
  540. data: trendsData,
  541. type: 'line',
  542. height: 300,
  543. colors: ['#238e38'],
  544. axisOptions: {
  545. xAxisMode: 'tick',
  546. yAxisMode: 'span',
  547. xIsSeries: 1
  548. }
  549. },
  550. options: [{
  551. name: "lineOptions",
  552. path: ["lineOptions"],
  553. type: "map",
  554. mapKeys: ['hideLine', 'hideDots', 'heatline', 'regionFill'],
  555. states: {
  556. "Line": [0, 1, 0, 0],
  557. "Dots": [1, 0, 0, 0],
  558. "HeatLine": [0, 1, 1, 0],
  559. "Region": [0, 1, 0, 1]
  560. },
  561. activeState: "HeatLine"
  562. }],
  563. actions: [{ name: "Export ...", fn: "export", args: [] }]
  564. }]
  565. }, {
  566. title: "Listen to state change",
  567. name: "state-change",
  568. contentBlocks: [{
  569. type: "demo",
  570. config: {
  571. title: "Jupiter's Moons: Semi-major Axis (1000 km)",
  572. data: eventsData,
  573. type: 'bar',
  574. height: 330,
  575. colors: ['grey'],
  576. isNavigable: 1
  577. },
  578. sideContent: '<div class="image-container border">\n <img class="moon-image" src="./assets/img/europa.jpg">\n </div>\n <div class="content-data mt1">\n <h6 class="moon-name">Europa</h6>\n <p>Semi-major-axis: <span class="semi-major-axis">671034</span> km</p>\n <p>Mass: <span class="mass">4800000</span> x 10^16 kg</p>\n <p>Diameter: <span class="diameter">3121.6</span> km</p>\n </div>',
  579. postSetup: function postSetup(chart, figure, row) {
  580. chart.parent.addEventListener('data-select', function (e) {
  581. var i = e.index;
  582. var name = moonData.names[i];
  583. row.querySelector('.moon-name').innerHTML = name;
  584. row.querySelector('.semi-major-axis').innerHTML = moonData.distances[i] * 1000;
  585. row.querySelector('.mass').innerHTML = moonData.masses[i];
  586. row.querySelector('.diameter').innerHTML = moonData.diameters[i];
  587. row.querySelector('img').src = "./assets/img/" + name.toLowerCase() + ".jpg";
  588. });
  589. }
  590. }, {
  591. type: "code",
  592. lang: "javascript",
  593. content: ' ...\n isNavigable: 1, // Navigate across data points; default 0\n ...\n\n chart.parent.addEventListener(\'data-select\', (e) => {\n update_moon_data(e.index); // e contains index and value of current datapoint\n });'
  594. }]
  595. }, {
  596. title: "And a Month-wise Heatmap",
  597. name: "heatmap",
  598. contentBlocks: [{
  599. type: "demo",
  600. config: {
  601. title: "Monthly Distribution",
  602. data: heatmapData,
  603. type: 'heatmap',
  604. discreteDomains: 1,
  605. countLabel: 'Level',
  606. colors: HEATMAP_COLORS_BLUE,
  607. legendScale: [0, 1, 2, 4, 5]
  608. },
  609. options: [{
  610. name: "Discrete domains",
  611. path: ["discreteDomains"],
  612. type: 'boolean',
  613. // boolNames: ["Continuous", "Discrete"],
  614. states: { "Discrete": 1, "Continuous": 0 }
  615. }, {
  616. name: "Colors",
  617. path: ["colors"],
  618. type: "object",
  619. states: {
  620. "Green (Default)": [],
  621. "Blue": HEATMAP_COLORS_BLUE,
  622. "GitHub's Halloween": HEATMAP_COLORS_YELLOW
  623. }
  624. }],
  625. actions: [{ name: "Export ...", fn: "export", args: [] }]
  626. }, {
  627. type: "code",
  628. lang: "javascript",
  629. content: ' let heatmap = new frappe.Chart("#heatmap", {\n type: \'heatmap\',\n title: "Monthly Distribution",\n data: {\n dataPoints: {\'1524064033\': 8, /* ... */},\n // object with timestamp-value pairs\n start: startDate\n end: endDate // Date objects\n },\n countLabel: \'Level\',\n discreteDomains: 0 // default: 1\n colors: [\'#ebedf0\', \'#c0ddf9\', \'#73b3f3\', \'#3886e1\', \'#17459e\'],\n // Set of five incremental colors,\n // preferably with a low-saturation color for zero data;\n // def: [\'#ebedf0\', \'#c6e48b\', \'#7bc96f\', \'#239a3b\', \'#196127\']\n });'
  630. }]
  631. }, {
  632. title: "Demo",
  633. name: "codepen",
  634. contentBlocks: [{
  635. type: "custom",
  636. html: '<p data-height="299" data-theme-id="light" data-slug-hash="wjKBoq" data-default-tab="js,result"\n data-user="pratu16x7" data-embed-version="2" data-pen-title="Frappe Charts Demo" class="codepen">\n See the Pen <a href="https://codepen.io/pratu16x7/pen/wjKBoq/">Frappe Charts Demo</a>\n by Prateeksha Singh (<a href="https://codepen.io/pratu16x7">@pratu16x7</a>) on\n <a href="https://codepen.io">CodePen</a>.\n </p>'
  637. }]
  638. }, {
  639. title: "Available Options",
  640. name: "options",
  641. contentBlocks: [{
  642. type: "code",
  643. lang: "javascript",
  644. content: '\n ...\n {\n data: {\n labels: [],\n datasets: [],\n yRegions: [],\n yMarkers: []\n }\n title: \'\',\n colors: [],\n height: 200,\n\n tooltipOptions: {\n formatTooltipX: d => (d + \'\').toUpperCase(),\n formatTooltipY: d => d + \' pts\',\n }\n\n // Axis charts\n isNavigable: 1, // default: 0\n valuesOverPoints: 1, // default: 0\n barOptions: {\n spaceRatio: 1 // default: 0.5\n stacked: 1 // default: 0\n }\n\n lineOptions: {\n dotSize: 6, // default: 4\n hideLine: 0, // default: 0\n hideDots: 1, // default: 0\n heatline: 1, // default: 0\n regionFill: 1 // default: 0\n }\n\n axisOptions: {\n yAxisMode: \'span\', // Axis lines, default\n xAxisMode: \'tick\', // No axis lines, only short ticks\n xIsSeries: 1 // Allow skipping x values for space\n // default: 0\n },\n\n // Pie/Percentage charts\n maxLegendPoints: 6, // default: 20\n maxSlices: 10, // default: 20\n\n // Percentage chart\n barOptions: {\n height: 15 // default: 20\n depth: 5 // default: 2\n }\n\n // Heatmap\n discreteDomains: 1, // default: 1\n }\n ...\n\n // Updating values\n chart.update(data);\n\n // Axis charts:\n chart.addDataPoint(label, valueFromEachDataset, index)\n chart.removeDataPoint(index)\n chart.updateDataset(datasetValues, index)\n\n // Exporting\n chart.export();\n\n // Unbind window-resize events\n chart.unbindWindowEvents();\n\n '
  645. }]
  646. }, {
  647. title: "Install",
  648. name: "installation",
  649. contentBlocks: [{ type: "text", content: 'Install via npm' }, { type: "code", lang: "console", content: ' npm install frappe-charts' }, { type: "text", content: 'And include it in your project' }, { type: "code", lang: "javascript", content: ' import { Chart } from "frappe-charts' }, { type: "text", content: 'Use as:' }, {
  650. type: "code",
  651. lang: "javascript",
  652. content: ' new Chart(); // ES6 module\n // or\n new frappe.Chart(); // Browser'
  653. }, { type: "text", content: '... or include it directly in your HTML' }, {
  654. type: "code",
  655. lang: "html",
  656. content: ' &lt;script src="https://unpkg.com/frappe-charts@1.1.0"&gt;&lt;/script&gt;'
  657. }]
  658. }];
  659. var docSections = [{
  660. name: "start",
  661. contentBlocks: [
  662. // Intro
  663. {
  664. type: "text",
  665. content: "A chart is generally a 2D rendition of data. For example,\n\t\t\t\t\tfor a set of values across items, the data could look like:"
  666. }, {
  667. type: "code",
  668. content: " data = {\n labels: [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"],\n datasets: [\n\t { values: [18, 40, 30, 35, 8, 52, 17, -4] }\n ]\n }"
  669. },
  670. // type: 'bar'
  671. {
  672. type: "text",
  673. content: "Plug that in with a type <b>bar</b>, a color and height:"
  674. }, {
  675. type: "code",
  676. content: " new frappe.Chart( \"#chart\", {\n data: data,\n type: 'bar',\n height: 140,\n colors: ['red']\n });"
  677. }, {
  678. type: "demo",
  679. config: {
  680. data: sampleData[0],
  681. type: 'bar',
  682. height: 140,
  683. colors: ['red']
  684. }
  685. },
  686. // type: 'line'
  687. {
  688. type: "text",
  689. content: "And similarly, a <b>line</b> chart:"
  690. }, {
  691. type: "code",
  692. content: " ...\n type: 'line',\n ..."
  693. }, {
  694. type: "demo",
  695. config: {
  696. data: sampleData[0],
  697. type: 'line',
  698. height: 140,
  699. colors: ['red']
  700. }
  701. },
  702. // Axes lines:
  703. {
  704. type: "text",
  705. content: "Axes lines are configurable. By default they are long\n\t\t\t\t\t<b>span</b>ning lines, but can also be short <b>tick</b>s:"
  706. }, {
  707. type: "code",
  708. content: " ...\n axisOptions: {\n xAxisMode: 'tick' // default: 'span'\n },\n ..."
  709. }, {
  710. type: "demo",
  711. config: {
  712. data: sampleData[2],
  713. type: 'bar',
  714. height: 140,
  715. colors: ['blue'],
  716. axisOptions: {
  717. xAxisMode: "tick"
  718. }
  719. }
  720. },
  721. // Bar width:
  722. {
  723. type: "text",
  724. content: "The bar <b>width</b> can be set by defining the <b>ratio of the space</b>\n\t\t\t\t\tbetween bars to the bar width."
  725. }, {
  726. type: "code",
  727. content: " ...\n barOptions: {\n spaceRatio: 0.2 // default: 1\n },\n ..."
  728. }, {
  729. type: "demo",
  730. config: {
  731. data: sampleData[3],
  732. type: 'bar',
  733. height: 140,
  734. colors: ['orange'],
  735. axisOptions: {
  736. xAxisMode: "tick"
  737. },
  738. barOptions: {
  739. spaceRatio: 0.2
  740. }
  741. },
  742. options: [{
  743. name: "barOptions",
  744. path: ["barOptions"],
  745. type: "map",
  746. mapKeys: ['spaceRatio'],
  747. states: {
  748. "0.2": [0.2],
  749. "0.5": [0.5],
  750. "1": [1],
  751. "1.5": [1.5]
  752. },
  753. activeState: "0.2"
  754. }]
  755. },
  756. // Dot radius:
  757. {
  758. type: "text",
  759. content: 'So can the <b>dot size</b> on a line graph, with the `dotSize` property in `lineOptions`.'
  760. }, {
  761. type: "code",
  762. content: " ...\n lineOptions: {\n dotRadius: 8 // default: 4\n },\n ..."
  763. }, {
  764. type: "demo",
  765. config: {
  766. data: sampleData[2],
  767. type: 'line',
  768. height: 140,
  769. colors: ['orange'],
  770. axisOptions: {
  771. xAxisMode: "tick"
  772. },
  773. lineOptions: {
  774. dotSize: 8
  775. }
  776. },
  777. options: [{
  778. name: "lineOptions",
  779. path: ["lineOptions"],
  780. type: "map",
  781. mapKeys: ['dotSize'],
  782. states: {
  783. "3": [3],
  784. "4": [4],
  785. "8": [8],
  786. "10": [10]
  787. },
  788. activeState: "8"
  789. }]
  790. }]
  791. }, {
  792. title: "Trends and region charts",
  793. name: "trends-and-region",
  794. contentBlocks: [{
  795. type: "text",
  796. content: 'lineOptions` have a bunch of other properties too. Region charts are'
  797. }, {
  798. type: "code",
  799. content: " ...\n data: {\n labels: [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"],\n datasets: [\n { name: \"Dataset 1\", values: [18, 40, 30, 35, 8, 52, 17, -4] },\n { name: \"Dataset 2\", values: [30, 50, -10, 15, 18, 32, 27, 14] }\n ]\n },\n ..."
  800. }, {
  801. type: "demo",
  802. config: {
  803. data: trendsData,
  804. type: 'line',
  805. height: 180,
  806. colors: ['violet'],
  807. axisOptions: {
  808. xAxisMode: 'tick',
  809. yAxisMode: 'span',
  810. xIsSeries: 1
  811. }
  812. },
  813. options: [{
  814. name: "lineOptions",
  815. path: ["lineOptions"],
  816. type: "map",
  817. mapKeys: ['hideLine', 'hideDots', 'heatline', 'regionFill'],
  818. states: {
  819. "Line": [0, 1, 0, 0],
  820. "Dots": [1, 0, 0, 0],
  821. "HeatLine": [0, 1, 1, 0],
  822. "Region": [0, 1, 0, 1]
  823. },
  824. activeState: "HeatLine"
  825. }]
  826. }]
  827. }, {
  828. title: "Adding more datasets",
  829. name: "multi-dataset",
  830. contentBlocks: [{
  831. type: "text",
  832. content: "A chart can have multiple datasets. In an axis chart, every dataset is represented individually."
  833. }, {
  834. type: "code",
  835. content: " ...\n data: {\n labels: [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"],\n datasets: [\n { name: \"Dataset 1\", values: [18, 40, 30, 35, 8, 52, 17, -4] },\n { name: \"Dataset 2\", values: [30, 50, -10, 15, 18, 32, 27, 14] }\n ]\n },\n ..."
  836. }, {
  837. type: "demo",
  838. config: {
  839. data: sampleData[1],
  840. type: 'line',
  841. height: 200,
  842. colors: ['green', 'light-green']
  843. },
  844. options: [{
  845. name: "type",
  846. path: ["type"],
  847. type: "string",
  848. states: {
  849. "Line": 'line',
  850. "Bar": 'bar'
  851. },
  852. activeState: "Mixed"
  853. }]
  854. }]
  855. }];
  856. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  857. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  858. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  859. var docsBuilder = function () {
  860. function docsBuilder(LIB_OBJ) {
  861. _classCallCheck(this, docsBuilder);
  862. this.LIB_OBJ = LIB_OBJ;
  863. }
  864. _createClass(docsBuilder, [{
  865. key: 'makeSection',
  866. value: function makeSection(parent, sys) {
  867. return new docSection(this.LIB_OBJ, parent, sys);
  868. }
  869. }]);
  870. return docsBuilder;
  871. }();
  872. var docSection = function () {
  873. function docSection(LIB_OBJ, parent, sys) {
  874. _classCallCheck(this, docSection);
  875. this.LIB_OBJ = LIB_OBJ;
  876. this.parent = parent; // should be preferably a section
  877. this.sys = sys;
  878. this.blockMap = {};
  879. this.demos = [];
  880. this.make();
  881. }
  882. _createClass(docSection, [{
  883. key: 'make',
  884. value: function make() {
  885. var _this = this;
  886. // const section = document.querySelector(this.parent);
  887. var s = this.sys;
  888. if (s.title) {
  889. $.create('h6', { inside: this.parent, innerHTML: s.title });
  890. }
  891. s.contentBlocks.forEach(function (blockConf, index) {
  892. _this.blockMap[index] = _this.getBlock(blockConf);
  893. });
  894. }
  895. }, {
  896. key: 'getBlock',
  897. value: function getBlock(blockConf) {
  898. var fnName = 'get' + toTitleCase(blockConf.type);
  899. if (this[fnName]) {
  900. return this[fnName](blockConf);
  901. } else {
  902. throw new Error('Unknown section block type \'' + blockConf.type + '\'.');
  903. }
  904. }
  905. }, {
  906. key: 'getText',
  907. value: function getText(blockConf) {
  908. return $.create('p', {
  909. inside: this.parent,
  910. className: 'new-context',
  911. innerHTML: blockConf.content
  912. });
  913. }
  914. }, {
  915. key: 'getCode',
  916. value: function getCode(blockConf) {
  917. var pre = $.create('pre', { inside: this.parent });
  918. var lang = blockConf.lang || 'javascript';
  919. var code = $.create('code', {
  920. inside: pre,
  921. className: 'hljs ' + lang,
  922. innerHTML: blockConf.content
  923. });
  924. }
  925. }, {
  926. key: 'getCustom',
  927. value: function getCustom(blockConf) {
  928. this.parent.innerHTML += blockConf.html;
  929. }
  930. }, {
  931. key: 'getDemo',
  932. value: function getDemo(blockConf) {
  933. var bc = blockConf;
  934. var args = bc.config;
  935. var figure = void 0,
  936. row = void 0;
  937. if (!bc.sideContent) {
  938. figure = $.create('figure', { inside: this.parent });
  939. } else {
  940. row = $.create('div', {
  941. inside: this.parent,
  942. className: "row",
  943. innerHTML: '<div class="col-sm-8"></div>\n\t\t\t\t\t<div class="col-sm-4"></div>'
  944. });
  945. figure = $.create('figure', { inside: row.querySelector('.col-sm-8') });
  946. row.querySelector('.col-sm-4').innerHTML += bc.sideContent;
  947. }
  948. var libObj = new this.LIB_OBJ(figure, args);
  949. var demoIndex = this.demos.length;
  950. this.demos.push(libObj);
  951. if (bc.postSetup) {
  952. bc.postSetup(this.demos[demoIndex], figure, row);
  953. }
  954. this.getDemoOptions(demoIndex, bc.options, args, figure);
  955. this.getDemoActions(demoIndex, bc.actions, args);
  956. }
  957. }, {
  958. key: 'getDemoOptions',
  959. value: function getDemoOptions(demoIndex) {
  960. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  961. var _this2 = this;
  962. var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  963. var figure = arguments[3];
  964. options.forEach(function (o) {
  965. var btnGroup = $.create('div', {
  966. inside: _this2.parent,
  967. className: 'btn-group ' + o.name
  968. });
  969. var mapKeys = o.mapKeys;
  970. if (o.type === "map") {
  971. args[o.path[0]] = {};
  972. }
  973. Object.keys(o.states).forEach(function (key) {
  974. var state = o.states[key];
  975. var activeClass = key === o.activeState ? 'active' : '';
  976. var button = $.create('button', {
  977. inside: btnGroup,
  978. className: 'btn btn-sm btn-secondary ' + activeClass,
  979. innerHTML: key,
  980. onClick: function onClick(e) {
  981. // map
  982. if (o.type === "map") {
  983. mapKeys.forEach(function (attr, i) {
  984. args[o.path[0]][attr] = state[i];
  985. });
  986. } else {
  987. // boolean, string, number, object
  988. args[o.path[0]] = state;
  989. }
  990. _this2.demos[demoIndex] = new _this2.LIB_OBJ(figure, args);
  991. }
  992. });
  993. if (activeClass) {
  994. button.click();
  995. }
  996. });
  997. });
  998. }
  999. }, {
  1000. key: 'getDemoActions',
  1001. value: function getDemoActions(demoIndex) {
  1002. var _this3 = this;
  1003. var actions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  1004. actions.forEach(function (o) {
  1005. var args = o.args || [];
  1006. $.create('button', {
  1007. inside: _this3.parent,
  1008. className: 'btn btn-action btn-sm btn-secondary',
  1009. innerHTML: o.name,
  1010. onClick: function onClick() {
  1011. var _demos$demoIndex;
  1012. (_demos$demoIndex = _this3.demos[demoIndex])[o.fn].apply(_demos$demoIndex, _toConsumableArray(args));
  1013. }
  1014. });
  1015. });
  1016. }
  1017. }]);
  1018. return docSection;
  1019. }();
  1020. var Chart = frappe.Chart; // eslint-disable-line no-undef
  1021. var dbd = new docsBuilder(Chart);
  1022. var currentElement = document.querySelector('header');
  1023. var sections = void 0;
  1024. if (window.location.pathname.split("/").pop().includes('index')) {
  1025. var lineCompositeChart = new Chart("#line-composite-1", lineComposite.config);
  1026. var barCompositeChart = new Chart("#bar-composite-1", barComposite.config);
  1027. lineCompositeChart.parent.addEventListener('data-select', function (e) {
  1028. var i = e.index;
  1029. barCompositeChart.updateDatasets([fireballOver25[i], fireball_5_25[i], fireball_2_5[i]]);
  1030. });
  1031. sections = demoSections;
  1032. } else {
  1033. sections = docSections;
  1034. }
  1035. sections.forEach(function (sectionConf) {
  1036. var sectionEl = $.create('section', { className: sectionConf.name || sectionConf.title });
  1037. insertAfter(sectionEl, currentElement);
  1038. currentElement = sectionEl;
  1039. dbd.makeSection(sectionEl, sectionConf);
  1040. });
  1041. }());