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.
 
 
 

345 lines
10 KiB

  1. import { lineCompositeData, barCompositeData, typeData, trendsData, heatmapData } from './data';
  2. import { HEATMAP_COLORS_YELLOW, HEATMAP_COLORS_BLUE } from '../../../src/js/utils/constants';
  3. export default {
  4. 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. 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. demoMain: {
  34. title: "Create a Chart",
  35. contentBlocks: [
  36. {
  37. type: "code",
  38. lang: "html",
  39. content: ` &lt!--HTML-->
  40. <figure id="frost-chart"></figure>`,
  41. },
  42. {
  43. type: "code",
  44. lang: "javascript",
  45. content: ` // Javascript
  46. let chart = new frappe.Chart( "#frost-chart", { // or DOM element
  47. data: {
  48. labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm",
  49. "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"],
  50. datasets: [
  51. {
  52. name: "Some Data", chartType: 'bar',
  53. values: [25, 40, 30, 35, 8, 52, 17, -4]
  54. },
  55. {
  56. name: "Another Set", chartType: 'bar',
  57. values: [25, 50, -10, 15, 18, 32, 27, 14]
  58. },
  59. {
  60. name: "Yet Another", chartType: 'line',
  61. values: [15, 20, -3, -15, 58, 12, -17, 37]
  62. }
  63. ],
  64. yMarkers: [{ label: "Marker", value: 70,
  65. options: { labelPos: 'left' }}],
  66. yRegions: [{ label: "Region", start: -10, end: 50,
  67. options: { labelPos: 'right' }}]
  68. },
  69. title: "My Awesome Chart",
  70. type: 'axis-mixed', // or 'bar', 'line', 'pie', 'percentage'
  71. height: 300,
  72. colors: ['purple', '#ffa3ef', 'light-blue'],
  73. tooltipOptions: {
  74. formatTooltipX: d => (d + '').toUpperCase(),
  75. formatTooltipY: d => d + ' pts',
  76. }
  77. });
  78. chart.export();`,
  79. },
  80. {
  81. type: "demo",
  82. config: {
  83. title: "My Awesome Chart",
  84. data: typeData,
  85. type: "axis-mixed",
  86. height: 300,
  87. colors: ["purple", "magenta", "light-blue"],
  88. maxSlices: 10,
  89. tooltipOptions: {
  90. formatTooltipX: d => (d + '').toUpperCase(),
  91. formatTooltipY: d => d + ' pts',
  92. }
  93. },
  94. options: [
  95. {
  96. name: "type",
  97. path: ["type"],
  98. type: "string",
  99. states: {
  100. "Mixed": 'axis-mixed',
  101. "Line": 'line',
  102. "Bar": 'bar',
  103. "Pie Chart": 'pie',
  104. "Percentage Chart": 'percentage',
  105. },
  106. activeState: "Mixed"
  107. }
  108. ],
  109. actions: [{ name: "Export ...", fn: "export", args: [] }],
  110. }
  111. ]
  112. },
  113. updateValues: { },
  114. trendsPlot: {
  115. title: "Plot Trends",
  116. contentBlocks: [
  117. {
  118. type: "demo",
  119. config: {
  120. title: "Mean Total Sunspot Count - Yearly",
  121. data: trendsData,
  122. type: 'line',
  123. height: 300,
  124. colors: ['#238e38'],
  125. axisOptions: {
  126. xAxisMode: 'tick',
  127. yAxisMode: 'span',
  128. xIsSeries: 1
  129. }
  130. },
  131. options: [
  132. {
  133. name: "lineOptions",
  134. path: ["lineOptions"],
  135. type: "map",
  136. mapKeys: ['hideLine', 'hideDots', 'heatline', 'regionFill'],
  137. states: {
  138. "Line": [0, 1, 0, 0],
  139. "Dots": [1, 0, 0, 0],
  140. "HeatLine": [0, 1, 1, 0],
  141. "Region": [0, 1, 0, 1]
  142. },
  143. activeState: "HeatLine"
  144. }
  145. ],
  146. actions: [{ name: "Export ...", fn: "export", args: [] }]
  147. }
  148. ],
  149. },
  150. stateChange: {},
  151. heatmap: {
  152. title: "And a Month-wise Heatmap",
  153. contentBlocks: [
  154. {
  155. type: "demo",
  156. config: {
  157. title: "Monthly Distribution",
  158. data: heatmapData,
  159. type: 'heatmap',
  160. discreteDomains: 1,
  161. countLabel: 'Level',
  162. colors: HEATMAP_COLORS_BLUE,
  163. legendScale: [0, 1, 2, 4, 5]
  164. },
  165. options: [
  166. {
  167. name: "Discrete domains",
  168. path: ["discreteDomains"],
  169. type: 'boolean',
  170. // boolNames: ["Continuous", "Discrete"],
  171. states: { "Discrete": 1, "Continuous": 0 }
  172. },
  173. {
  174. name: "Colors",
  175. path: ["colors"],
  176. type: "object",
  177. states: {
  178. "Green (Default)": [],
  179. "Blue": HEATMAP_COLORS_BLUE,
  180. "GitHub's Halloween": HEATMAP_COLORS_YELLOW
  181. }
  182. }
  183. ],
  184. actions: [{ name: "Export ...", fn: "export", args: [] }]
  185. },
  186. {
  187. type: "code",
  188. lang: "javascript",
  189. content: ` let heatmap = new frappe.Chart("#heatmap", {
  190. type: 'heatmap',
  191. title: "Monthly Distribution",
  192. data: {
  193. dataPoints: {'1524064033': 8, /* ... */},
  194. // object with timestamp-value pairs
  195. start: startDate
  196. end: endDate // Date objects
  197. },
  198. countLabel: 'Level',
  199. discreteDomains: 0 // default: 1
  200. colors: ['#ebedf0', '#c0ddf9', '#73b3f3', '#3886e1', '#17459e'],
  201. // Set of five incremental colors,
  202. // preferably with a low-saturation color for zero data;
  203. // def: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127']
  204. });`,
  205. }
  206. ],
  207. },
  208. codePenDemo: {
  209. title: "Demo",
  210. contentBlocks: [
  211. {
  212. type: "custom",
  213. html: `<p data-height="299" data-theme-id="light" data-slug-hash="wjKBoq" data-default-tab="js,result"
  214. data-user="pratu16x7" data-embed-version="2" data-pen-title="Frappe Charts Demo" class="codepen">
  215. See the Pen <a href="https://codepen.io/pratu16x7/pen/wjKBoq/">Frappe Charts Demo</a>
  216. by Prateeksha Singh (<a href="https://codepen.io/pratu16x7">@pratu16x7</a>) on
  217. <a href="https://codepen.io">CodePen</a>.
  218. </p>`
  219. }
  220. ]
  221. },
  222. optionsList: {
  223. title: "Available Options",
  224. contentBlocks: [
  225. {
  226. type: "code",
  227. lang: "javascript",
  228. content: `
  229. ...
  230. {
  231. data: {
  232. labels: [],
  233. datasets: [],
  234. yRegions: [],
  235. yMarkers: []
  236. }
  237. title: '',
  238. colors: [],
  239. height: 200,
  240. tooltipOptions: {
  241. formatTooltipX: d => (d + '').toUpperCase(),
  242. formatTooltipY: d => d + ' pts',
  243. }
  244. // Axis charts
  245. isNavigable: 1, // default: 0
  246. valuesOverPoints: 1, // default: 0
  247. barOptions: {
  248. spaceRatio: 1 // default: 0.5
  249. stacked: 1 // default: 0
  250. }
  251. lineOptions: {
  252. dotSize: 6, // default: 4
  253. hideLine: 0, // default: 0
  254. hideDots: 1, // default: 0
  255. heatline: 1, // default: 0
  256. regionFill: 1 // default: 0
  257. }
  258. axisOptions: {
  259. yAxisMode: 'span', // Axis lines, default
  260. xAxisMode: 'tick', // No axis lines, only short ticks
  261. xIsSeries: 1 // Allow skipping x values for space
  262. // default: 0
  263. },
  264. // Pie/Percentage charts
  265. maxLegendPoints: 6, // default: 20
  266. maxSlices: 10, // default: 20
  267. // Percentage chart
  268. barOptions: {
  269. height: 15 // default: 20
  270. depth: 5 // default: 2
  271. }
  272. // Heatmap
  273. discreteDomains: 1, // default: 1
  274. }
  275. ...
  276. // Updating values
  277. chart.update(data);
  278. // Axis charts:
  279. chart.addDataPoint(label, valueFromEachDataset, index)
  280. chart.removeDataPoint(index)
  281. chart.updateDataset(datasetValues, index)
  282. // Exporting
  283. chart.export();
  284. // Unbind window-resize events
  285. chart.unbindWindowEvents();
  286. `
  287. }
  288. ]
  289. },
  290. installation: {
  291. title: "Install",
  292. contentBlocks: [
  293. { type: "text", content: 'Install via npm' },
  294. { type: "code", lang: "console", content: ` npm install frappe-charts` },
  295. { type: "text", content: 'And include it in your project' },
  296. { type: "code", lang: "javascript", content: ` import { Chart } from "frappe-charts` },
  297. { type: "text", content: 'Use as:' },
  298. {
  299. type: "code",
  300. lang: "javascript",
  301. content: ` new Chart(); // ES6 module
  302. // or
  303. new frappe.Chart(); // Browser`,
  304. },
  305. { type: "text", content: '... or include it directly in your HTML' },
  306. {
  307. type: "code",
  308. lang: "html",
  309. content: ` &lt;script src="https://unpkg.com/frappe-charts@1.1.0"&gt;&lt;/script&gt;`,
  310. },
  311. ]
  312. }
  313. }