1. 1 : /* global Spyral, Highcharts */
  2. 2 :
  3. 3 : import NetworkGraph from './networkgraph';
  4. 4 :
  5. 5 : import Util from './util.js';
  6. 6 :
  7. 7 : /**
  8. 8 : * The Chart class in Spyral.
  9. 9 : * This class provides methods for creating a variety of charts.
  10. 10 : * Charts are created using the [Highcharts Library]{@link https://api.highcharts.com/highcharts/}.
  11. 11 : * Highcharts have many configuration options and Spyral.Chart helps to streamline the process.
  12. 12 : * A simple example:
  13. 13 : *
  14. 14 : * Spyral.Chart.line({ series: [{ data: [0,2,1,3] }] })
  15. 15 : *
  16. 16 : * A more complex example:
  17. 17 : *
  18. 18 : * Spyral.Chart.column({
  19. 19 : * title: 'Wildflowers',
  20. 20 : * series: [{
  21. 21 : * name: 'Ontario',
  22. 22 : * data: [13, 39, 139, 38]
  23. 23 : * },{
  24. 24 : * name: 'Quebec',
  25. 25 : * data: [14, 33, 94, 30]
  26. 26 : * }],
  27. 27 : * xAxis: {
  28. 28 : * title: 'Number of Petals',
  29. 29 : * categories: [3, 4, 5, 6]
  30. 30 : * }
  31. 31 : * })
  32. 32 : *
  33. 33 : * @memberof Spyral
  34. 34 : * @class
  35. 35 : */
  36. 36 : class Chart {
  37. 37 : /**
  38. 38 : * The Highcharts config object
  39. 39 : * @typedef {Object} Spyral.Chart~HighchartsConfig
  40. 40 : * @property {(string|object)} title
  41. 41 : * @property {(string|object)} subtitle
  42. 42 : * @property {Object} credits
  43. 43 : * @property {Object} xAxis
  44. 44 : * @property {Object} yAxis
  45. 45 : * @property {Object} chart
  46. 46 : * @property {Array<Spyral.Chart~HighchartsSeriesConfig>} series
  47. 47 : * @property {Object} plotOptions
  48. 48 : */
  49. 49 :
  50. 50 : /**
  51. 51 : * The series config object
  52. 52 : * @typedef {Object} Spyral.Chart~HighchartsSeriesConfig
  53. 53 : * @property {Array} data
  54. 54 : * @property {string} [name]
  55. 55 : */
  56. 56 :
  57. 57 : /**
  58. 58 : * Construct a new Chart class
  59. 59 : * @constructor
  60. 60 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  61. 61 : * @param {Array} data An array of data to visualize.
  62. 62 : */
  63. 63 : constructor(target, data) {
  64. 64 : if (Util.isNode(target)) {
  65. 65 : if (target.isConnected === false) {
  66. 66 : throw new Error('The target node does not exist within the document.');
  67. 67 : }
  68. 68 : } else if (Util.isString(target) === false) {
  69. 69 : data = target;
  70. 70 : target = undefined;
  71. 71 : }
  72. 72 : this.target = target;
  73. 73 : this.data = data;
  74. 74 : }
  75. 75 :
  76. 76 : /**
  77. 77 : * Create a new chart.
  78. 78 : * See [Highcharts API]{@link https://api.highcharts.com/highcharts/} for full set of config options.
  79. 79 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  80. 80 : * @param {Spyral.Chart~HighchartsConfig} config
  81. 81 : * @returns {Highcharts.Chart}
  82. 82 : */
  83. 83 : create(target, config) {
  84. 84 : [target, config] = Chart._handleTargetAndConfig(target, config);
  85. 85 : return Highcharts.chart(target, config);
  86. 86 : }
  87. 87 :
  88. 88 : /**
  89. 89 : * Create a new chart.
  90. 90 : * See [Highcharts API]{@link https://api.highcharts.com/highcharts/} for full set of config options.
  91. 91 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  92. 92 : * @param {Spyral.Chart~HighchartsConfig} config
  93. 93 : * @returns {Highcharts.Chart}
  94. 94 : * @static
  95. 95 : */
  96. 96 : static create(target, config) {
  97. 97 : [target, config] = Chart._handleTargetAndConfig(target, config);
  98. 98 : return Highcharts.chart(target, config);
  99. 99 : }
  100. 100 :
  101. 101 : static _handleTargetAndConfig(target, config) {
  102. 102 : if (Util.isNode(target) === false && typeof target === 'object') {
  103. 103 : config = target;
  104. 104 : target = undefined;
  105. 105 : }
  106. 106 :
  107. 107 : if (target === undefined) {
  108. 108 : if (typeof Spyral !== 'undefined' && Spyral.Notebook) {
  109. 109 : target = Spyral.Notebook.getTarget();
  110. 110 : if (target.clientHeight <= 40) {
  111. 111 : target.style.height = '400px'; // 400 is the default Highcharts height
  112. 112 : }
  113. 113 : } else {
  114. 114 : target = document.createElement('div');
  115. 115 : document.body.appendChild(target);
  116. 116 : }
  117. 117 : } else {
  118. 118 : if (Util.isNode(target) && target.isConnected === false) {
  119. 119 : throw new Error('The target node does not exist within the document.');
  120. 120 : }
  121. 121 : }
  122. 122 :
  123. 123 : // convert title and suppress if not provided
  124. 124 : if ('title' in config) {
  125. 125 : if (typeof config.title === 'string') {
  126. 126 : config.title = {text: config.title};
  127. 127 : }
  128. 128 : } else {
  129. 129 : config.title = false;
  130. 130 : }
  131. 131 :
  132. 132 : // convert subtitle and convert if not provided
  133. 133 : if ('subtitle' in config) {
  134. 134 : if (typeof config.subtitle === 'string') {
  135. 135 : config.subtitle = {text: config.subtitle};
  136. 136 : }
  137. 137 : } else {
  138. 138 : config.subtitle = false;
  139. 139 : }
  140. 140 :
  141. 141 : // convert credits
  142. 142 : if (!('credits' in config)) {
  143. 143 : config.credits = false;
  144. 144 : }
  145. 145 :
  146. 146 : // suppress xAxis title unless provided
  147. 147 : if (!('xAxis' in config)) {config.xAxis = {};}
  148. 148 : if (!('title' in config.xAxis)) {
  149. 149 : config.xAxis.title = false;
  150. 150 : } else if (typeof config.xAxis.title === 'string') {
  151. 151 : config.xAxis.title = {text: config.xAxis.title};
  152. 152 : }
  153. 153 :
  154. 154 : // suppress xAxis title unless provided
  155. 155 : if (!('yAxis' in config)) {config.yAxis = {};}
  156. 156 : if (!('title' in config.yAxis)) {
  157. 157 : config.yAxis.title = false;
  158. 158 : } else if (typeof config.yAxis.title === 'string') {
  159. 159 : config.yAxis.title = {text: config.yAxis.title};
  160. 160 : }
  161. 161 :
  162. 162 : return [target, config];
  163. 163 : }
  164. 164 :
  165. 165 : static _setDefaultChartType(config, type) {
  166. 166 : if ('type' in config) {
  167. 167 : config.chart.type = config.type;
  168. 168 : delete config.type;
  169. 169 : return;
  170. 170 : }
  171. 171 :
  172. 172 : // TODO: check plot options and series?
  173. 173 :
  174. 174 : if ('chart' in config) {
  175. 175 : if ('type' in config.chart) {return;} // already set
  176. 176 : } else {
  177. 177 : config.chart = {};
  178. 178 : }
  179. 179 :
  180. 180 : config.chart.type = type;
  181. 181 : return config;
  182. 182 : }
  183. 183 :
  184. 184 : /**
  185. 185 : * Add the provided data to the config as a series
  186. 186 : * @param {Spyral.Chart~HighchartsConfig} config
  187. 187 : * @param {Array} data
  188. 188 : * @static
  189. 189 : */
  190. 190 : static setSeriesData(config, data) {
  191. 191 : if (Array.isArray(data)) {
  192. 192 : if (Array.isArray(data[0])) {
  193. 193 : config.series = data.map(subArray => { return {data: subArray}; });
  194. 194 : } else {
  195. 195 : config.series = [{data: data}];
  196. 196 : }
  197. 197 : }
  198. 198 : }
  199. 199 :
  200. 200 : /**
  201. 201 : * Create a bar chart
  202. 202 : * @param {Spyral.Chart~HighchartsConfig} [config]
  203. 203 : * @returns {Highcharts.Chart}
  204. 204 : */
  205. 205 : bar(config={}) {
  206. 206 : Chart.setSeriesData(config, this.data);
  207. 207 : return Chart.bar(this.target, config);
  208. 208 : }
  209. 209 : /**
  210. 210 : * Create a bar chart
  211. 211 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  212. 212 : * @param {Spyral.Chart~HighchartsConfig} config
  213. 213 : * @returns {Highcharts.Chart}
  214. 214 : * @static
  215. 215 : */
  216. 216 : static bar(target, config) {
  217. 217 : [target, config] = Chart._handleTargetAndConfig(target, config);
  218. 218 : Chart._setDefaultChartType(config, 'bar');
  219. 219 : return Highcharts.chart(target, config);
  220. 220 : }
  221. 221 :
  222. 222 : /**
  223. 223 : * Create a column chart
  224. 224 : * @param {Spyral.Chart~HighchartsConfig} [config]
  225. 225 : * @returns {Highcharts.Chart}
  226. 226 : */
  227. 227 : column(config={}) {
  228. 228 : Chart.setSeriesData(config, this.data);
  229. 229 : return Chart.column(this.target, config);
  230. 230 : }
  231. 231 : /**
  232. 232 : * Create a column chart
  233. 233 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  234. 234 : * @param {Spyral.Chart~HighchartsConfig} config
  235. 235 : * @returns {Highcharts.Chart}
  236. 236 : * @static
  237. 237 : */
  238. 238 : static column(target, config) {
  239. 239 : [target, config] = Chart._handleTargetAndConfig(target, config);
  240. 240 : Chart._setDefaultChartType(config, 'column');
  241. 241 : return Highcharts.chart(target, config);
  242. 242 : }
  243. 243 :
  244. 244 : /**
  245. 245 : * Create a line chart
  246. 246 : * @param {Spyral.Chart~HighchartsConfig} [config]
  247. 247 : * @returns {Highcharts.Chart}
  248. 248 : */
  249. 249 : line(config={}) {
  250. 250 : Chart.setSeriesData(config, this.data);
  251. 251 : return Chart.line(this.target, config);
  252. 252 : }
  253. 253 : /**
  254. 254 : * Create a line chart
  255. 255 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  256. 256 : * @param {Spyral.Chart~HighchartsConfig} config
  257. 257 : * @returns {Highcharts.Chart}
  258. 258 : * @static
  259. 259 : */
  260. 260 : static line(target, config) {
  261. 261 : [target, config] = Chart._handleTargetAndConfig(target, config);
  262. 262 : Chart._setDefaultChartType(config, 'line');
  263. 263 : return Highcharts.chart(target, config);
  264. 264 : }
  265. 265 :
  266. 266 : /**
  267. 267 : * Create a pie chart
  268. 268 : * @param {Spyral.Chart~HighchartsConfig} [config]
  269. 269 : * @returns {Highcharts.Chart}
  270. 270 : */
  271. 271 : pie(config={}) {
  272. 272 : Chart.setSeriesData(config, this.data);
  273. 273 : return Chart.pie(this.target, config);
  274. 274 : }
  275. 275 : /**
  276. 276 : * Create a pie chart
  277. 277 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  278. 278 : * @param {Spyral.Chart~HighchartsConfig} config
  279. 279 : * @returns {Highcharts.Chart}
  280. 280 : * @static
  281. 281 : */
  282. 282 : static pie(target, config) {
  283. 283 : [target, config] = Chart._handleTargetAndConfig(target, config);
  284. 284 : Chart._setDefaultChartType(config, 'pie');
  285. 285 : return Highcharts.chart(target, config);
  286. 286 : }
  287. 287 :
  288. 288 : /**
  289. 289 : * Create a polar chart
  290. 290 : * @param {Spyral.Chart~HighchartsConfig} [config]
  291. 291 : * @returns {Highcharts.Chart}
  292. 292 : */
  293. 293 : polar(config={}) {
  294. 294 : Chart.setSeriesData(config, this.data);
  295. 295 : return Chart.polar(this.target, config);
  296. 296 : }
  297. 297 : /**
  298. 298 : * Create a polar chart
  299. 299 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  300. 300 : * @param {Spyral.Chart~HighchartsConfig} config
  301. 301 : * @returns {Highcharts.Chart}
  302. 302 : * @static
  303. 303 : */
  304. 304 : static polar(target, config) {
  305. 305 : [target, config] = Chart._handleTargetAndConfig(target, config);
  306. 306 : Chart._setDefaultChartType(config, 'polar');
  307. 307 : return Highcharts.chart(target, config);
  308. 308 : }
  309. 309 :
  310. 310 : /**
  311. 311 : * Create a scatter plot
  312. 312 : * @param {Spyral.Chart~HighchartsConfig} [config]
  313. 313 : * @returns {Highcharts.Chart}
  314. 314 : */
  315. 315 : scatter(config={}) {
  316. 316 : Chart.setSeriesData(config, this.data);
  317. 317 : return Chart.scatter(this.target, config);
  318. 318 : }
  319. 319 : /**
  320. 320 : * Create a scatter plot
  321. 321 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  322. 322 : * @param {Spyral.Chart~HighchartsConfig} config
  323. 323 : * @returns {Highcharts.Chart}
  324. 324 : * @static
  325. 325 : */
  326. 326 : static scatter(target, config) {
  327. 327 : [target, config] = Chart._handleTargetAndConfig(target, config);
  328. 328 : Chart._setDefaultChartType(config, 'scatter');
  329. 329 : return Highcharts.chart(target, config);
  330. 330 : }
  331. 331 :
  332. 332 : /**
  333. 333 : * Create a network graph
  334. 334 : * @param {NetworkGraph~Config} [config]
  335. 335 : * @returns {NetworkGraph}
  336. 336 : */
  337. 337 : networkgraph(config={}) {
  338. 338 : Chart.setSeriesData(config, this.data);
  339. 339 : return Chart.networkgraph(this.target, config);
  340. 340 : }
  341. 341 : /**
  342. 342 : * Create a network graph
  343. 343 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  344. 344 : * @param {NetworkGraph~Config} config
  345. 345 : * @returns {NetworkGraph}
  346. 346 : * @static
  347. 347 : */
  348. 348 : static networkgraph(target, config) {
  349. 349 : [target, config] = Chart._handleTargetAndConfig(target, config);
  350. 350 : return new NetworkGraph(target, config);
  351. 351 : }
  352. 352 :
  353. 353 : static _loadHighchartsModule(moduleName) {
  354. 354 : return Util.loadScript(`../resources/highcharts/11/modules/${moduleName}.js`);
  355. 355 : }
  356. 356 :
  357. 357 : /**
  358. 358 : * Create an arc-diagram chart
  359. 359 : * @param {Spyral.Chart~HighchartsConfig} [config]
  360. 360 : * @returns {Promise}
  361. 361 : */
  362. 362 : arcdiagram(config={}) {
  363. 363 : Chart.setSeriesData(config, this.data);
  364. 364 : return Chart.arcdiagram(this.target, config);
  365. 365 : }
  366. 366 : /**
  367. 367 : * Create an arc-diagram chart
  368. 368 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  369. 369 : * @param {Spyral.Chart~HighchartsConfig} config
  370. 370 : * @returns {Promise}
  371. 371 : * @static
  372. 372 : */
  373. 373 : static async arcdiagram(target, config) {
  374. 374 : [target, config] = Chart._handleTargetAndConfig(target, config);
  375. 375 : Chart._setDefaultChartType(config, 'arcdiagram');
  376. 376 : await Chart._loadHighchartsModule('arc-diagram');
  377. 377 : return Highcharts.chart(target, config);
  378. 378 : }
  379. 379 :
  380. 380 : /**
  381. 381 : * Create a dependency wheel chart
  382. 382 : * @param {Spyral.Chart~HighchartsConfig} [config]
  383. 383 : * @returns {Promise}
  384. 384 : */
  385. 385 : dependencywheel(config={}) {
  386. 386 : Chart.setSeriesData(config, this.data);
  387. 387 : return Chart.dependencywheel(this.target, config);
  388. 388 : }
  389. 389 : /**
  390. 390 : * Create a dependency wheel chart
  391. 391 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  392. 392 : * @param {Spyral.Chart~HighchartsConfig} config
  393. 393 : * @returns {Promise}
  394. 394 : * @static
  395. 395 : */
  396. 396 : static async dependencywheel(target, config) {
  397. 397 : [target, config] = Chart._handleTargetAndConfig(target, config);
  398. 398 : Chart._setDefaultChartType(config, 'dependencywheel');
  399. 399 : await Chart._loadHighchartsModule('sankey');
  400. 400 : await Chart._loadHighchartsModule('dependency-wheel');
  401. 401 : return Highcharts.chart(target, config);
  402. 402 : }
  403. 403 :
  404. 404 : /**
  405. 405 : * Create a dumbbell chart
  406. 406 : * @param {Spyral.Chart~HighchartsConfig} [config]
  407. 407 : * @returns {Promise}
  408. 408 : */
  409. 409 : dumbbell(config={}) {
  410. 410 : Chart.setSeriesData(config, this.data);
  411. 411 : return Chart.dumbbell(this.target, config);
  412. 412 : }
  413. 413 : /**
  414. 414 : * Create a dumbbell chart
  415. 415 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  416. 416 : * @param {Spyral.Chart~HighchartsConfig} config
  417. 417 : * @returns {Promise}
  418. 418 : * @static
  419. 419 : */
  420. 420 : static async dumbbell(target, config) {
  421. 421 : [target, config] = Chart._handleTargetAndConfig(target, config);
  422. 422 : Chart._setDefaultChartType(config, 'dumbbell');
  423. 423 : await Chart._loadHighchartsModule('dumbbell');
  424. 424 : return Highcharts.chart(target, config);
  425. 425 : }
  426. 426 :
  427. 427 : /**
  428. 428 : * Create a heatmap chart
  429. 429 : * @param {Spyral.Chart~HighchartsConfig} [config]
  430. 430 : * @returns {Promise}
  431. 431 : */
  432. 432 : heatmap(config={}) {
  433. 433 : Chart.setSeriesData(config, this.data);
  434. 434 : return Chart.heatmap(this.target, config);
  435. 435 : }
  436. 436 : /**
  437. 437 : * Create a heatmap chart
  438. 438 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  439. 439 : * @param {Spyral.Chart~HighchartsConfig} config
  440. 440 : * @returns {Promise}
  441. 441 : * @static
  442. 442 : */
  443. 443 : static async heatmap(target, config) {
  444. 444 : [target, config] = Chart._handleTargetAndConfig(target, config);
  445. 445 : Chart._setDefaultChartType(config, 'heatmap');
  446. 446 : await Chart._loadHighchartsModule('heatmap');
  447. 447 : return Highcharts.chart(target, config);
  448. 448 : }
  449. 449 :
  450. 450 : /**
  451. 451 : * Create a histogram chart
  452. 452 : * @param {Spyral.Chart~HighchartsConfig} [config]
  453. 453 : * @returns {Promise}
  454. 454 : */
  455. 455 : histogram(config={}) {
  456. 456 : Chart.setSeriesData(config, this.data);
  457. 457 : return Chart.histogram(this.target, config);
  458. 458 : }
  459. 459 : /**
  460. 460 : * Create a histogram chart
  461. 461 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  462. 462 : * @param {Spyral.Chart~HighchartsConfig} config
  463. 463 : * @returns {Promise}
  464. 464 : * @static
  465. 465 : */
  466. 466 : static async histogram(target, config) {
  467. 467 : [target, config] = Chart._handleTargetAndConfig(target, config);
  468. 468 : Chart._setDefaultChartType(config, 'histogram');
  469. 469 : await Chart._loadHighchartsModule('histogram-bellcurve');
  470. 470 : return Highcharts.chart(target, config);
  471. 471 : }
  472. 472 :
  473. 473 : /**
  474. 474 : * Create an item chart
  475. 475 : * @param {Spyral.Chart~HighchartsConfig} [config]
  476. 476 : * @returns {Promise}
  477. 477 : */
  478. 478 : item(config={}) {
  479. 479 : Chart.setSeriesData(config, this.data);
  480. 480 : return Chart.item(this.target, config);
  481. 481 : }
  482. 482 : /**
  483. 483 : * Create an item chart
  484. 484 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  485. 485 : * @param {Spyral.Chart~HighchartsConfig} config
  486. 486 : * @returns {Promise}
  487. 487 : * @static
  488. 488 : */
  489. 489 : static async item(target, config) {
  490. 490 : [target, config] = Chart._handleTargetAndConfig(target, config);
  491. 491 : Chart._setDefaultChartType(config, 'item');
  492. 492 : await Chart._loadHighchartsModule('item-series');
  493. 493 : return Highcharts.chart(target, config);
  494. 494 : }
  495. 495 :
  496. 496 : /**
  497. 497 : * Create a map chart
  498. 498 : * @param {Spyral.Chart~HighchartsConfig} [config]
  499. 499 : * @returns {Promise}
  500. 500 : */
  501. 501 : map(config={}) {
  502. 502 : Chart.setSeriesData(config, this.data);
  503. 503 : return Chart.map(this.target, config);
  504. 504 : }
  505. 505 : /**
  506. 506 : * Create a map chart
  507. 507 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  508. 508 : * @param {Spyral.Chart~HighchartsConfig} config
  509. 509 : * @returns {Promise}
  510. 510 : * @static
  511. 511 : */
  512. 512 : static async map(target, config) {
  513. 513 : [target, config] = Chart._handleTargetAndConfig(target, config);
  514. 514 : Chart._setDefaultChartType(config, 'map');
  515. 515 : await Chart._loadHighchartsModule('map');
  516. 516 : return Highcharts.mapChart(target, config);
  517. 517 : }
  518. 518 :
  519. 519 : /**
  520. 520 : * Create a sankey chart
  521. 521 : * @param {Spyral.Chart~HighchartsConfig} [config]
  522. 522 : * @returns {Promise}
  523. 523 : */
  524. 524 : sankey(config={}) {
  525. 525 : Chart.setSeriesData(config, this.data);
  526. 526 : return Chart.sankey(this.target, config);
  527. 527 : }
  528. 528 : /**
  529. 529 : * Create a sankey chart
  530. 530 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  531. 531 : * @param {Spyral.Chart~HighchartsConfig} config
  532. 532 : * @returns {Promise}
  533. 533 : * @static
  534. 534 : */
  535. 535 : static async sankey(target, config) {
  536. 536 : [target, config] = Chart._handleTargetAndConfig(target, config);
  537. 537 : Chart._setDefaultChartType(config, 'sankey');
  538. 538 : await Chart._loadHighchartsModule('sankey');
  539. 539 : return Highcharts.chart(target, config);
  540. 540 : }
  541. 541 :
  542. 542 : /**
  543. 543 : * Create a streamgraph chart
  544. 544 : * @param {Spyral.Chart~HighchartsConfig} [config]
  545. 545 : * @returns {Promise}
  546. 546 : */
  547. 547 : streamgraph(config={}) {
  548. 548 : Chart.setSeriesData(config, this.data);
  549. 549 : return Chart.streamgraph(this.target, config);
  550. 550 : }
  551. 551 : /**
  552. 552 : * Create a streamgraph chart
  553. 553 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  554. 554 : * @param {Spyral.Chart~HighchartsConfig} config
  555. 555 : * @returns {Promise}
  556. 556 : * @static
  557. 557 : */
  558. 558 : static async streamgraph(target, config) {
  559. 559 : [target, config] = Chart._handleTargetAndConfig(target, config);
  560. 560 : Chart._setDefaultChartType(config, 'streamgraph');
  561. 561 : await Chart._loadHighchartsModule('streamgraph');
  562. 562 : return Highcharts.chart(target, config);
  563. 563 : }
  564. 564 :
  565. 565 : /**
  566. 566 : * Create a sunburst chart
  567. 567 : * @param {Spyral.Chart~HighchartsConfig} [config]
  568. 568 : * @returns {Promise}
  569. 569 : */
  570. 570 : sunburst(config={}) {
  571. 571 : Chart.setSeriesData(config, this.data);
  572. 572 : return Chart.sunburst(this.target, config);
  573. 573 : }
  574. 574 : /**
  575. 575 : * Create a sunburst chart
  576. 576 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  577. 577 : * @param {Spyral.Chart~HighchartsConfig} config
  578. 578 : * @returns {Promise}
  579. 579 : * @static
  580. 580 : */
  581. 581 : static async sunburst(target, config) {
  582. 582 : [target, config] = Chart._handleTargetAndConfig(target, config);
  583. 583 : Chart._setDefaultChartType(config, 'sunburst');
  584. 584 : await Chart._loadHighchartsModule('sunburst');
  585. 585 : return Highcharts.chart(target, config);
  586. 586 : }
  587. 587 :
  588. 588 : /**
  589. 589 : * Create a treegraph chart
  590. 590 : * @param {Spyral.Chart~HighchartsConfig} config
  591. 591 : * @returns {Promise}
  592. 592 : */
  593. 593 : treegraph(config={}) {
  594. 594 : Chart.setSeriesData(config, this.data);
  595. 595 : return Chart.treegraph(this.target, config);
  596. 596 : }
  597. 597 : /**
  598. 598 : * Create a treegraph chart
  599. 599 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  600. 600 : * @param {Spyral.Chart~HighchartsConfig} config
  601. 601 : * @returns {Promise}
  602. 602 : * @static
  603. 603 : */
  604. 604 : static async treegraph(target, config) {
  605. 605 : [target, config] = Chart._handleTargetAndConfig(target, config);
  606. 606 : Chart._setDefaultChartType(config, 'treegraph');
  607. 607 : await Chart._loadHighchartsModule('treemap');
  608. 608 : await Chart._loadHighchartsModule('treegraph');
  609. 609 : return Highcharts.chart(target, config);
  610. 610 : }
  611. 611 :
  612. 612 : /**
  613. 613 : * Create a treemap chart
  614. 614 : * @param {Spyral.Chart~HighchartsConfig} [config]
  615. 615 : * @returns {Promise}
  616. 616 : */
  617. 617 : treemap(config={}) {
  618. 618 : Chart.setSeriesData(config, this.data);
  619. 619 : return Chart.treemap(this.target, config);
  620. 620 : }
  621. 621 : /**
  622. 622 : * Create a treemap chart
  623. 623 : * @param {(String|Element)} [target] An element or ID to use as the chart's target. If not specified, one will be created.
  624. 624 : * @param {Spyral.Chart~HighchartsConfig} config
  625. 625 : * @returns {Promise}
  626. 626 : * @static
  627. 627 : */
  628. 628 : static async treemap(target, config) {
  629. 629 : [target, config] = Chart._handleTargetAndConfig(target, config);
  630. 630 : Chart._setDefaultChartType(config, 'treemap');
  631. 631 : await Chart._loadHighchartsModule('treemap');
  632. 632 : return Highcharts.chart(target, config);
  633. 633 : }
  634. 634 : }
  635. 635 :
  636. 636 : export default Chart;