選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.min.js 31 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  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 lineComposite = {
  411. config: {
  412. title: "Fireball/Bolide Events - Yearly (reported)",
  413. data: lineCompositeData,
  414. type: "line",
  415. height: 190,
  416. colors: ["green"],
  417. isNavigable: 1,
  418. valuesOverPoints: 1,
  419. lineOptions: {
  420. dotSize: 8
  421. }
  422. }
  423. };
  424. var barComposite = {
  425. config: {
  426. data: barCompositeData,
  427. type: "bar",
  428. height: 210,
  429. colors: ["violet", "light-blue", "#46a9f9"],
  430. valuesOverPoints: 1,
  431. axisOptions: {
  432. xAxisMode: "tick"
  433. },
  434. barOptions: {
  435. stacked: 1
  436. }
  437. }
  438. };
  439. var demoSections = [{
  440. title: "Create a Chart",
  441. name: "demo-main",
  442. contentBlocks: [{
  443. type: "code",
  444. lang: "html",
  445. content: ' &lt!--HTML--&gt;\n &lt;figure id="frost-chart"&gt;&lt;/figure&gt;'
  446. }, {
  447. type: "code",
  448. lang: "javascript",
  449. 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();'
  450. }, {
  451. type: "demo",
  452. config: {
  453. title: "My Awesome Chart",
  454. data: typeData,
  455. type: "axis-mixed",
  456. height: 300,
  457. colors: ["purple", "magenta", "light-blue"],
  458. maxSlices: 10,
  459. tooltipOptions: {
  460. formatTooltipX: function formatTooltipX(d) {
  461. return (d + '').toUpperCase();
  462. },
  463. formatTooltipY: function formatTooltipY(d) {
  464. return d + ' pts';
  465. }
  466. }
  467. },
  468. options: [{
  469. name: "type",
  470. path: ["type"],
  471. type: "string",
  472. states: {
  473. "Mixed": 'axis-mixed',
  474. "Line": 'line',
  475. "Bar": 'bar',
  476. "Pie Chart": 'pie',
  477. "Percentage Chart": 'percentage'
  478. },
  479. activeState: "Mixed"
  480. }],
  481. actions: [{ name: "Export ...", fn: "export", args: [] }]
  482. }]
  483. }, {
  484. title: "Update Values",
  485. name: "updates-chart",
  486. contentBlocks: [{
  487. type: "demo",
  488. config: {
  489. data: getUpdateData(),
  490. type: 'line',
  491. height: 300,
  492. colors: ['#ff6c03'],
  493. lineOptions: {
  494. regionFill: 1
  495. }
  496. },
  497. actions: [{
  498. name: "Random Data",
  499. fn: "update",
  500. args: [getUpdateData()]
  501. }, {
  502. name: "Add Value",
  503. fn: "addDataPoint",
  504. args: getAddUpdateData()
  505. }, {
  506. name: "Remove Value",
  507. fn: "removeDataPoint",
  508. args: []
  509. }, {
  510. name: "Export ...",
  511. fn: "export",
  512. args: []
  513. }]
  514. }]
  515. }, {
  516. title: "Plot Trends",
  517. name: "trends-plot",
  518. contentBlocks: [{
  519. type: "demo",
  520. config: {
  521. title: "Mean Total Sunspot Count - Yearly",
  522. data: trendsData,
  523. type: 'line',
  524. height: 300,
  525. colors: ['#238e38'],
  526. axisOptions: {
  527. xAxisMode: 'tick',
  528. yAxisMode: 'span',
  529. xIsSeries: 1
  530. }
  531. },
  532. options: [{
  533. name: "lineOptions",
  534. path: ["lineOptions"],
  535. type: "map",
  536. mapKeys: ['hideLine', 'hideDots', 'heatline', 'regionFill'],
  537. states: {
  538. "Line": [0, 1, 0, 0],
  539. "Dots": [1, 0, 0, 0],
  540. "HeatLine": [0, 1, 1, 0],
  541. "Region": [0, 1, 0, 1]
  542. },
  543. activeState: "HeatLine"
  544. }],
  545. actions: [{ name: "Export ...", fn: "export", args: [] }]
  546. }]
  547. }, {
  548. title: "Listen to state change",
  549. name: "state-change",
  550. contentBlocks: [{
  551. type: "demo",
  552. config: {
  553. title: "Jupiter's Moons: Semi-major Axis (1000 km)",
  554. data: eventsData,
  555. type: 'bar',
  556. height: 330,
  557. colors: ['grey'],
  558. isNavigable: 1
  559. },
  560. 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>',
  561. postSetup: function postSetup(chart, figure, row) {
  562. chart.parent.addEventListener('data-select', function (e) {
  563. var i = e.index;
  564. var name = moonData.names[i];
  565. row.querySelector('.moon-name').innerHTML = name;
  566. row.querySelector('.semi-major-axis').innerHTML = moonData.distances[i] * 1000;
  567. row.querySelector('.mass').innerHTML = moonData.masses[i];
  568. row.querySelector('.diameter').innerHTML = moonData.diameters[i];
  569. row.querySelector('img').src = "./assets/img/" + name.toLowerCase() + ".jpg";
  570. });
  571. }
  572. }, {
  573. type: "code",
  574. lang: "javascript",
  575. 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 });'
  576. }]
  577. }, {
  578. title: "And a Month-wise Heatmap",
  579. name: "heatmap",
  580. contentBlocks: [{
  581. type: "demo",
  582. config: {
  583. title: "Monthly Distribution",
  584. data: heatmapData,
  585. type: 'heatmap',
  586. discreteDomains: 1,
  587. countLabel: 'Level',
  588. colors: HEATMAP_COLORS_BLUE,
  589. legendScale: [0, 1, 2, 4, 5]
  590. },
  591. options: [{
  592. name: "Discrete domains",
  593. path: ["discreteDomains"],
  594. type: 'boolean',
  595. // boolNames: ["Continuous", "Discrete"],
  596. states: { "Discrete": 1, "Continuous": 0 }
  597. }, {
  598. name: "Colors",
  599. path: ["colors"],
  600. type: "object",
  601. states: {
  602. "Green (Default)": [],
  603. "Blue": HEATMAP_COLORS_BLUE,
  604. "GitHub's Halloween": HEATMAP_COLORS_YELLOW
  605. }
  606. }],
  607. actions: [{ name: "Export ...", fn: "export", args: [] }]
  608. }, {
  609. type: "code",
  610. lang: "javascript",
  611. 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 });'
  612. }]
  613. }, {
  614. title: "Demo",
  615. name: "codepen",
  616. contentBlocks: [{
  617. type: "custom",
  618. 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>'
  619. }]
  620. }, {
  621. title: "Available Options",
  622. name: "options",
  623. contentBlocks: [{
  624. type: "code",
  625. lang: "javascript",
  626. 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 '
  627. }]
  628. }, {
  629. title: "Install",
  630. name: "installation",
  631. 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:' }, {
  632. type: "code",
  633. lang: "javascript",
  634. content: ' new Chart(); // ES6 module\n // or\n new frappe.Chart(); // Browser'
  635. }, { type: "text", content: '... or include it directly in your HTML' }, {
  636. type: "code",
  637. lang: "html",
  638. content: ' &lt;script src="https://unpkg.com/frappe-charts@1.1.0"&gt;&lt;/script&gt;'
  639. }]
  640. }];
  641. 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; }; }();
  642. 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); } }
  643. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  644. var docsBuilder = function () {
  645. function docsBuilder(LIB_OBJ) {
  646. _classCallCheck(this, docsBuilder);
  647. this.LIB_OBJ = LIB_OBJ;
  648. }
  649. _createClass(docsBuilder, [{
  650. key: 'makeSection',
  651. value: function makeSection(parent, sys) {
  652. return new docSection(this.LIB_OBJ, parent, sys);
  653. }
  654. }]);
  655. return docsBuilder;
  656. }();
  657. var docSection = function () {
  658. function docSection(LIB_OBJ, parent, sys) {
  659. _classCallCheck(this, docSection);
  660. this.LIB_OBJ = LIB_OBJ;
  661. this.parent = parent; // should be preferably a section
  662. this.sys = sys;
  663. this.blockMap = {};
  664. this.make();
  665. }
  666. _createClass(docSection, [{
  667. key: 'make',
  668. value: function make() {
  669. var _this = this;
  670. // const section = document.querySelector(this.parent);
  671. var s = this.sys;
  672. $.create('h6', { inside: this.parent, innerHTML: s.title });
  673. s.contentBlocks.forEach(function (blockConf, index) {
  674. _this.blockMap[index] = _this.getBlock(blockConf);
  675. });
  676. }
  677. }, {
  678. key: 'getBlock',
  679. value: function getBlock(blockConf) {
  680. var fnName = 'get' + toTitleCase(blockConf.type);
  681. if (this[fnName]) {
  682. return this[fnName](blockConf);
  683. } else {
  684. throw new Error('Unknown section block type \'' + blockConf.type + '\'.');
  685. }
  686. }
  687. }, {
  688. key: 'getText',
  689. value: function getText(blockConf) {
  690. return $.create('p', {
  691. inside: this.parent,
  692. innerHTML: blockConf.content
  693. });
  694. }
  695. }, {
  696. key: 'getCode',
  697. value: function getCode(blockConf) {
  698. var pre = $.create('pre', { inside: this.parent });
  699. var lang = blockConf.lang || 'javascript';
  700. var code = $.create('code', {
  701. inside: pre,
  702. className: 'hljs ' + lang,
  703. innerHTML: blockConf.content
  704. });
  705. }
  706. }, {
  707. key: 'getCustom',
  708. value: function getCustom(blockConf) {
  709. this.parent.innerHTML += blockConf.html;
  710. }
  711. }, {
  712. key: 'getDemo',
  713. value: function getDemo(blockConf) {
  714. var bc = blockConf;
  715. var args = bc.config;
  716. var figure = void 0,
  717. row = void 0;
  718. if (!bc.sideContent) {
  719. figure = $.create('figure', { inside: this.parent });
  720. } else {
  721. row = $.create('div', {
  722. inside: this.parent,
  723. className: "row",
  724. innerHTML: '<div class="col-sm-8"></div>\n\t\t\t\t\t<div class="col-sm-4"></div>'
  725. });
  726. figure = $.create('figure', { inside: row.querySelector('.col-sm-8') });
  727. row.querySelector('.col-sm-4').innerHTML += bc.sideContent;
  728. }
  729. this.libObj = new this.LIB_OBJ(figure, args);
  730. if (bc.postSetup) {
  731. bc.postSetup(this.libObj, figure, row);
  732. }
  733. this.getDemoOptions(bc.options, args, figure);
  734. this.getDemoActions(bc.actions, args);
  735. }
  736. }, {
  737. key: 'getDemoOptions',
  738. value: function getDemoOptions() {
  739. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  740. var _this2 = this;
  741. var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  742. var figure = arguments[2];
  743. options.forEach(function (o) {
  744. var btnGroup = $.create('div', {
  745. inside: _this2.parent,
  746. className: 'btn-group ' + o.name
  747. });
  748. var mapKeys = o.mapKeys;
  749. if (o.type === "map") {
  750. args[o.path[0]] = {};
  751. }
  752. Object.keys(o.states).forEach(function (key) {
  753. var state = o.states[key];
  754. var activeClass = key === o.activeState ? 'active' : '';
  755. var button = $.create('button', {
  756. inside: btnGroup,
  757. className: 'btn btn-sm btn-secondary ' + activeClass,
  758. innerHTML: key,
  759. onClick: function onClick(e) {
  760. // map
  761. if (o.type === "map") {
  762. mapKeys.forEach(function (attr, i) {
  763. args[o.path[0]][attr] = state[i];
  764. });
  765. } else {
  766. // boolean, string, number, object
  767. args[o.path[0]] = state;
  768. }
  769. _this2.libObj = new _this2.LIB_OBJ(figure, args);
  770. }
  771. });
  772. if (activeClass) {
  773. button.click();
  774. }
  775. });
  776. });
  777. }
  778. }, {
  779. key: 'getDemoActions',
  780. value: function getDemoActions() {
  781. var _this3 = this;
  782. var actions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  783. actions.forEach(function (o) {
  784. var args = o.args || [];
  785. $.create('button', {
  786. inside: _this3.parent,
  787. className: 'btn btn-action btn-sm btn-secondary',
  788. innerHTML: o.name,
  789. onClick: function onClick() {
  790. var _libObj;
  791. (_libObj = _this3.libObj)[o.fn].apply(_libObj, _toConsumableArray(args));
  792. }
  793. });
  794. });
  795. }
  796. }]);
  797. return docSection;
  798. }();
  799. var Chart = frappe.Chart; // eslint-disable-line no-undef
  800. var dbd = new docsBuilder(Chart);
  801. var lineCompositeChart = new Chart("#line-composite-1", lineComposite.config);
  802. var barCompositeChart = new Chart("#bar-composite-1", barComposite.config);
  803. lineCompositeChart.parent.addEventListener('data-select', function (e) {
  804. var i = e.index;
  805. barCompositeChart.updateDatasets([fireballOver25[i], fireball_5_25[i], fireball_2_5[i]]);
  806. });
  807. var currentElement = document.querySelector('header');
  808. demoSections.forEach(function (sectionConf) {
  809. var sectionEl = $.create('section', { className: sectionConf.name });
  810. insertAfter(sectionEl, currentElement);
  811. currentElement = sectionEl;
  812. dbd.makeSection(sectionEl, sectionConf);
  813. });
  814. }());