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

demoConfig.js 13 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. import { lineCompositeData, barCompositeData, typeData, getUpdateData,
  2. getAddUpdateData, trendsData, eventsData, moonData, heatmapData } from './data';
  3. import { HEATMAP_COLORS_YELLOW, HEATMAP_COLORS_BLUE } from '../../../src/js/utils/constants';
  4. export const lineComposite = {
  5. config: {
  6. title: "Fireball/Bolide Events - Yearly (reported)",
  7. data: lineCompositeData,
  8. type: "line",
  9. height: 190,
  10. colors: ["green"],
  11. isNavigable: 1,
  12. valuesOverPoints: 1,
  13. lineOptions: {
  14. dotSize: 8
  15. }
  16. }
  17. }
  18. export const barComposite = {
  19. config: {
  20. data: barCompositeData,
  21. type: "bar",
  22. height: 210,
  23. colors: ["violet", "light-blue", "#46a9f9"],
  24. valuesOverPoints: 1,
  25. axisOptions: {
  26. xAxisMode: "tick"
  27. },
  28. barOptions: {
  29. stacked: 1
  30. }
  31. }
  32. }
  33. export const demoSections = [
  34. {
  35. title: "Create a Chart",
  36. name: "demo-main",
  37. contentBlocks: [
  38. {
  39. type: "code",
  40. lang: "html",
  41. content: ` &lt!--HTML-->
  42. <figure id="frost-chart"></figure>`,
  43. },
  44. {
  45. type: "code",
  46. lang: "javascript",
  47. content: ` // Javascript
  48. let chart = new frappe.Chart( "#frost-chart", { // or DOM element
  49. data: {
  50. labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm",
  51. "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"],
  52. datasets: [
  53. {
  54. name: "Some Data", chartType: 'bar',
  55. values: [25, 40, 30, 35, 8, 52, 17, -4]
  56. },
  57. {
  58. name: "Another Set", chartType: 'bar',
  59. values: [25, 50, -10, 15, 18, 32, 27, 14]
  60. },
  61. {
  62. name: "Yet Another", chartType: 'line',
  63. values: [15, 20, -3, -15, 58, 12, -17, 37]
  64. }
  65. ],
  66. yMarkers: [{ label: "Marker", value: 70,
  67. options: { labelPos: 'left' }}],
  68. yRegions: [{ label: "Region", start: -10, end: 50,
  69. options: { labelPos: 'right' }}]
  70. },
  71. title: "My Awesome Chart",
  72. type: 'axis-mixed', // or 'bar', 'line', 'pie', 'percentage'
  73. height: 300,
  74. colors: ['purple', '#ffa3ef', 'light-blue'],
  75. tooltipOptions: {
  76. formatTooltipX: d => (d + '').toUpperCase(),
  77. formatTooltipY: d => d + ' pts',
  78. }
  79. });
  80. chart.export();`,
  81. },
  82. {
  83. type: "demo",
  84. config: {
  85. title: "My Awesome Chart",
  86. data: typeData,
  87. type: "axis-mixed",
  88. height: 300,
  89. colors: ["purple", "magenta", "light-blue"],
  90. maxSlices: 10,
  91. tooltipOptions: {
  92. formatTooltipX: d => (d + '').toUpperCase(),
  93. formatTooltipY: d => d + ' pts',
  94. }
  95. },
  96. options: [
  97. {
  98. name: "type",
  99. path: ["type"],
  100. type: "string",
  101. states: {
  102. "Mixed": 'axis-mixed',
  103. "Line": 'line',
  104. "Bar": 'bar',
  105. "Pie Chart": 'pie',
  106. "Percentage Chart": 'percentage',
  107. },
  108. activeState: "Mixed"
  109. }
  110. ],
  111. actions: [{ name: "Export ...", fn: "export", args: [] }],
  112. }
  113. ]
  114. },
  115. {
  116. title: "Update Values",
  117. name: "updates-chart",
  118. contentBlocks: [
  119. {
  120. type: "demo",
  121. config: {
  122. data: getUpdateData(),
  123. type: 'line',
  124. height: 300,
  125. colors: ['#ff6c03'],
  126. lineOptions: {
  127. areaFill: 1
  128. }
  129. },
  130. actions: [
  131. {
  132. name: "Random Data",
  133. fn: "update",
  134. args: [getUpdateData()]
  135. },
  136. {
  137. name: "Add Value",
  138. fn: "addDataPoint",
  139. args: getAddUpdateData()
  140. },
  141. {
  142. name: "Remove Value",
  143. fn: "removeDataPoint",
  144. args: []
  145. },
  146. {
  147. name: "Export ...",
  148. fn: "export",
  149. args: []
  150. }
  151. ]
  152. }
  153. ]
  154. },
  155. {
  156. title: "Plot Trends",
  157. name: "trends-plot",
  158. contentBlocks: [
  159. {
  160. type: "demo",
  161. config: {
  162. title: "Mean Total Sunspot Count - Yearly",
  163. data: trendsData,
  164. type: 'line',
  165. height: 300,
  166. colors: ['#238e38'],
  167. axisOptions: {
  168. xAxisMode: 'tick',
  169. yAxisMode: 'span',
  170. xIsSeries: 1
  171. }
  172. },
  173. options: [
  174. {
  175. name: "lineOptions",
  176. path: ["lineOptions"],
  177. type: "map",
  178. mapKeys: ['hideLine', 'hideDots', 'heatline', 'areaFill'],
  179. states: {
  180. "Line": [0, 1, 0, 0],
  181. "Dots": [1, 0, 0, 0],
  182. "HeatLine": [0, 1, 1, 0],
  183. "Area": [0, 1, 0, 1]
  184. },
  185. activeState: "HeatLine"
  186. }
  187. ],
  188. actions: [{ name: "Export ...", fn: "export", args: [] }]
  189. }
  190. ],
  191. },
  192. {
  193. title: "Listen to state change",
  194. name: "state-change",
  195. contentBlocks: [
  196. {
  197. type: "demo",
  198. config: {
  199. title: "Jupiter's Moons: Semi-major Axis (1000 km)",
  200. data: eventsData,
  201. type: 'bar',
  202. height: 330,
  203. colors: ['grey'],
  204. isNavigable: 1,
  205. },
  206. sideContent: `<div class="image-container border">
  207. <img class="moon-image" src="./assets/img/europa.jpg">
  208. </div>
  209. <div class="content-data mt1">
  210. <h6 class="moon-name">Europa</h6>
  211. <p>Semi-major-axis: <span class="semi-major-axis">671034</span> km</p>
  212. <p>Mass: <span class="mass">4800000</span> x 10^16 kg</p>
  213. <p>Diameter: <span class="diameter">3121.6</span> km</p>
  214. </div>`,
  215. postSetup: (chart, figure, row) => {
  216. chart.parent.addEventListener('data-select', (e) => {
  217. let i = e.index;
  218. let name = moonData.names[i];
  219. row.querySelector('.moon-name').innerHTML = name;
  220. row.querySelector('.semi-major-axis').innerHTML = moonData.distances[i] * 1000;
  221. row.querySelector('.mass').innerHTML = moonData.masses[i];
  222. row.querySelector('.diameter').innerHTML = moonData.diameters[i];
  223. row.querySelector('img').src = "./assets/img/" + name.toLowerCase() + ".jpg";
  224. });
  225. }
  226. },
  227. {
  228. type: "code",
  229. lang: "javascript",
  230. content: ` ...
  231. isNavigable: 1, // Navigate across data points; default 0
  232. ...
  233. chart.parent.addEventListener('data-select', (e) => {
  234. update_moon_data(e.index); // e contains index and value of current datapoint
  235. });`,
  236. }
  237. ]
  238. },
  239. {
  240. title: "And a Month-wise Heatmap",
  241. name: "heatmap",
  242. contentBlocks: [
  243. {
  244. type: "demo",
  245. config: {
  246. title: "Monthly Distribution",
  247. data: heatmapData,
  248. type: 'heatmap',
  249. discreteDomains: 1,
  250. countLabel: 'Level',
  251. colors: HEATMAP_COLORS_BLUE,
  252. legendScale: [0, 1, 2, 4, 5]
  253. },
  254. options: [
  255. {
  256. name: "Discrete domains",
  257. path: ["discreteDomains"],
  258. type: 'boolean',
  259. // boolNames: ["Continuous", "Discrete"],
  260. states: { "Discrete": 1, "Continuous": 0 }
  261. },
  262. {
  263. name: "Colors",
  264. path: ["colors"],
  265. type: "object",
  266. states: {
  267. "Green (Default)": [],
  268. "Blue": HEATMAP_COLORS_BLUE,
  269. "GitHub's Halloween": HEATMAP_COLORS_YELLOW
  270. }
  271. }
  272. ],
  273. actions: [{ name: "Export ...", fn: "export", args: [] }]
  274. },
  275. {
  276. type: "code",
  277. lang: "javascript",
  278. content: ` let heatmap = new frappe.Chart("#heatmap", {
  279. type: 'heatmap',
  280. title: "Monthly Distribution",
  281. data: {
  282. dataPoints: {'1524064033': 8, /* ... */},
  283. // object with timestamp-value pairs
  284. start: startDate
  285. end: endDate // Date objects
  286. },
  287. countLabel: 'Level',
  288. discreteDomains: 0 // default: 1
  289. colors: ['#ebedf0', '#c0ddf9', '#73b3f3', '#3886e1', '#17459e'],
  290. // Set of five incremental colors,
  291. // preferably with a low-saturation color for zero data;
  292. // def: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127']
  293. });`,
  294. }
  295. ],
  296. },
  297. {
  298. title: "Demo",
  299. name: "codepen",
  300. contentBlocks: [
  301. {
  302. type: "custom",
  303. html: `<p data-height="299" data-theme-id="light" data-slug-hash="wjKBoq" data-default-tab="js,result"
  304. data-user="pratu16x7" data-embed-version="2" data-pen-title="Frappe Charts Demo" class="codepen">
  305. See the Pen <a href="https://codepen.io/pratu16x7/pen/wjKBoq/">Frappe Charts Demo</a>
  306. by Prateeksha Singh (<a href="https://codepen.io/pratu16x7">@pratu16x7</a>) on
  307. <a href="https://codepen.io">CodePen</a>.
  308. </p>`
  309. }
  310. ]
  311. },
  312. {
  313. title: "Available Options",
  314. name: "options",
  315. contentBlocks: [
  316. {
  317. type: "code",
  318. lang: "javascript",
  319. content: `
  320. ...
  321. {
  322. data: {
  323. labels: [],
  324. datasets: [],
  325. yRegions: [],
  326. yMarkers: []
  327. }
  328. title: '',
  329. colors: [],
  330. height: 200,
  331. tooltipOptions: {
  332. formatTooltipX: d => (d + '').toUpperCase(),
  333. formatTooltipY: d => d + ' pts',
  334. }
  335. // Axis charts
  336. isNavigable: 1, // default: 0
  337. valuesOverPoints: 1, // default: 0
  338. barOptions: {
  339. spaceRatio: 1 // default: 0.5
  340. stacked: 1 // default: 0
  341. }
  342. lineOptions: {
  343. dotSize: 6, // default: 4
  344. hideLine: 0, // default: 0
  345. hideDots: 1, // default: 0
  346. heatline: 1, // default: 0
  347. areaFill: 1 // default: 0
  348. }
  349. axisOptions: {
  350. yAxisMode: 'span', // Axis lines, default
  351. xAxisMode: 'tick', // No axis lines, only short ticks
  352. xIsSeries: 1 // Allow skipping x values for space
  353. // default: 0
  354. },
  355. // Pie/Percentage charts
  356. maxLegendPoints: 6, // default: 20
  357. maxSlices: 10, // default: 20
  358. // Percentage chart
  359. barOptions: {
  360. height: 15 // default: 20
  361. depth: 5 // default: 2
  362. }
  363. // Heatmap
  364. discreteDomains: 1, // default: 1
  365. }
  366. ...
  367. // Updating values
  368. chart.update(data);
  369. // Axis charts:
  370. chart.addDataPoint(label, valueFromEachDataset, index)
  371. chart.removeDataPoint(index)
  372. chart.updateDataset(datasetValues, index)
  373. // Exporting
  374. chart.export();
  375. // Unbind window-resize events
  376. chart.unbindWindowEvents();
  377. `
  378. }
  379. ]
  380. },
  381. {
  382. title: "Install",
  383. name: "installation",
  384. contentBlocks: [
  385. { type: "text", content: 'Install via npm' },
  386. { type: "code", lang: "console", content: ` npm install frappe-charts` },
  387. { type: "text", content: 'And include it in your project' },
  388. { type: "code", lang: "javascript", content: ` import { Chart } from "frappe-charts` },
  389. { type: "text", content: 'Use as:' },
  390. {
  391. type: "code",
  392. lang: "javascript",
  393. content: ` new Chart(); // ES6 module
  394. // or
  395. new frappe.Chart(); // Browser`,
  396. },
  397. { type: "text", content: '... or include it directly in your HTML' },
  398. {
  399. type: "code",
  400. lang: "html",
  401. content: ` &lt;script src="https://unpkg.com/frappe-charts@1.1.0"&gt;&lt;/script&gt;`,
  402. },
  403. ]
  404. }
  405. ]