apexcharts 8.0.1 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/README.md +14 -8
  2. package/dist/apexcharts.common.js +2 -2
  3. package/dist/apexcharts.core.js +2310 -2274
  4. package/dist/apexcharts.core.min.js +2 -2
  5. package/dist/apexcharts.esm.js +1367 -1110
  6. package/dist/apexcharts.full.js +3880 -3531
  7. package/dist/apexcharts.full.min.js +2 -2
  8. package/dist/apexcharts.js +3676 -3409
  9. package/dist/apexcharts.min.js +2 -2
  10. package/dist/apexcharts.ssr.common.js +2 -2
  11. package/dist/apexcharts.ssr.esm.js +4114 -3591
  12. package/dist/area.common.js +2 -2
  13. package/dist/area.esm.js +25 -67
  14. package/dist/bar.common.js +2 -2
  15. package/dist/bar.esm.js +159 -163
  16. package/dist/bar.js +2 -2
  17. package/dist/boxPlot.common.js +2 -2
  18. package/dist/boxPlot.esm.js +125 -106
  19. package/dist/bubble.common.js +2 -2
  20. package/dist/bubble.esm.js +25 -67
  21. package/dist/candlestick.common.js +2 -2
  22. package/dist/candlestick.esm.js +125 -106
  23. package/dist/candlestick.js +2 -2
  24. package/dist/column.common.js +2 -2
  25. package/dist/column.esm.js +159 -163
  26. package/dist/core.common.js +2 -2
  27. package/dist/core.esm.js +2310 -2274
  28. package/dist/donut.common.js +2 -2
  29. package/dist/donut.esm.js +100 -78
  30. package/dist/dumbbell.common.js +2 -2
  31. package/dist/dumbbell.esm.js +192 -167
  32. package/dist/features/all.common.js +2 -2
  33. package/dist/features/all.esm.js +945 -640
  34. package/dist/features/annotations.common.js +2 -2
  35. package/dist/features/annotations.esm.js +46 -21
  36. package/dist/features/annotations.js +2 -2
  37. package/dist/features/context-menu.common.js +1 -1
  38. package/dist/features/context-menu.esm.js +1 -1
  39. package/dist/features/context-menu.js +1 -1
  40. package/dist/features/drilldown.common.js +2 -2
  41. package/dist/features/drilldown.esm.js +22 -2
  42. package/dist/features/drilldown.js +2 -2
  43. package/dist/features/dumbbell.common.js +2 -2
  44. package/dist/features/dumbbell.esm.js +34 -5
  45. package/dist/features/dumbbell.js +2 -2
  46. package/dist/features/exports.common.js +2 -2
  47. package/dist/features/exports.esm.js +203 -204
  48. package/dist/features/exports.js +2 -2
  49. package/dist/features/facet.common.js +1 -1
  50. package/dist/features/facet.esm.js +1 -1
  51. package/dist/features/facet.js +1 -1
  52. package/dist/features/highlight-filter.common.js +2 -2
  53. package/dist/features/highlight-filter.esm.js +97 -41
  54. package/dist/features/highlight-filter.js +2 -2
  55. package/dist/features/history.common.js +2 -2
  56. package/dist/features/history.esm.js +4 -3
  57. package/dist/features/history.js +2 -2
  58. package/dist/features/ink.common.js +1 -1
  59. package/dist/features/ink.esm.js +1 -1
  60. package/dist/features/ink.js +1 -1
  61. package/dist/features/keyboard.common.js +2 -2
  62. package/dist/features/keyboard.esm.js +20 -23
  63. package/dist/features/keyboard.js +2 -2
  64. package/dist/features/legend.common.js +2 -2
  65. package/dist/features/legend.esm.js +61 -41
  66. package/dist/features/legend.js +2 -2
  67. package/dist/features/link.common.js +2 -2
  68. package/dist/features/link.esm.js +8 -8
  69. package/dist/features/link.js +2 -2
  70. package/dist/features/marks.common.js +2 -2
  71. package/dist/features/marks.esm.js +1 -1
  72. package/dist/features/marks.js +1 -1
  73. package/dist/features/measure.common.js +1 -1
  74. package/dist/features/measure.esm.js +1 -1
  75. package/dist/features/measure.js +1 -1
  76. package/dist/features/morph.common.js +2 -2
  77. package/dist/features/morph.esm.js +260 -279
  78. package/dist/features/morph.js +2 -2
  79. package/dist/features/perspectives.common.js +2 -2
  80. package/dist/features/perspectives.esm.js +28 -19
  81. package/dist/features/perspectives.js +2 -2
  82. package/dist/features/raincloud.common.js +2 -2
  83. package/dist/features/raincloud.esm.js +54 -36
  84. package/dist/features/raincloud.js +2 -2
  85. package/dist/features/renderer-canvas.common.js +1 -1
  86. package/dist/features/renderer-canvas.esm.js +1 -1
  87. package/dist/features/renderer-canvas.js +1 -1
  88. package/dist/features/stats.common.js +2 -2
  89. package/dist/features/stats.esm.js +66 -18
  90. package/dist/features/stats.js +2 -2
  91. package/dist/features/storyboard.common.js +2 -2
  92. package/dist/features/storyboard.esm.js +24 -15
  93. package/dist/features/storyboard.js +2 -2
  94. package/dist/features/streamgraph.common.js +2 -2
  95. package/dist/features/streamgraph.esm.js +34 -5
  96. package/dist/features/streamgraph.js +2 -2
  97. package/dist/features/toolbar.common.js +2 -2
  98. package/dist/features/toolbar.esm.js +211 -217
  99. package/dist/features/toolbar.js +2 -2
  100. package/dist/features/trellis.common.js +2 -2
  101. package/dist/features/trellis.esm.js +31 -19
  102. package/dist/features/trellis.js +2 -2
  103. package/dist/features/waterfall.common.js +2 -2
  104. package/dist/features/waterfall.esm.js +34 -5
  105. package/dist/features/waterfall.js +2 -2
  106. package/dist/features/weave.common.js +2 -2
  107. package/dist/features/weave.esm.js +290 -48
  108. package/dist/features/weave.js +2 -2
  109. package/dist/full.common.js +2 -2
  110. package/dist/full.esm.js +289 -150
  111. package/dist/heatmap.common.js +2 -2
  112. package/dist/heatmap.esm.js +48 -17
  113. package/dist/heatmap.js +2 -2
  114. package/dist/histogram.common.js +2 -2
  115. package/dist/histogram.esm.js +224 -180
  116. package/dist/icicle.common.js +2 -2
  117. package/dist/icicle.esm.js +1 -1
  118. package/dist/icicle.js +1 -1
  119. package/dist/line.common.js +2 -2
  120. package/dist/line.esm.js +25 -67
  121. package/dist/line.js +2 -2
  122. package/dist/pictograms.common.js +1 -1
  123. package/dist/pictograms.esm.js +1 -1
  124. package/dist/pictograms.js +1 -1
  125. package/dist/pie.common.js +2 -2
  126. package/dist/pie.esm.js +100 -78
  127. package/dist/pie.js +2 -2
  128. package/dist/polarArea.common.js +2 -2
  129. package/dist/polarArea.esm.js +100 -78
  130. package/dist/radar.common.js +2 -2
  131. package/dist/radar.esm.js +8 -5
  132. package/dist/radar.js +2 -2
  133. package/dist/radialBar.common.js +2 -2
  134. package/dist/radialBar.esm.js +166 -133
  135. package/dist/radialBar.js +2 -2
  136. package/dist/raincloud.common.js +2 -2
  137. package/dist/raincloud.esm.js +55 -42
  138. package/dist/rangeArea.common.js +2 -2
  139. package/dist/rangeArea.esm.js +25 -67
  140. package/dist/rangeBar.common.js +2 -2
  141. package/dist/rangeBar.esm.js +159 -163
  142. package/dist/scatter.common.js +2 -2
  143. package/dist/scatter.esm.js +25 -67
  144. package/dist/streamgraph.common.js +2 -2
  145. package/dist/streamgraph.esm.js +58 -71
  146. package/dist/sunburst.common.js +2 -2
  147. package/dist/sunburst.esm.js +1 -1
  148. package/dist/sunburst.js +1 -1
  149. package/dist/treemap.common.js +2 -2
  150. package/dist/treemap.esm.js +28 -90
  151. package/dist/treemap.js +2 -2
  152. package/dist/unit-shapes.common.js +2 -2
  153. package/dist/unit-shapes.esm.js +1 -1
  154. package/dist/unit-shapes.js +1 -1
  155. package/dist/unit.common.js +2 -2
  156. package/dist/unit.esm.js +30 -6
  157. package/dist/unit.js +2 -2
  158. package/dist/violin.common.js +2 -2
  159. package/dist/violin.esm.js +2 -7
  160. package/dist/violin.js +2 -2
  161. package/dist/waterfall.common.js +2 -2
  162. package/dist/waterfall.esm.js +192 -167
  163. package/package.json +3 -1
  164. package/src/apexcharts.js +260 -201
  165. package/src/charts/Bar.js +16 -5
  166. package/src/charts/BarStacked.js +42 -88
  167. package/src/charts/BoxCandleStick.js +1 -7
  168. package/src/charts/HeatMap.js +73 -16
  169. package/src/charts/Line.js +21 -71
  170. package/src/charts/Pie.js +142 -89
  171. package/src/charts/Radar.js +4 -1
  172. package/src/charts/Radial.js +91 -63
  173. package/src/charts/RangeBar.js +1 -7
  174. package/src/charts/Treemap.js +25 -78
  175. package/src/charts/Unit.js +28 -10
  176. package/src/charts/Violin.js +1 -7
  177. package/src/charts/common/Hierarchy.js +0 -22
  178. package/src/charts/common/OuterLabels.js +12 -5
  179. package/src/charts/common/Stats.js +55 -28
  180. package/src/charts/common/bar/DataLabels.js +94 -83
  181. package/src/charts/common/bar/Helpers.js +34 -57
  182. package/src/charts/common/circle/Helpers.js +5 -2
  183. package/src/charts/common/treemap/Helpers.js +1 -1
  184. package/src/entries/full.js +0 -17
  185. package/src/features/link.js +9 -10
  186. package/src/features/perspectives.js +20 -19
  187. package/src/features/raincloud.js +51 -53
  188. package/src/features/stats.js +23 -35
  189. package/src/libs/Treemap-squared.js +7 -47
  190. package/src/modules/Animations.js +55 -73
  191. package/src/modules/Base.js +3 -2
  192. package/src/modules/ChartFactory.js +6 -1
  193. package/src/modules/Core.js +57 -30
  194. package/src/modules/CoreUtils.js +32 -33
  195. package/src/modules/Crosshairs.js +29 -11
  196. package/src/modules/Data.js +279 -153
  197. package/src/modules/DataLabels.js +18 -2
  198. package/src/modules/Events.js +1 -4
  199. package/src/modules/Exports.js +284 -305
  200. package/src/modules/Fill.js +23 -10
  201. package/src/modules/Formatters.js +14 -3
  202. package/src/modules/Graphics.js +8 -14
  203. package/src/modules/MorphPieces.js +4 -2
  204. package/src/modules/MorphTypeChange.js +332 -316
  205. package/src/modules/Range.js +56 -99
  206. package/src/modules/Responsive.js +186 -61
  207. package/src/modules/Scales.js +4 -47
  208. package/src/modules/Series.js +14 -45
  209. package/src/modules/Theme.js +108 -57
  210. package/src/modules/Toolbar.js +7 -13
  211. package/src/modules/accessibility/KeyboardNavigation.js +29 -28
  212. package/src/modules/animations/AxisTransition.js +54 -16
  213. package/src/modules/animations/CircleTransition.js +1 -4
  214. package/src/modules/animations/DataLabelTransition.js +15 -10
  215. package/src/modules/animations/StreamScroll.js +6 -4
  216. package/src/modules/annotations/Annotations.js +18 -17
  217. package/src/modules/annotations/Helpers.js +41 -17
  218. package/src/modules/axes/XAxis.js +4 -4
  219. package/src/modules/axes/YAxis.js +1 -6
  220. package/src/modules/dimensions/Dimensions.js +12 -7
  221. package/src/modules/dimensions/Grid.js +15 -3
  222. package/src/modules/dimensions/YAxis.js +7 -6
  223. package/src/modules/drilldown/Drilldown.js +22 -1
  224. package/src/modules/dumbbell/DumbbellData.js +3 -5
  225. package/src/modules/helpers/Destroy.js +10 -1
  226. package/src/modules/helpers/InitCtxVariables.js +19 -16
  227. package/src/modules/helpers/RawStash.js +51 -0
  228. package/src/modules/helpers/UpdateHelpers.js +95 -30
  229. package/src/modules/highlightFilter/HighlightFilter.js +107 -52
  230. package/src/modules/highlightFilter/PiePart.js +1 -1
  231. package/src/modules/highlightFilter/RadialPart.js +1 -1
  232. package/src/modules/history/History.js +7 -2
  233. package/src/modules/legend/Legend.js +100 -62
  234. package/src/modules/license/LicenseEnforcer.js +6 -1
  235. package/src/modules/settings/Config.js +60 -153
  236. package/src/modules/settings/Defaults.js +352 -58
  237. package/src/modules/settings/Globals.js +23 -5
  238. package/src/modules/settings/Options.js +19 -5
  239. package/src/modules/settings/TypeAliases.js +3 -6
  240. package/src/modules/streamgraph/StreamData.js +3 -5
  241. package/src/modules/tooltip/AxesTooltip.js +33 -41
  242. package/src/modules/tooltip/Intersect.js +50 -43
  243. package/src/modules/tooltip/Labels.js +62 -23
  244. package/src/modules/tooltip/Marker.js +6 -7
  245. package/src/modules/tooltip/Position.js +31 -35
  246. package/src/modules/tooltip/Tooltip.js +107 -119
  247. package/src/modules/tooltip/Utils.js +94 -159
  248. package/src/modules/trellis/TrellisExports.js +21 -9
  249. package/src/modules/trellis/TrellisTooltip.js +18 -8
  250. package/src/modules/waterfall/WaterfallData.js +3 -5
  251. package/src/modules/weave/Claims.js +14 -3
  252. package/src/modules/weave/Highlights.js +209 -0
  253. package/src/modules/weave/PluginAPI.js +64 -3
  254. package/src/modules/weave/WeaveHost.js +215 -51
  255. package/src/ssr/BrowserAPIs.js +5 -3
  256. package/src/ssr/DOMShim.js +6 -30
  257. package/src/ssr/Hydration.js +5 -36
  258. package/src/ssr/RenderShim.js +333 -0
  259. package/src/ssr/SSRRenderer.js +81 -36
  260. package/src/svg/SVGAnimation.js +10 -7
  261. package/src/types/internal.d.ts +37 -7
  262. package/src/utils/Constants.js +7 -8
  263. package/src/utils/DateTime.js +21 -195
  264. package/src/utils/MissingFeature.js +7 -9
  265. package/src/utils/Resize.js +4 -0
  266. package/src/utils/Utils.js +102 -171
  267. package/types/apexcharts.d.ts +57 -7
@@ -1,12 +1,11 @@
1
1
  /*!
2
- * ApexCharts v8.0.1
2
+ * ApexCharts v8.2.0
3
3
  * (c) 2018-2026 ApexCharts
4
4
  */
5
5
  import * as _core from "apexcharts/core";
6
6
  import _core__default from "apexcharts/core";
7
7
  import { default as default2 } from "apexcharts/core";
8
8
  const AxesUtils = _core.__apex_axes_AxesUtils;
9
- const Data = _core.__apex_Data;
10
9
  const Series = _core.__apex_Series;
11
10
  const Utils = _core.__apex_Utils;
12
11
  const Environment = _core.__apex_Environment_Environment;
@@ -304,48 +303,58 @@ class Exports {
304
303
  return families;
305
304
  }
306
305
  /**
307
- * Every `@font-face` rule reachable from the document, as `{ family, css }`.
306
+ * Every `@font-face` rule reachable from the document, as
307
+ * `{ family, css, base }`, where `base` is the URL the rule's relative
308
+ * `url()`s resolve against: its stylesheet, not the page.
308
309
  *
309
- * Same-origin sheets are read through `cssRules`. A cross-origin sheet throws
310
- * on that access, so it is re-fetched by href and its `@font-face` blocks are
311
- * pulled out of the text: that is the path that matters in practice, since
312
- * hosted webfonts (the subject of #3617) are exactly the cross-origin case.
313
- * @returns {Promise<Array<{family: string, css: string}>>}
310
+ * Same-origin sheets are read through `cssRules`, descending into `@import`
311
+ * and grouping rules (`@media`, `@supports`, `@layer`). A cross-origin sheet
312
+ * throws on that access, so it is re-fetched by href and its `@font-face`
313
+ * blocks are pulled out of the text: that is the path that matters in
314
+ * practice, since hosted webfonts (the subject of #3617) are exactly the
315
+ * cross-origin case.
316
+ * @returns {Promise<Array<{family: string, css: string, base: string}>>}
314
317
  */
315
318
  collectFontFaceRules() {
316
319
  if (!Environment.isBrowser()) return Promise.resolve([]);
317
320
  const found = [];
318
321
  const remote = [];
319
- const pushFromText = (cssText) => {
322
+ const pushFromText = (cssText, base) => {
320
323
  const blocks = cssText.match(/@font-face\s*\{[^}]*\}/gi) || [];
321
324
  blocks.forEach((css) => {
322
325
  const m = css.match(/font-family\s*:\s*([^;}]+)/i);
323
326
  if (!m) return;
324
327
  const family = m[1].trim().replace(/^['"]|['"]$/g, "");
325
- found.push({ family: family.toLowerCase(), css });
328
+ found.push({ family: family.toLowerCase(), css, base });
326
329
  });
327
330
  };
328
- const sheets = Array.from(document.styleSheets || []);
329
- sheets.forEach((sheet) => {
331
+ const walkRules = (rules, base) => {
332
+ Array.from(rules).forEach((rule) => {
333
+ if (rule.type === 5) {
334
+ if (rule.cssText) pushFromText(rule.cssText, base);
335
+ } else if (rule.styleSheet) {
336
+ walkSheet(rule.styleSheet);
337
+ } else if (rule.cssRules) {
338
+ walkRules(rule.cssRules, base);
339
+ }
340
+ });
341
+ };
342
+ const walkSheet = (sheet) => {
330
343
  let rules = null;
331
344
  try {
332
345
  rules = sheet.cssRules;
333
346
  } catch (e) {
334
- rules = null;
335
347
  }
336
348
  if (rules) {
337
- Array.from(rules).forEach((rule) => {
338
- if (rule.type === 5 && rule.cssText) pushFromText(rule.cssText);
339
- });
340
- return;
341
- }
342
- if (sheet.href) {
349
+ walkRules(rules, sheet.href || document.baseURI);
350
+ } else if (sheet.href) {
343
351
  remote.push(
344
- fetch(sheet.href).then((r) => r.ok ? r.text() : "").then(pushFromText).catch(() => {
352
+ fetch(sheet.href).then((r) => r.ok ? r.text() : "").then((text) => pushFromText(text, sheet.href)).catch(() => {
345
353
  })
346
354
  );
347
355
  }
348
- });
356
+ };
357
+ Array.from(document.styleSheets || []).forEach(walkSheet);
349
358
  return Promise.all(remote).then(() => found);
350
359
  }
351
360
  /**
@@ -378,7 +387,7 @@ class Exports {
378
387
  if (!wanted.length) return Promise.resolve([]);
379
388
  return Promise.all(
380
389
  wanted.map(
381
- (face) => this.inlineFontFaceUrls(face.css).catch(() => null)
390
+ (face) => this.inlineFontFaceUrls(face.css, face.base).catch(() => null)
382
391
  )
383
392
  );
384
393
  }).then((cssBlocks) => {
@@ -395,9 +404,10 @@ class Exports {
395
404
  * data URI. Resolves to null if no url could be fetched, so the caller can
396
405
  * drop a block that would only reference unreachable files.
397
406
  * @param {string} css
407
+ * @param {string} [base] the URL relative `url()`s resolve against
398
408
  * @returns {Promise<string | null>}
399
409
  */
400
- inlineFontFaceUrls(css) {
410
+ inlineFontFaceUrls(css, base) {
401
411
  const urls = [];
402
412
  const re = /url\(\s*(['"]?)([^'")]+)\1\s*\)/gi;
403
413
  let m;
@@ -407,7 +417,7 @@ class Exports {
407
417
  if (!urls.length) return Promise.resolve(css.includes("data:") ? css : null);
408
418
  return Promise.all(
409
419
  urls.map(
410
- (url) => this.fetchAsDataUri(url).then((dataUri) => ({ url, dataUri })).catch(() => ({ url, dataUri: null }))
420
+ (url) => this.fetchAsDataUri(base ? new URL(url, base).href : url).then((dataUri) => ({ url, dataUri })).catch(() => ({ url, dataUri: null }))
411
421
  )
412
422
  ).then((results) => {
413
423
  let out = css;
@@ -468,6 +478,7 @@ class Exports {
468
478
  (_a = w.globals.layoutTween) == null ? void 0 : _a.finish();
469
479
  (_b = w.globals.circleTween) == null ? void 0 : _b.finish();
470
480
  (_c = w.globals.highlightTween) == null ? void 0 : _c.finish();
481
+ [...w.globals.chromeTweens || []].forEach((finish) => finish());
471
482
  const clonedNode = (
472
483
  /** @type {HTMLElement} */
473
484
  w.dom.elWrap.cloneNode(true)
@@ -574,19 +585,26 @@ class Exports {
574
585
  });
575
586
  }
576
587
  /**
588
+ * Resolves `{ imgURI: '' }` when the PNG cannot be made (no 2d context for
589
+ * a canvas that size, an SVG the browser will not decode, a tainted
590
+ * canvas), so a caller is never left waiting.
577
591
  * @param {Record<string, any> | undefined} options
578
592
  */
579
593
  dataURI(options) {
580
594
  if (Environment.isSSR()) return Promise.resolve({ imgURI: "" });
581
595
  return new Promise((resolve) => {
582
596
  const w = this.w;
597
+ const fail = () => {
598
+ console.warn("ApexCharts: the PNG export could not be rendered");
599
+ resolve({ imgURI: "" });
600
+ };
583
601
  const scale = options ? options.scale || options.width / w.globals.svgWidth : 1;
584
602
  const canvas = document.createElement("canvas");
585
603
  canvas.width = w.globals.svgWidth * scale;
586
604
  canvas.height = parseInt(w.dom.elWrap.style.height, 10) * scale;
587
605
  const canvasBg = this.resolveExportBackground();
588
606
  const ctx = canvas.getContext("2d");
589
- if (!ctx) return;
607
+ if (!ctx) return fail();
590
608
  ctx.fillStyle = canvasBg;
591
609
  ctx.fillRect(0, 0, canvas.width, canvas.height);
592
610
  this.getSvgString(scale).then((svgData) => {
@@ -594,18 +612,23 @@ class Exports {
594
612
  const img = new Image();
595
613
  img.crossOrigin = "anonymous";
596
614
  img.onload = () => {
597
- ctx.drawImage(img, 0, 0);
598
- const edgeCanvas = canvas;
599
- if (edgeCanvas.msToBlob) {
600
- const blob = edgeCanvas.msToBlob();
601
- resolve({ blob });
602
- } else {
603
- const imgURI = canvas.toDataURL("image/png");
604
- resolve({ imgURI });
615
+ try {
616
+ ctx.drawImage(img, 0, 0);
617
+ const edgeCanvas = canvas;
618
+ if (edgeCanvas.msToBlob) {
619
+ const blob = edgeCanvas.msToBlob();
620
+ resolve({ blob });
621
+ } else {
622
+ const imgURI = canvas.toDataURL("image/png");
623
+ resolve({ imgURI });
624
+ }
625
+ } catch (e) {
626
+ fail();
605
627
  }
606
628
  };
629
+ img.onerror = fail;
607
630
  img.src = svgUrl;
608
- });
631
+ }).catch(fail);
609
632
  });
610
633
  }
611
634
  exportToSVG() {
@@ -624,7 +647,7 @@ class Exports {
624
647
  this.dataURI(option).then(({ imgURI, blob }) => {
625
648
  if (blob) {
626
649
  navigator.msSaveOrOpenBlob(blob, this.w.globals.chartID + ".png");
627
- } else {
650
+ } else if (imgURI) {
628
651
  this.triggerDownload(
629
652
  imgURI,
630
653
  this.w.config.chart.toolbar.export.png.filename,
@@ -641,48 +664,54 @@ class Exports {
641
664
  lineDelimiter = "\n"
642
665
  }) {
643
666
  const w = this.w;
644
- if (!series) series = w.config.series;
645
- let columns = [];
667
+ const gl = w.globals;
668
+ const csvCfg = w.config.chart.toolbar.export.csv;
669
+ const raw = !series && (gl.streamgraphRawSeries || gl.waterfallRawSeries || gl.dumbbellRawSeries);
670
+ if (!series) series = raw || w.config.series;
671
+ const hidden = new Set(
672
+ raw && raw === gl.dumbbellRawSeries ? w.dumbbellData.hidden : gl.collapsedSeriesIndices
673
+ );
646
674
  const rows = [];
647
- let result = "";
648
- const universalBOM = "\uFEFF";
649
- const gSeries = w.seriesData.series.map((s, i) => {
650
- return w.globals.collapsedSeriesIndices.indexOf(i) === -1 ? s : [];
651
- });
675
+ const body = [];
676
+ const isDatetime = w.config.xaxis.type === "datetime";
677
+ const utc = w.config.xaxis.labels.datetimeUTC;
652
678
  const csvSafe = (val) => {
653
679
  if (val == null || Utils.isNumber(val)) return val;
654
680
  const s = String(val);
655
- return /^[=+\-@\t\r]/.test(s) ? `'${s}` : s;
681
+ return /^[=+\-@\t\r]/.test(s) && isNaN(+s) ? `'${s}` : s;
656
682
  };
657
- const getFormattedCategory = (cat) => {
658
- if (typeof w.config.chart.toolbar.export.csv.categoryFormatter === "function") {
659
- return w.config.chart.toolbar.export.csv.categoryFormatter(cat);
683
+ const isDateCat = (cat) => isDatetime && String(cat).length >= 10 && !isNaN(new Date(cat).getTime());
684
+ const datetimeText = (cat, withTime2) => {
685
+ const d = new Date(cat);
686
+ if (!utc) d.setTime(d.getTime() - d.getTimezoneOffset() * 6e4);
687
+ if (withTime2) {
688
+ return d.toISOString().slice(0, 23).replace("T", " ").replace(".000", "");
660
689
  }
661
- if (w.config.xaxis.type === "datetime" && String(cat).length >= 10) {
662
- return new Date(cat).toDateString();
690
+ const [day, date, month, year] = d.toUTCString().split(" ");
691
+ return `${day.slice(0, 3)} ${month} ${date} ${year}`;
692
+ };
693
+ const getFormattedCategory = (cat, withTime2) => {
694
+ if (typeof csvCfg.categoryFormatter === "function") {
695
+ return csvCfg.categoryFormatter(cat);
663
696
  }
664
- return Utils.isNumber(cat) ? cat : csvSafe(cat.split(columnDelimiter).join(""));
697
+ if (cat == null) return "";
698
+ if (isDateCat(cat)) return datetimeText(cat, withTime2);
699
+ return Utils.isNumber(cat) ? cat : csvSafe(String(cat).split(columnDelimiter).join(""));
665
700
  };
666
701
  const getFormattedValue = (value) => {
667
- return typeof w.config.chart.toolbar.export.csv.valueFormatter === "function" ? w.config.chart.toolbar.export.csv.valueFormatter(value) : csvSafe(value);
702
+ return typeof csvCfg.valueFormatter === "function" ? csvCfg.valueFormatter(value) : csvSafe(value);
668
703
  };
669
- const seriesMaxDataLength = Math.max(
670
- ...series.map((s) => {
671
- return s.data ? s.data.length : 0;
672
- })
673
- );
674
- const dataFormat = new Data(this.w);
675
704
  const axesUtils = new AxesUtils(this.w, {
676
705
  theme: this.ctx.theme,
677
706
  timeScale: this.ctx.timeScale
678
707
  });
679
708
  const getCat = (i) => {
680
709
  let cat = "";
681
- if (!w.globals.axisCharts) {
710
+ if (!gl.axisCharts) {
682
711
  cat = w.config.labels[i];
683
712
  } else {
684
713
  if (w.config.xaxis.type === "category" || w.config.xaxis.convertedCatToNumeric) {
685
- if (w.globals.isBarHorizontal) {
714
+ if (gl.isBarHorizontal) {
686
715
  const lbFormatter = w.formatters.yLabelFormatters[0];
687
716
  const sr = new Series(this.ctx.w);
688
717
  const activeSeries = sr.getActiveConfigSeriesIndex();
@@ -700,7 +729,7 @@ class Exports {
700
729
  ).text;
701
730
  }
702
731
  }
703
- if (w.config.xaxis.type === "datetime") {
732
+ if (isDatetime) {
704
733
  if (w.config.xaxis.categories.length) {
705
734
  cat = w.config.xaxis.categories[i];
706
735
  } else if (w.config.labels.length) {
@@ -708,159 +737,129 @@ class Exports {
708
737
  }
709
738
  }
710
739
  }
711
- if (cat === null) return "nullvalue";
712
- if (Array.isArray(cat)) {
713
- cat = cat.join(" ");
714
- }
715
- return Utils.isNumber(cat) ? cat : cat.split(columnDelimiter).join("");
716
- };
717
- const getEmptyDataForCsvColumn = () => {
718
- return [...Array(seriesMaxDataLength)].map(() => "");
740
+ return Array.isArray(cat) ? cat.join(" ") : cat;
719
741
  };
720
- const handleAxisRowsColumns = (s, sI) => {
721
- var _a, _b, _c, _d, _e, _f;
722
- if (columns.length && sI === 0) {
723
- rows.push(columns.join(columnDelimiter));
724
- }
725
- if (s.data) {
726
- const rowData = s.data.length ? s.data : getEmptyDataForCsvColumn();
727
- for (let i = 0; i < rowData.length; i++) {
728
- columns = [];
729
- let cat = getCat(i);
730
- if (cat === "nullvalue") continue;
731
- if (!cat) {
732
- if (dataFormat.isFormatXY()) {
733
- cat = series[sI].data[i].x;
734
- } else if (dataFormat.isFormat2DArray()) {
735
- cat = series[sI].data[i] ? series[sI].data[i][0] : "";
736
- }
737
- }
738
- if (sI === 0) {
739
- columns.push(getFormattedCategory(cat));
740
- for (let ci = 0; ci < w.seriesData.series.length; ci++) {
741
- const value = dataFormat.isFormatXY() ? (_a = series[ci].data[i]) == null ? void 0 : _a.y : gSeries[ci][i];
742
- columns.push(getFormattedValue(value));
743
- }
744
- }
745
- if (w.config.chart.type === "candlestick" || s.type && s.type === "candlestick") {
746
- columns.pop();
747
- columns.push(w.candleData.seriesCandleO[sI][i]);
748
- columns.push(w.candleData.seriesCandleH[sI][i]);
749
- columns.push(w.candleData.seriesCandleL[sI][i]);
750
- columns.push(w.candleData.seriesCandleC[sI][i]);
751
- }
752
- if (w.config.chart.type === "boxPlot" || s.type && s.type === "boxPlot") {
753
- columns.pop();
754
- columns.push(w.candleData.seriesCandleO[sI][i]);
755
- columns.push(w.candleData.seriesCandleH[sI][i]);
756
- columns.push(w.candleData.seriesCandleM[sI][i]);
757
- columns.push(w.candleData.seriesCandleL[sI][i]);
758
- columns.push(w.candleData.seriesCandleC[sI][i]);
759
- }
760
- if (w.config.chart.type === "rangeBar") {
761
- columns.pop();
762
- columns.push(w.rangeData.seriesRangeStart[sI][i]);
763
- columns.push(w.rangeData.seriesRangeEnd[sI][i]);
764
- }
765
- if (w.config.chart.type === "violin" || s.type && s.type === "violin") {
766
- columns.pop();
767
- columns.push((_b = w.violinData.seriesViolinMin[sI]) == null ? void 0 : _b[i]);
768
- columns.push((_c = w.violinData.seriesViolinMax[sI]) == null ? void 0 : _c[i]);
769
- columns.push((_f = (_e = (_d = w.violinData.seriesViolinPoints[sI]) == null ? void 0 : _d[i]) == null ? void 0 : _e.length) != null ? _f : 0);
770
- }
771
- if (columns.length) {
772
- rows.push(columns.join(columnDelimiter));
742
+ const cd = w.candleData;
743
+ const rd = w.rangeData;
744
+ const vd = w.violinData;
745
+ const multi = series.length > 1;
746
+ const cols = series.map((s, sI) => {
747
+ const type = raw ? "" : s.type || w.config.chart.type;
748
+ const fields = type === "candlestick" ? {
749
+ open: cd.seriesCandleO,
750
+ high: cd.seriesCandleH,
751
+ low: cd.seriesCandleL,
752
+ close: cd.seriesCandleC
753
+ } : type === "boxPlot" ? {
754
+ minimum: cd.seriesCandleO,
755
+ q1: cd.seriesCandleH,
756
+ median: cd.seriesCandleM,
757
+ q3: cd.seriesCandleL,
758
+ maximum: cd.seriesCandleC
759
+ } : type === "rangeBar" || type === "rangeArea" ? { minimum: rd.seriesRangeStart, maximum: rd.seriesRangeEnd } : type === "violin" ? {
760
+ minimum: vd.seriesViolinMin,
761
+ maximum: vd.seriesViolinMax,
762
+ observations: vd.seriesViolinPoints
763
+ } : null;
764
+ const name = String(s.name || `series-${sI}`).split(columnDelimiter).join("") || `series-${sI}`;
765
+ const keys = fields ? Object.keys(fields) : [name];
766
+ return {
767
+ head: fields && multi ? keys.map((k) => `${name} ${k}`) : keys,
768
+ /** @param {number} i */
769
+ cells: (i) => {
770
+ var _a;
771
+ const off = hidden.has(sI);
772
+ if (!fields) {
773
+ const d = off ? void 0 : (_a = s.data) == null ? void 0 : _a[i];
774
+ return [
775
+ getFormattedValue(
776
+ d && typeof d === "object" ? Array.isArray(d) ? d[1] : d.y : d
777
+ )
778
+ ];
773
779
  }
780
+ return Object.values(fields).map((src) => {
781
+ var _a2;
782
+ const v = off ? void 0 : (_a2 = src == null ? void 0 : src[sI]) == null ? void 0 : _a2[i];
783
+ return getFormattedValue(Array.isArray(v) ? v.length : v);
784
+ });
774
785
  }
775
- }
776
- };
777
- const handleUnequalXValues = () => {
778
- const byCategory = /* @__PURE__ */ new Map();
779
- series.forEach((s, sI) => {
780
- s == null ? void 0 : s.data.forEach((dataItem) => {
781
- let cat, value;
782
- if (dataFormat.isFormatXY()) {
783
- cat = dataItem.x;
784
- value = dataItem.y;
785
- } else if (dataFormat.isFormat2DArray()) {
786
- cat = dataItem[0];
787
- value = dataItem[1];
788
- } else {
789
- return;
790
- }
791
- const key = String(cat);
792
- let row = byCategory.get(key);
793
- if (!row) {
794
- row = { cat, values: Array(series.length).fill("") };
795
- byCategory.set(key, row);
796
- }
797
- row.values[sI] = getFormattedValue(value);
798
- });
799
- });
800
- if (columns.length) {
801
- rows.push(columns.join(columnDelimiter));
802
- }
803
- Array.from(byCategory.values()).sort((a, b) => {
804
- const aText = typeof a.cat === "string";
805
- const bText = typeof b.cat === "string";
806
- if (aText !== bText) return aText ? 1 : -1;
807
- if (!aText) return a.cat - b.cat;
808
- return a.cat < b.cat ? -1 : 1;
809
- }).forEach(({ cat, values }) => {
810
- rows.push([getFormattedCategory(cat), ...values].join(columnDelimiter));
811
- });
812
- };
813
- columns.push(w.config.chart.toolbar.export.csv.headerCategory);
814
- if (w.config.chart.type === "boxPlot") {
815
- columns.push("minimum");
816
- columns.push("q1");
817
- columns.push("median");
818
- columns.push("q3");
819
- columns.push("maximum");
820
- } else if (w.config.chart.type === "candlestick") {
821
- columns.push("open");
822
- columns.push("high");
823
- columns.push("low");
824
- columns.push("close");
825
- } else if (w.config.chart.type === "rangeBar") {
826
- columns.push("minimum");
827
- columns.push("maximum");
828
- } else if (w.config.chart.type === "violin") {
829
- columns.push("minimum");
830
- columns.push("maximum");
831
- columns.push("observations");
832
- } else {
833
- series.map((s, sI) => {
834
- const sname = (s.name ? s.name : `series-${sI}`) + "";
835
- if (w.globals.axisCharts) {
836
- columns.push(
837
- sname.split(columnDelimiter).join("") ? sname.split(columnDelimiter).join("") : `series-${sI}`
838
- );
839
- }
786
+ };
787
+ });
788
+ if (!gl.axisCharts) {
789
+ rows.push(
790
+ [csvCfg.headerCategory, csvCfg.headerValue].join(columnDelimiter)
791
+ );
792
+ series.forEach((_, sI) => {
793
+ rows.push(
794
+ [
795
+ getFormattedCategory(w.labelData.labels[sI]),
796
+ getFormattedValue(hidden.has(sI) ? "" : w.seriesData.series[sI])
797
+ ].join(columnDelimiter)
798
+ );
840
799
  });
841
- }
842
- if (!w.globals.axisCharts) {
843
- columns.push(w.config.chart.toolbar.export.csv.headerValue);
844
- rows.push(columns.join(columnDelimiter));
845
- }
846
- if (!w.globals.allSeriesHasEqualX && w.globals.axisCharts && !w.config.xaxis.categories.length && !w.config.labels.length) {
847
- handleUnequalXValues();
848
800
  } else {
849
- series.map((s, sI) => {
850
- if (w.globals.axisCharts) {
851
- handleAxisRowsColumns(s, sI);
852
- } else {
853
- columns = [];
854
- columns.push(getFormattedCategory(w.labelData.labels[sI]));
855
- columns.push(getFormattedValue(gSeries[sI]));
856
- rows.push(columns.join(columnDelimiter));
801
+ rows.push(
802
+ [csvCfg.headerCategory, ...cols.flatMap((c) => c.head)].join(
803
+ columnDelimiter
804
+ )
805
+ );
806
+ if (!gl.allSeriesHasEqualX && !w.config.xaxis.categories.length && !w.config.labels.length) {
807
+ const byCategory = /* @__PURE__ */ new Map();
808
+ series.forEach((s, sI) => {
809
+ var _a;
810
+ (_a = s == null ? void 0 : s.data) == null ? void 0 : _a.forEach((d, i) => {
811
+ if (!d || typeof d !== "object") return;
812
+ const cat = Array.isArray(d) ? d[0] : d.x;
813
+ const key = String(cat);
814
+ let row = byCategory.get(key);
815
+ if (!row) {
816
+ row = { cat, values: cols.map((c) => c.head.map(() => "")) };
817
+ byCategory.set(key, row);
818
+ }
819
+ row.values[sI] = cols[sI].cells(i);
820
+ });
821
+ });
822
+ Array.from(byCategory.values()).sort((a, b) => {
823
+ const aText = typeof a.cat === "string";
824
+ const bText = typeof b.cat === "string";
825
+ if (aText !== bText) return aText ? 1 : -1;
826
+ if (!aText) return a.cat - b.cat;
827
+ return w.axisFlags.isXNumeric ? a.cat < b.cat ? -1 : 1 : 0;
828
+ }).forEach(({ cat, values }) => body.push([cat, ...values.flat()]));
829
+ } else {
830
+ const len = Math.max(
831
+ 0,
832
+ ...series.map((s) => {
833
+ var _a;
834
+ return ((_a = s.data) == null ? void 0 : _a.length) || 0;
835
+ })
836
+ );
837
+ for (let i = 0; i < len; i++) {
838
+ let cat = getCat(i);
839
+ if (cat === null) continue;
840
+ if (!cat) {
841
+ const d = series.map((s) => {
842
+ var _a;
843
+ return (_a = s.data) == null ? void 0 : _a[i];
844
+ }).find((d2) => d2 != null);
845
+ cat = d == null ? "" : Array.isArray(d) ? d[0] : d.x;
846
+ }
847
+ body.push([cat, ...cols.flatMap((c) => c.cells(i))]);
857
848
  }
858
- });
849
+ }
859
850
  }
860
- result += rows.join(lineDelimiter);
851
+ const dates = body.map((r) => r[0]).filter(isDateCat);
852
+ const withTime = new Set(dates.map((c) => datetimeText(c))).size < dates.length;
853
+ body.forEach(
854
+ (r) => rows.push(
855
+ [getFormattedCategory(r[0], withTime), ...r.slice(1)].join(
856
+ columnDelimiter
857
+ )
858
+ )
859
+ );
861
860
  this.triggerDownload(
862
- "data:text/csv; charset=utf-8," + encodeURIComponent(universalBOM + result),
863
- fileName ? fileName : w.config.chart.toolbar.export.csv.filename,
861
+ "data:text/csv; charset=utf-8," + encodeURIComponent("\uFEFF" + rows.join(lineDelimiter)),
862
+ fileName ? fileName : csvCfg.filename,
864
863
  ".csv"
865
864
  );
866
865
  }