Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

437 wiersze
13 KiB

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