您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

1021 行
32 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. function clone(date) {
  159. return new Date(date.getTime());
  160. }
  161. function timestampSec(date) {
  162. return date.getTime() / NO_OF_MILLIS;
  163. }
  164. function timestampToMidnight(timestamp) {
  165. var roundAhead = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  166. var midnightTs = Math.floor(timestamp - timestamp % SEC_IN_DAY);
  167. if (roundAhead) {
  168. return midnightTs + SEC_IN_DAY;
  169. }
  170. return midnightTs;
  171. }
  172. // export function getMonthsBetween(startDate, endDate) {}
  173. // mutates
  174. // mutates
  175. function addDays(date, numberOfDays) {
  176. date.setDate(date.getDate() + numberOfDays);
  177. }
  178. // Fixed 5-color theme,
  179. // More colors are difficult to parse visually
  180. var HEATMAP_COLORS_BLUE = ['#ebedf0', '#c0ddf9', '#73b3f3', '#3886e1', '#17459e'];
  181. var HEATMAP_COLORS_YELLOW = ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c'];
  182. // Universal constants
  183. /**
  184. * Returns the value of a number upto 2 decimal places.
  185. * @param {Number} d Any number
  186. */
  187. /**
  188. * Returns whether or not two given arrays are equal.
  189. * @param {Array} arr1 First array
  190. * @param {Array} arr2 Second array
  191. */
  192. /**
  193. * Shuffles array in place. ES6 version
  194. * @param {Array} array An array containing the items.
  195. */
  196. function shuffle(array) {
  197. // Awesomeness: https://bost.ocks.org/mike/shuffle/
  198. // https://stackoverflow.com/a/2450976/6495043
  199. // https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array?noredirect=1&lq=1
  200. for (var i = array.length - 1; i > 0; i--) {
  201. var j = Math.floor(Math.random() * (i + 1));
  202. var _ref = [array[j], array[i]];
  203. array[i] = _ref[0];
  204. array[j] = _ref[1];
  205. }
  206. return array;
  207. }
  208. /**
  209. * Fill an array with extra points
  210. * @param {Array} array Array
  211. * @param {Number} count number of filler elements
  212. * @param {Object} element element to fill with
  213. * @param {Boolean} start fill at start?
  214. */
  215. /**
  216. * Returns pixel width of string.
  217. * @param {String} string
  218. * @param {Number} charWidth Width of single char in pixels
  219. */
  220. // https://stackoverflow.com/a/29325222
  221. function getRandomBias(min, max, bias, influence) {
  222. var range = max - min;
  223. var biasValue = range * bias + min;
  224. var rnd = Math.random() * range + min,
  225. // random in range
  226. mix = Math.random() * influence; // random mixer
  227. return rnd * (1 - mix) + biasValue * mix; // mix full range and bias
  228. }
  229. function toTitleCase(str) {
  230. return str.replace(/\w*/g, function (txt) {
  231. return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  232. });
  233. }
  234. // Composite Chart
  235. // ================================================================================
  236. var reportCountList = [152, 222, 199, 287, 534, 709, 1179, 1256, 1632, 1856, 1850];
  237. var lineCompositeData = {
  238. labels: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017"],
  239. yMarkers: [{
  240. label: "Average 100 reports/month",
  241. value: 1200,
  242. options: { labelPos: 'left' }
  243. }],
  244. datasets: [{
  245. "name": "Events",
  246. "values": reportCountList
  247. }]
  248. };
  249. 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]];
  250. 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]];
  251. var fireballOver25 = [
  252. // [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  253. [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]];
  254. var barCompositeData = {
  255. labels: MONTH_NAMES_SHORT,
  256. datasets: [{
  257. name: "Over 25 reports",
  258. values: fireballOver25[9]
  259. }, {
  260. name: "5 to 25 reports",
  261. values: fireball_5_25[9]
  262. }, {
  263. name: "2 to 5 reports",
  264. values: fireball_2_5[9]
  265. }]
  266. };
  267. // Demo Chart multitype Chart
  268. // ================================================================================
  269. var typeData = {
  270. labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm", "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"],
  271. yMarkers: [{
  272. label: "Marker",
  273. value: 43,
  274. options: { labelPos: 'left'
  275. // type: 'dashed'
  276. } }],
  277. yRegions: [{
  278. label: "Region",
  279. start: -10,
  280. end: 50,
  281. options: { labelPos: 'right' }
  282. }],
  283. datasets: [{
  284. name: "Some Data",
  285. values: [18, 40, 30, 35, 8, 52, 17, -4],
  286. axisPosition: 'right',
  287. chartType: 'bar'
  288. }, {
  289. name: "Another Set",
  290. values: [30, 50, -10, 15, 18, 32, 27, 14],
  291. axisPosition: 'right',
  292. chartType: 'bar'
  293. }, {
  294. name: "Yet Another",
  295. values: [15, 20, -3, -15, 58, 12, -17, 37],
  296. chartType: 'line'
  297. }]
  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 baseLength = 10;
  301. var fullLength = 30;
  302. var getRandom = function getRandom() {
  303. return Math.floor(getRandomBias(-40, 60, 0.8, 1));
  304. };
  305. var updateDataAllValues = Array.from({ length: fullLength }, getRandom);
  306. // We're gonna be shuffling this
  307. var updateDataAllIndices = updateDataAllLabels.map(function (d, i) {
  308. return i;
  309. });
  310. var getUpdateArray = function getUpdateArray(sourceArray) {
  311. var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
  312. var indices = updateDataAllIndices.slice(0, length);
  313. return indices.map(function (index) {
  314. return sourceArray[index];
  315. });
  316. };
  317. var currentLastIndex = baseLength;
  318. function getUpdateData() {
  319. shuffle(updateDataAllIndices);
  320. var value = getRandom();
  321. var start = getRandom();
  322. var end = getRandom();
  323. currentLastIndex = baseLength;
  324. return {
  325. labels: updateDataAllLabels.slice(0, baseLength),
  326. datasets: [{
  327. values: getUpdateArray(updateDataAllValues)
  328. }],
  329. yMarkers: [{
  330. label: "Altitude",
  331. value: value,
  332. type: 'dashed'
  333. }],
  334. yRegions: [{
  335. label: "Range",
  336. start: start,
  337. end: end
  338. }]
  339. };
  340. }
  341. function getAddUpdateData() {
  342. if (currentLastIndex >= fullLength) return;
  343. // TODO: Fix update on removal
  344. currentLastIndex++;
  345. var c = currentLastIndex - 1;
  346. return [updateDataAllLabels[c], [updateDataAllValues[c]]];
  347. // updateChart.addDataPoint(
  348. // updateDataAllLabels[index], [updateDataAllValues[index]]
  349. // );
  350. }
  351. var trendsData = {
  352. 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],
  353. datasets: [{
  354. 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]
  355. }]
  356. };
  357. var moonData = {
  358. names: ["Ganymede", "Callisto", "Io", "Europa"],
  359. masses: [14819000, 10759000, 8931900, 4800000],
  360. distances: [1070.412, 1882.709, 421.700, 671.034],
  361. diameters: [5262.4, 4820.6, 3637.4, 3121.6]
  362. };
  363. var eventsData = {
  364. labels: ["Ganymede", "Callisto", "Io", "Europa"],
  365. datasets: [{
  366. "values": moonData.distances,
  367. "formatted": moonData.distances.map(function (d) {
  368. return d * 1000 + " km";
  369. })
  370. }]
  371. };
  372. // const jupiterMoons = {
  373. // 'Ganymede': {
  374. // mass: '14819000 x 10^16 kg',
  375. // 'semi-major-axis': '1070412 km',
  376. // 'diameter': '5262.4 km'
  377. // },
  378. // 'Callisto': {
  379. // mass: '10759000 x 10^16 kg',
  380. // 'semi-major-axis': '1882709 km',
  381. // 'diameter': '4820.6 km'
  382. // },
  383. // 'Io': {
  384. // mass: '8931900 x 10^16 kg',
  385. // 'semi-major-axis': '421700 km',
  386. // 'diameter': '3637.4 km'
  387. // },
  388. // 'Europa': {
  389. // mass: '4800000 x 10^16 kg',
  390. // 'semi-major-axis': '671034 km',
  391. // 'diameter': '3121.6 km'
  392. // },
  393. // };
  394. // ================================================================================
  395. var today = new Date();
  396. var start = clone(today);
  397. addDays(start, 4);
  398. var end = clone(start);
  399. start.setFullYear(start.getFullYear() - 2);
  400. end.setFullYear(end.getFullYear() - 1);
  401. var dataPoints = {};
  402. var startTs = timestampSec(start);
  403. var endTs = timestampSec(end);
  404. startTs = timestampToMidnight(startTs);
  405. endTs = timestampToMidnight(endTs, true);
  406. while (startTs < endTs) {
  407. dataPoints[parseInt(startTs)] = Math.floor(getRandomBias(0, 5, 0.2, 1));
  408. startTs += SEC_IN_DAY;
  409. }
  410. var heatmapData = {
  411. dataPoints: dataPoints,
  412. start: start,
  413. end: end
  414. };
  415. var lineComposite = {
  416. config: {
  417. title: "Fireball/Bolide Events - Yearly (reported)",
  418. data: lineCompositeData,
  419. type: "line",
  420. height: 190,
  421. colors: ["green"],
  422. isNavigable: 1,
  423. valuesOverPoints: 1,
  424. lineOptions: {
  425. dotSize: 8
  426. }
  427. }
  428. };
  429. var barComposite = {
  430. config: {
  431. data: barCompositeData,
  432. type: "bar",
  433. height: 210,
  434. colors: ["violet", "light-blue", "#46a9f9"],
  435. valuesOverPoints: 1,
  436. axisOptions: {
  437. xAxisMode: "tick"
  438. },
  439. barOptions: {
  440. stacked: 1
  441. }
  442. }
  443. };
  444. var demoSections = [{
  445. title: "Create a Chart",
  446. name: "demo-main",
  447. contentBlocks: [{
  448. type: "code",
  449. lang: "html",
  450. content: ' &lt!--HTML--&gt;\n &lt;figure id="frost-chart"&gt;&lt;/figure&gt;'
  451. }, {
  452. type: "code",
  453. lang: "javascript",
  454. 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();'
  455. }, {
  456. type: "demo",
  457. config: {
  458. title: "My Awesome Chart",
  459. data: typeData,
  460. type: "axis-mixed",
  461. height: 300,
  462. colors: ["purple", "magenta", "light-blue"],
  463. maxSlices: 10,
  464. tooltipOptions: {
  465. formatTooltipX: function formatTooltipX(d) {
  466. return (d + '').toUpperCase();
  467. },
  468. formatTooltipY: function formatTooltipY(d) {
  469. return d + ' pts';
  470. }
  471. }
  472. },
  473. options: [{
  474. name: "type",
  475. path: ["type"],
  476. type: "string",
  477. states: {
  478. "Mixed": 'axis-mixed',
  479. "Line": 'line',
  480. "Bar": 'bar',
  481. "Pie Chart": 'pie',
  482. "Percentage Chart": 'percentage'
  483. },
  484. activeState: "Mixed"
  485. }],
  486. actions: [{ name: "Export ...", fn: "export", args: [] }]
  487. }]
  488. }, {
  489. title: "Update Values",
  490. name: "updates-chart",
  491. contentBlocks: [{
  492. type: "demo",
  493. config: {
  494. data: getUpdateData(),
  495. type: 'line',
  496. height: 300,
  497. colors: ['#ff6c03'],
  498. lineOptions: {
  499. regionFill: 1
  500. }
  501. },
  502. actions: [{
  503. name: "Random Data",
  504. fn: "update",
  505. args: [getUpdateData()]
  506. }, {
  507. name: "Add Value",
  508. fn: "addDataPoint",
  509. args: getAddUpdateData()
  510. }, {
  511. name: "Remove Value",
  512. fn: "removeDataPoint",
  513. args: []
  514. }, {
  515. name: "Export ...",
  516. fn: "export",
  517. args: []
  518. }]
  519. }]
  520. }, {
  521. title: "Plot Trends",
  522. name: "trends-plot",
  523. contentBlocks: [{
  524. type: "demo",
  525. config: {
  526. title: "Mean Total Sunspot Count - Yearly",
  527. data: trendsData,
  528. type: 'line',
  529. height: 300,
  530. colors: ['#238e38'],
  531. axisOptions: {
  532. xAxisMode: 'tick',
  533. yAxisMode: 'span',
  534. xIsSeries: 1
  535. }
  536. },
  537. options: [{
  538. name: "lineOptions",
  539. path: ["lineOptions"],
  540. type: "map",
  541. mapKeys: ['hideLine', 'hideDots', 'heatline', 'regionFill'],
  542. states: {
  543. "Line": [0, 1, 0, 0],
  544. "Dots": [1, 0, 0, 0],
  545. "HeatLine": [0, 1, 1, 0],
  546. "Region": [0, 1, 0, 1]
  547. },
  548. activeState: "HeatLine"
  549. }],
  550. actions: [{ name: "Export ...", fn: "export", args: [] }]
  551. }]
  552. }, {
  553. title: "Listen to state change",
  554. name: "state-change",
  555. contentBlocks: [{
  556. type: "demo",
  557. config: {
  558. title: "Jupiter's Moons: Semi-major Axis (1000 km)",
  559. data: eventsData,
  560. type: 'bar',
  561. height: 330,
  562. colors: ['grey'],
  563. isNavigable: 1
  564. },
  565. 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>',
  566. postSetup: function postSetup(chart, figure, row) {
  567. chart.parent.addEventListener('data-select', function (e) {
  568. var i = e.index;
  569. var name = moonData.names[i];
  570. row.querySelector('.moon-name').innerHTML = name;
  571. row.querySelector('.semi-major-axis').innerHTML = moonData.distances[i] * 1000;
  572. row.querySelector('.mass').innerHTML = moonData.masses[i];
  573. row.querySelector('.diameter').innerHTML = moonData.diameters[i];
  574. row.querySelector('img').src = "./assets/img/" + name.toLowerCase() + ".jpg";
  575. });
  576. }
  577. }, {
  578. type: "code",
  579. lang: "javascript",
  580. 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 });'
  581. }]
  582. }, {
  583. title: "And a Month-wise Heatmap",
  584. name: "heatmap",
  585. contentBlocks: [{
  586. type: "demo",
  587. config: {
  588. title: "Monthly Distribution",
  589. data: heatmapData,
  590. type: 'heatmap',
  591. discreteDomains: 1,
  592. countLabel: 'Level',
  593. colors: HEATMAP_COLORS_BLUE,
  594. legendScale: [0, 1, 2, 4, 5]
  595. },
  596. options: [{
  597. name: "Discrete domains",
  598. path: ["discreteDomains"],
  599. type: 'boolean',
  600. // boolNames: ["Continuous", "Discrete"],
  601. states: { "Discrete": 1, "Continuous": 0 }
  602. }, {
  603. name: "Colors",
  604. path: ["colors"],
  605. type: "object",
  606. states: {
  607. "Green (Default)": [],
  608. "Blue": HEATMAP_COLORS_BLUE,
  609. "GitHub's Halloween": HEATMAP_COLORS_YELLOW
  610. }
  611. }],
  612. actions: [{ name: "Export ...", fn: "export", args: [] }]
  613. }, {
  614. type: "code",
  615. lang: "javascript",
  616. 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 });'
  617. }]
  618. }, {
  619. title: "Demo",
  620. name: "codepen",
  621. contentBlocks: [{
  622. type: "custom",
  623. 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>'
  624. }]
  625. }, {
  626. title: "Available Options",
  627. name: "options",
  628. contentBlocks: [{
  629. type: "code",
  630. lang: "javascript",
  631. 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 '
  632. }]
  633. }, {
  634. title: "Install",
  635. name: "installation",
  636. 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:' }, {
  637. type: "code",
  638. lang: "javascript",
  639. content: ' new Chart(); // ES6 module\n // or\n new frappe.Chart(); // Browser'
  640. }, { type: "text", content: '... or include it directly in your HTML' }, {
  641. type: "code",
  642. lang: "html",
  643. content: ' &lt;script src="https://unpkg.com/frappe-charts@1.1.0"&gt;&lt;/script&gt;'
  644. }]
  645. }];
  646. 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; }; }();
  647. 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); } }
  648. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  649. var docsBuilder = function () {
  650. function docsBuilder(LIB_OBJ) {
  651. _classCallCheck(this, docsBuilder);
  652. this.LIB_OBJ = LIB_OBJ;
  653. }
  654. _createClass(docsBuilder, [{
  655. key: 'makeSection',
  656. value: function makeSection(parent, sys) {
  657. console.log('parent here?', parent);
  658. return new docSection(this.LIB_OBJ, parent, sys);
  659. }
  660. }]);
  661. return docsBuilder;
  662. }();
  663. var docSection = function () {
  664. function docSection(LIB_OBJ, parent, sys) {
  665. _classCallCheck(this, docSection);
  666. this.LIB_OBJ = LIB_OBJ;
  667. this.parent = parent; // should be preferably a section
  668. this.sys = sys;
  669. this.blockMap = {};
  670. this.demos = [];
  671. this.make();
  672. }
  673. _createClass(docSection, [{
  674. key: 'make',
  675. value: function make() {
  676. // const section = document.querySelector(this.parent);
  677. var s = this.sys;
  678. // if(s.title) {
  679. // $.create('h6', { inside: this.parent, innerHTML: s.title });
  680. // }
  681. // s.contentBlocks.forEach((blockConf, index) => {
  682. // this.blockMap[index] = this.getBlock(blockConf);
  683. // });
  684. this.blockMap['test'] = this.getDemo(s);
  685. }
  686. }, {
  687. key: 'getBlock',
  688. value: function getBlock(blockConf) {
  689. var fnName = 'get' + toTitleCase(blockConf.type);
  690. if (this[fnName]) {
  691. return this[fnName](blockConf);
  692. } else {
  693. throw new Error('Unknown section block type \'' + blockConf.type + '\'.');
  694. }
  695. }
  696. }, {
  697. key: 'getText',
  698. value: function getText(blockConf) {
  699. return $.create('p', {
  700. inside: this.parent,
  701. className: 'new-context',
  702. innerHTML: blockConf.content
  703. });
  704. }
  705. }, {
  706. key: 'getCode',
  707. value: function getCode(blockConf) {
  708. var pre = $.create('pre', { inside: this.parent });
  709. var lang = blockConf.lang || 'javascript';
  710. var code = $.create('code', {
  711. inside: pre,
  712. className: 'hljs ' + lang,
  713. innerHTML: blockConf.content
  714. });
  715. }
  716. }, {
  717. key: 'getCustom',
  718. value: function getCustom(blockConf) {
  719. this.parent.innerHTML += blockConf.html;
  720. }
  721. }, {
  722. key: 'getDemo',
  723. value: function getDemo(blockConf) {
  724. var bc = blockConf;
  725. var args = bc.config;
  726. var figure = void 0,
  727. row = void 0;
  728. if (!bc.sideContent) {
  729. figure = $.create('figure', { inside: this.parent });
  730. } else {
  731. row = $.create('div', {
  732. inside: this.parent,
  733. className: "row",
  734. innerHTML: '<div class="col-sm-8"></div>\n\t\t\t\t\t<div class="col-sm-4"></div>'
  735. });
  736. figure = $.create('figure', { inside: row.querySelector('.col-sm-8') });
  737. row.querySelector('.col-sm-4').innerHTML += bc.sideContent;
  738. }
  739. var libObj = new this.LIB_OBJ(figure, args);
  740. var demoIndex = this.demos.length;
  741. this.demos.push(libObj);
  742. if (bc.postSetup) {
  743. bc.postSetup(this.demos[demoIndex], figure, row);
  744. }
  745. this.getDemoOptions(demoIndex, bc.options, args, figure);
  746. this.getDemoActions(demoIndex, bc.actions, args);
  747. }
  748. }, {
  749. key: 'getDemoOptions',
  750. value: function getDemoOptions(demoIndex) {
  751. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  752. var _this = this;
  753. var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  754. var figure = arguments[3];
  755. options.forEach(function (o) {
  756. var btnGroup = $.create('div', {
  757. inside: _this.parent,
  758. className: 'btn-group ' + o.name
  759. });
  760. var mapKeys = o.mapKeys;
  761. if (o.type === "map") {
  762. args[o.path[0]] = {};
  763. }
  764. var inputGroup = $.create('input', {
  765. inside: btnGroup
  766. // className: `form-control`,
  767. // innerHTML: `<input type="text" class="form-control" placeholder="Username"
  768. // aria-label="Username" aria-describedby="basic-addon1">`
  769. });
  770. Object.keys(o.states).forEach(function (key) {
  771. var state = o.states[key];
  772. var activeClass = key === o.activeState ? 'active' : '';
  773. var button = $.create('button', {
  774. inside: btnGroup,
  775. className: 'btn btn-sm btn-secondary ' + activeClass,
  776. innerHTML: key,
  777. onClick: function onClick(e) {
  778. // map
  779. if (o.type === "map") {
  780. mapKeys.forEach(function (attr, i) {
  781. args[o.path[0]][attr] = state[i];
  782. });
  783. } else {
  784. // boolean, string, number, object
  785. args[o.path[0]] = state;
  786. }
  787. _this.demos[demoIndex] = new _this.LIB_OBJ(figure, args);
  788. }
  789. });
  790. if (activeClass) {
  791. button.click();
  792. }
  793. });
  794. });
  795. }
  796. }, {
  797. key: 'getDemoActions',
  798. value: function getDemoActions(demoIndex) {
  799. var _this2 = this;
  800. var actions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  801. actions.forEach(function (o) {
  802. var args = o.args || [];
  803. $.create('button', {
  804. inside: _this2.parent,
  805. className: 'btn btn-action btn-sm btn-secondary',
  806. innerHTML: o.name,
  807. onClick: function onClick() {
  808. var _demos$demoIndex;
  809. (_demos$demoIndex = _this2.demos[demoIndex])[o.fn].apply(_demos$demoIndex, _toConsumableArray(args));
  810. }
  811. });
  812. });
  813. }
  814. }]);
  815. return docSection;
  816. }();
  817. var Chart = frappe.Chart; // eslint-disable-line no-undef
  818. var dbd = new docsBuilder(Chart);
  819. var currentElement = document.querySelector('header');
  820. var sections = [];
  821. if (document.querySelectorAll('#line-composite-1').length) {
  822. var lineCompositeChart = new Chart("#line-composite-1", lineComposite.config);
  823. var barCompositeChart = new Chart("#bar-composite-1", barComposite.config);
  824. lineCompositeChart.parent.addEventListener('data-select', function (e) {
  825. var i = e.index;
  826. barCompositeChart.updateDatasets([fireballOver25[i], fireball_5_25[i], fireball_2_5[i]]);
  827. });
  828. sections = demoSections;
  829. }
  830. // else {
  831. // sections = docSections;
  832. // }
  833. sections.forEach(function (sectionConf) {
  834. var sectionEl = $.create('section', { className: sectionConf.name || sectionConf.title });
  835. insertAfter(sectionEl, currentElement);
  836. currentElement = sectionEl;
  837. dbd.makeSection(sectionEl, sectionConf);
  838. });
  839. }());