chartist 0.11.3 → 1.1.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 (124) hide show
  1. package/LICENSE-WTFPL +5 -5
  2. package/README.md +142 -32
  3. package/dist/axes/AutoScaleAxis.d.ts +12 -0
  4. package/dist/axes/AutoScaleAxis.d.ts.map +1 -0
  5. package/dist/axes/Axis.d.ts +40 -0
  6. package/dist/axes/Axis.d.ts.map +1 -0
  7. package/dist/axes/FixedScaleAxis.d.ts +11 -0
  8. package/dist/axes/FixedScaleAxis.d.ts.map +1 -0
  9. package/dist/axes/StepAxis.d.ts +9 -0
  10. package/dist/axes/StepAxis.d.ts.map +1 -0
  11. package/dist/axes/index.d.ts +6 -0
  12. package/dist/axes/index.d.ts.map +1 -0
  13. package/dist/axes/types.d.ts +5 -0
  14. package/dist/axes/types.d.ts.map +1 -0
  15. package/dist/charts/BarChart/BarChart.d.ts +47 -0
  16. package/dist/charts/BarChart/BarChart.d.ts.map +1 -0
  17. package/dist/charts/BarChart/BarChart.types.d.ts +40 -0
  18. package/dist/charts/BarChart/BarChart.types.d.ts.map +1 -0
  19. package/dist/charts/BarChart/index.d.ts +3 -0
  20. package/dist/charts/BarChart/index.d.ts.map +1 -0
  21. package/dist/charts/BaseChart.d.ts +47 -0
  22. package/dist/charts/BaseChart.d.ts.map +1 -0
  23. package/dist/charts/LineChart/LineChart.d.ts +92 -0
  24. package/dist/charts/LineChart/LineChart.d.ts.map +1 -0
  25. package/dist/charts/LineChart/LineChart.types.d.ts +53 -0
  26. package/dist/charts/LineChart/LineChart.types.d.ts.map +1 -0
  27. package/dist/charts/LineChart/index.d.ts +3 -0
  28. package/dist/charts/LineChart/index.d.ts.map +1 -0
  29. package/dist/charts/PieChart/PieChart.d.ts +83 -0
  30. package/dist/charts/PieChart/PieChart.d.ts.map +1 -0
  31. package/dist/charts/PieChart/PieChart.types.d.ts +53 -0
  32. package/dist/charts/PieChart/PieChart.types.d.ts.map +1 -0
  33. package/dist/charts/PieChart/index.d.ts +3 -0
  34. package/dist/charts/PieChart/index.d.ts.map +1 -0
  35. package/dist/charts/index.d.ts +6 -0
  36. package/dist/charts/index.d.ts.map +1 -0
  37. package/dist/charts/types.d.ts +11 -0
  38. package/dist/charts/types.d.ts.map +1 -0
  39. package/dist/core/constants.d.ts +13 -0
  40. package/dist/core/constants.d.ts.map +1 -0
  41. package/dist/core/creation.d.ts +61 -0
  42. package/dist/core/creation.d.ts.map +1 -0
  43. package/dist/core/data/bounds.d.ts +14 -0
  44. package/dist/core/data/bounds.d.ts.map +1 -0
  45. package/dist/core/data/data.d.ts +23 -0
  46. package/dist/core/data/data.d.ts.map +1 -0
  47. package/dist/core/data/highLow.d.ts +13 -0
  48. package/dist/core/data/highLow.d.ts.map +1 -0
  49. package/dist/core/data/index.d.ts +7 -0
  50. package/dist/core/data/index.d.ts.map +1 -0
  51. package/dist/core/data/normalize.d.ts +11 -0
  52. package/dist/core/data/normalize.d.ts.map +1 -0
  53. package/dist/core/data/segments.d.ts +29 -0
  54. package/dist/core/data/segments.d.ts.map +1 -0
  55. package/dist/core/data/serialize.d.ts +12 -0
  56. package/dist/core/data/serialize.d.ts.map +1 -0
  57. package/dist/core/index.d.ts +8 -0
  58. package/dist/core/index.d.ts.map +1 -0
  59. package/dist/core/lang.d.ts +23 -0
  60. package/dist/core/lang.d.ts.map +1 -0
  61. package/dist/core/math.d.ts +42 -0
  62. package/dist/core/math.d.ts.map +1 -0
  63. package/dist/core/optionsProvider.d.ts +15 -0
  64. package/dist/core/optionsProvider.d.ts.map +1 -0
  65. package/dist/core/types.d.ts +205 -0
  66. package/dist/core/types.d.ts.map +1 -0
  67. package/dist/event/EventEmitter.d.ts +27 -0
  68. package/dist/event/EventEmitter.d.ts.map +1 -0
  69. package/dist/event/index.d.ts +2 -0
  70. package/dist/event/index.d.ts.map +1 -0
  71. package/dist/index.cjs +3557 -0
  72. package/dist/index.cjs.map +1 -0
  73. package/dist/index.css +2 -0
  74. package/dist/index.css.map +1 -0
  75. package/dist/index.d.ts +8 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +3497 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/index.umd.js +2 -0
  80. package/dist/index.umd.js.map +1 -0
  81. package/dist/interpolation/cardinal.d.ts +28 -0
  82. package/dist/interpolation/cardinal.d.ts.map +1 -0
  83. package/dist/interpolation/index.d.ts +6 -0
  84. package/dist/interpolation/index.d.ts.map +1 -0
  85. package/dist/interpolation/monotoneCubic.d.ts +28 -0
  86. package/dist/interpolation/monotoneCubic.d.ts.map +1 -0
  87. package/dist/interpolation/none.d.ts +20 -0
  88. package/dist/interpolation/none.d.ts.map +1 -0
  89. package/dist/interpolation/simple.d.ts +28 -0
  90. package/dist/interpolation/simple.d.ts.map +1 -0
  91. package/dist/interpolation/step.d.ts +24 -0
  92. package/dist/interpolation/step.d.ts.map +1 -0
  93. package/dist/svg/Svg.d.ts +201 -0
  94. package/dist/svg/Svg.d.ts.map +1 -0
  95. package/dist/svg/SvgList.d.ts +31 -0
  96. package/dist/svg/SvgList.d.ts.map +1 -0
  97. package/dist/svg/SvgPath.d.ts +125 -0
  98. package/dist/svg/SvgPath.d.ts.map +1 -0
  99. package/dist/svg/animation.d.ts +37 -0
  100. package/dist/svg/animation.d.ts.map +1 -0
  101. package/dist/svg/index.d.ts +6 -0
  102. package/dist/svg/index.d.ts.map +1 -0
  103. package/dist/svg/types.d.ts +54 -0
  104. package/dist/svg/types.d.ts.map +1 -0
  105. package/dist/utils/extend.d.ts +10 -0
  106. package/dist/utils/extend.d.ts.map +1 -0
  107. package/dist/utils/functional.d.ts +30 -0
  108. package/dist/utils/functional.d.ts.map +1 -0
  109. package/dist/utils/index.d.ts +5 -0
  110. package/dist/utils/index.d.ts.map +1 -0
  111. package/dist/utils/types.d.ts +7 -0
  112. package/dist/utils/types.d.ts.map +1 -0
  113. package/dist/utils/utils.d.ts +27 -0
  114. package/dist/utils/utils.d.ts.map +1 -0
  115. package/package.json +36 -76
  116. package/CHANGELOG.md +0 -232
  117. package/dist/chartist.css +0 -615
  118. package/dist/chartist.css.map +0 -10
  119. package/dist/chartist.js +0 -4516
  120. package/dist/chartist.min.css +0 -1
  121. package/dist/chartist.min.js +0 -10
  122. package/dist/chartist.min.js.map +0 -1
  123. package/dist/scss/chartist.scss +0 -241
  124. package/dist/scss/settings/_chartist-settings.scss +0 -88
package/dist/index.cjs ADDED
@@ -0,0 +1,3557 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * This object contains all namespaces used within Chartist.
7
+ */ const namespaces = {
8
+ svg: "http://www.w3.org/2000/svg",
9
+ xmlns: "http://www.w3.org/2000/xmlns/",
10
+ xhtml: "http://www.w3.org/1999/xhtml",
11
+ xlink: "http://www.w3.org/1999/xlink",
12
+ ct: "http://gionkunz.github.com/chartist-js/ct"
13
+ };
14
+ /**
15
+ * Precision level used internally in Chartist for rounding. If you require more decimal places you can increase this number.
16
+ */ const precision = 8;
17
+ /**
18
+ * A map with characters to escape for strings to be safely used as attribute values.
19
+ */ const escapingMap = {
20
+ "&": "&",
21
+ "<": "&lt;",
22
+ ">": "&gt;",
23
+ '"': "&quot;",
24
+ "'": "&#039;"
25
+ };
26
+
27
+ /**
28
+ * Converts a number to a string with a unit. If a string is passed then this will be returned unmodified.
29
+ * @return Returns the passed number value with unit.
30
+ */ function ensureUnit(value, unit) {
31
+ if (typeof value === "number") {
32
+ return value + unit;
33
+ }
34
+ return value;
35
+ }
36
+ /**
37
+ * Converts a number or string to a quantity object.
38
+ * @return Returns an object containing the value as number and the unit as string.
39
+ */ function quantity(input) {
40
+ if (typeof input === "string") {
41
+ const match = /^(\d+)\s*(.*)$/g.exec(input);
42
+ return {
43
+ value: match ? +match[1] : 0,
44
+ unit: (match === null || match === void 0 ? void 0 : match[2]) || undefined
45
+ };
46
+ }
47
+ return {
48
+ value: Number(input)
49
+ };
50
+ }
51
+ /**
52
+ * Generates a-z from a number 0 to 26
53
+ * @param n A number from 0 to 26 that will result in a letter a-z
54
+ * @return A character from a-z based on the input number n
55
+ */ function alphaNumerate(n) {
56
+ // Limit to a-z
57
+ return String.fromCharCode(97 + n % 26);
58
+ }
59
+
60
+ const EPSILON = 2.221e-16;
61
+ /**
62
+ * Calculate the order of magnitude for the chart scale
63
+ * @param value The value Range of the chart
64
+ * @return The order of magnitude
65
+ */ function orderOfMagnitude(value) {
66
+ return Math.floor(Math.log(Math.abs(value)) / Math.LN10);
67
+ }
68
+ /**
69
+ * Project a data length into screen coordinates (pixels)
70
+ * @param axisLength The svg element for the chart
71
+ * @param length Single data value from a series array
72
+ * @param bounds All the values to set the bounds of the chart
73
+ * @return The projected data length in pixels
74
+ */ function projectLength(axisLength, length, bounds) {
75
+ return length / bounds.range * axisLength;
76
+ }
77
+ /**
78
+ * This helper function can be used to round values with certain precision level after decimal. This is used to prevent rounding errors near float point precision limit.
79
+ * @param value The value that should be rounded with precision
80
+ * @param [digits] The number of digits after decimal used to do the rounding
81
+ * @returns Rounded value
82
+ */ function roundWithPrecision(value, digits) {
83
+ const precision$1 = Math.pow(10, digits || precision);
84
+ return Math.round(value * precision$1) / precision$1;
85
+ }
86
+ /**
87
+ * Pollard Rho Algorithm to find smallest factor of an integer value. There are more efficient algorithms for factorization, but this one is quite efficient and not so complex.
88
+ * @param num An integer number where the smallest factor should be searched for
89
+ * @returns The smallest integer factor of the parameter num.
90
+ */ function rho(num) {
91
+ if (num === 1) {
92
+ return num;
93
+ }
94
+ function gcd(p, q) {
95
+ if (p % q === 0) {
96
+ return q;
97
+ } else {
98
+ return gcd(q, p % q);
99
+ }
100
+ }
101
+ function f(x) {
102
+ return x * x + 1;
103
+ }
104
+ let x1 = 2;
105
+ let x2 = 2;
106
+ let divisor;
107
+ if (num % 2 === 0) {
108
+ return 2;
109
+ }
110
+ do {
111
+ x1 = f(x1) % num;
112
+ x2 = f(f(x2)) % num;
113
+ divisor = gcd(Math.abs(x1 - x2), num);
114
+ }while (divisor === 1);
115
+ return divisor;
116
+ }
117
+ /**
118
+ * Calculate cartesian coordinates of polar coordinates
119
+ * @param centerX X-axis coordinates of center point of circle segment
120
+ * @param centerY X-axis coordinates of center point of circle segment
121
+ * @param radius Radius of circle segment
122
+ * @param angleInDegrees Angle of circle segment in degrees
123
+ * @return Coordinates of point on circumference
124
+ */ function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
125
+ const angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
126
+ return {
127
+ x: centerX + radius * Math.cos(angleInRadians),
128
+ y: centerY + radius * Math.sin(angleInRadians)
129
+ };
130
+ }
131
+
132
+ /**
133
+ * Calculate and retrieve all the bounds for the chart and return them in one array
134
+ * @param axisLength The length of the Axis used for
135
+ * @param highLow An object containing a high and low property indicating the value range of the chart.
136
+ * @param scaleMinSpace The minimum projected length a step should result in
137
+ * @param onlyInteger
138
+ * @return All the values to set the bounds of the chart
139
+ */ function getBounds(axisLength, highLow, scaleMinSpace) {
140
+ let onlyInteger = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
141
+ const bounds = {
142
+ high: highLow.high,
143
+ low: highLow.low,
144
+ valueRange: 0,
145
+ oom: 0,
146
+ step: 0,
147
+ min: 0,
148
+ max: 0,
149
+ range: 0,
150
+ numberOfSteps: 0,
151
+ values: []
152
+ };
153
+ bounds.valueRange = bounds.high - bounds.low;
154
+ bounds.oom = orderOfMagnitude(bounds.valueRange);
155
+ bounds.step = Math.pow(10, bounds.oom);
156
+ bounds.min = Math.floor(bounds.low / bounds.step) * bounds.step;
157
+ bounds.max = Math.ceil(bounds.high / bounds.step) * bounds.step;
158
+ bounds.range = bounds.max - bounds.min;
159
+ bounds.numberOfSteps = Math.round(bounds.range / bounds.step);
160
+ // Optimize scale step by checking if subdivision is possible based on horizontalGridMinSpace
161
+ // If we are already below the scaleMinSpace value we will scale up
162
+ const length = projectLength(axisLength, bounds.step, bounds);
163
+ const scaleUp = length < scaleMinSpace;
164
+ const smallestFactor = onlyInteger ? rho(bounds.range) : 0;
165
+ // First check if we should only use integer steps and if step 1 is still larger than scaleMinSpace so we can use 1
166
+ if (onlyInteger && projectLength(axisLength, 1, bounds) >= scaleMinSpace) {
167
+ bounds.step = 1;
168
+ } else if (onlyInteger && smallestFactor < bounds.step && projectLength(axisLength, smallestFactor, bounds) >= scaleMinSpace) {
169
+ // If step 1 was too small, we can try the smallest factor of range
170
+ // If the smallest factor is smaller than the current bounds.step and the projected length of smallest factor
171
+ // is larger than the scaleMinSpace we should go for it.
172
+ bounds.step = smallestFactor;
173
+ } else {
174
+ // Trying to divide or multiply by 2 and find the best step value
175
+ let optimizationCounter = 0;
176
+ for(;;){
177
+ if (scaleUp && projectLength(axisLength, bounds.step, bounds) <= scaleMinSpace) {
178
+ bounds.step *= 2;
179
+ } else if (!scaleUp && projectLength(axisLength, bounds.step / 2, bounds) >= scaleMinSpace) {
180
+ bounds.step /= 2;
181
+ if (onlyInteger && bounds.step % 1 !== 0) {
182
+ bounds.step *= 2;
183
+ break;
184
+ }
185
+ } else {
186
+ break;
187
+ }
188
+ if (optimizationCounter++ > 1000) {
189
+ throw new Error("Exceeded maximum number of iterations while optimizing scale step!");
190
+ }
191
+ }
192
+ }
193
+ bounds.step = Math.max(bounds.step, EPSILON);
194
+ function safeIncrement(value, increment) {
195
+ // If increment is too small use *= (1+EPSILON) as a simple nextafter
196
+ if (value === (value += increment)) {
197
+ value *= 1 + (increment > 0 ? EPSILON : -EPSILON);
198
+ }
199
+ return value;
200
+ }
201
+ // Narrow min and max based on new step
202
+ let newMin = bounds.min;
203
+ let newMax = bounds.max;
204
+ while(newMin + bounds.step <= bounds.low){
205
+ newMin = safeIncrement(newMin, bounds.step);
206
+ }
207
+ while(newMax - bounds.step >= bounds.high){
208
+ newMax = safeIncrement(newMax, -bounds.step);
209
+ }
210
+ bounds.min = newMin;
211
+ bounds.max = newMax;
212
+ bounds.range = bounds.max - bounds.min;
213
+ const values = [];
214
+ for(let i = bounds.min; i <= bounds.max; i = safeIncrement(i, bounds.step)){
215
+ const value = roundWithPrecision(i);
216
+ if (value !== values[values.length - 1]) {
217
+ values.push(value);
218
+ }
219
+ }
220
+ bounds.values = values;
221
+ return bounds;
222
+ }
223
+
224
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
225
+ function extend() {
226
+ let target = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
227
+ for(var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
228
+ sources[_key - 1] = arguments[_key];
229
+ }
230
+ for(let i = 0; i < sources.length; i++){
231
+ const source = sources[i];
232
+ for(const prop in source){
233
+ const sourceProp = source[prop];
234
+ if (typeof sourceProp === "object" && sourceProp !== null && !(sourceProp instanceof Array)) {
235
+ target[prop] = extend(target[prop], sourceProp);
236
+ } else {
237
+ target[prop] = sourceProp;
238
+ }
239
+ }
240
+ }
241
+ return target;
242
+ }
243
+
244
+ /**
245
+ * Helps to simplify functional style code
246
+ * @param n This exact value will be returned by the noop function
247
+ * @return The same value that was provided to the n parameter
248
+ */ const noop = (n)=>n
249
+ ;
250
+ /**
251
+ * Functional style helper to produce array with given length initialized with undefined values
252
+ */ const times = (length)=>Array.from({
253
+ length
254
+ })
255
+ ;
256
+ /**
257
+ * Sum helper to be used in reduce functions
258
+ */ const sum = (previous, current)=>previous + (current ? current : 0)
259
+ ;
260
+ /**
261
+ * Map for multi dimensional arrays where their nested arrays will be mapped in serial. The output array will have the length of the largest nested array. The callback function is called with variable arguments where each argument is the nested array value (or undefined if there are no more values).
262
+ *
263
+ * For example:
264
+ * @example
265
+ * ```javascript
266
+ * const data = [[1, 2], [3], []];
267
+ * serialMap(data, cb);
268
+ *
269
+ * // where cb will be called 2 times
270
+ * // 1. call arguments: (1, 3, undefined)
271
+ * // 2. call arguments: (2, undefined, undefined)
272
+ * ```
273
+ */ const serialMap = (array, callback)=>times(Math.max(...array.map((element)=>element.length
274
+ ))).map((_inner, index)=>callback(...array.map((element)=>element[index]
275
+ ))
276
+ )
277
+ ;
278
+
279
+ function safeHasProperty(target, property) {
280
+ return target !== null && typeof target === "object" && Reflect.has(target, property);
281
+ }
282
+ function isNumeric(value) {
283
+ return value !== null && isFinite(value);
284
+ }
285
+ /**
286
+ * Returns true on all falsey values except the numeric value 0.
287
+ */ function isFalseyButZero(value) {
288
+ return !value && value !== 0;
289
+ }
290
+ function getNumberOrUndefined(value) {
291
+ return isNumeric(value) ? Number(value) : undefined;
292
+ }
293
+ /**
294
+ * Checks if value is array of arrays or not.
295
+ */ function isArrayOfArrays(data) {
296
+ if (!Array.isArray(data)) {
297
+ return false;
298
+ }
299
+ return data.every(Array.isArray);
300
+ }
301
+
302
+ /**
303
+ * Get meta data of a specific value in a series.
304
+ */ function getMetaData(seriesData, index) {
305
+ const value = Array.isArray(seriesData) ? seriesData[index] : safeHasProperty(seriesData, "data") ? seriesData.data[index] : null;
306
+ return safeHasProperty(value, "meta") ? value.meta : undefined;
307
+ }
308
+ function isDataHoleValue(value) {
309
+ return value === null || value === undefined || typeof value === "number" && isNaN(value);
310
+ }
311
+ /**
312
+ * Checks if value is array of series objects.
313
+ */ function isArrayOfSeries(value) {
314
+ return Array.isArray(value) && value.every((_)=>Array.isArray(_) || safeHasProperty(_, "data")
315
+ );
316
+ }
317
+ /**
318
+ * Checks if provided value object is multi value (contains x or y properties)
319
+ */ function isMultiValue(value) {
320
+ return typeof value === "object" && value !== null && (Reflect.has(value, "x") || Reflect.has(value, "y"));
321
+ }
322
+ /**
323
+ * Gets a value from a dimension `value.x` or `value.y` while returning value directly if it's a valid numeric value. If the value is not numeric and it's falsey this function will return `defaultValue`.
324
+ */ function getMultiValue(value) {
325
+ let dimension = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "y";
326
+ if (isMultiValue(value) && safeHasProperty(value, dimension)) {
327
+ return getNumberOrUndefined(value[dimension]);
328
+ } else {
329
+ return getNumberOrUndefined(value);
330
+ }
331
+ }
332
+
333
+ /**
334
+ * Get highest and lowest value of data array. This Array contains the data that will be visualized in the chart.
335
+ * @param data The array that contains the data to be visualized in the chart
336
+ * @param options The Object that contains the chart options
337
+ * @param dimension Axis dimension 'x' or 'y' used to access the correct value and high / low configuration
338
+ * @return An object that contains the highest and lowest value that will be visualized on the chart.
339
+ */ function getHighLow(data, options, dimension) {
340
+ // TODO: Remove workaround for deprecated global high / low config. Axis high / low configuration is preferred
341
+ options = {
342
+ ...options,
343
+ ...dimension ? dimension === "x" ? options.axisX : options.axisY : {}
344
+ };
345
+ const highLow = {
346
+ high: options.high === undefined ? -Number.MAX_VALUE : +options.high,
347
+ low: options.low === undefined ? Number.MAX_VALUE : +options.low
348
+ };
349
+ const findHigh = options.high === undefined;
350
+ const findLow = options.low === undefined;
351
+ // Function to recursively walk through arrays and find highest and lowest number
352
+ function recursiveHighLow(sourceData) {
353
+ if (isDataHoleValue(sourceData)) {
354
+ return;
355
+ } else if (Array.isArray(sourceData)) {
356
+ for(let i = 0; i < sourceData.length; i++){
357
+ recursiveHighLow(sourceData[i]);
358
+ }
359
+ } else {
360
+ const value = Number(dimension && safeHasProperty(sourceData, dimension) ? sourceData[dimension] : sourceData);
361
+ if (findHigh && value > highLow.high) {
362
+ highLow.high = value;
363
+ }
364
+ if (findLow && value < highLow.low) {
365
+ highLow.low = value;
366
+ }
367
+ }
368
+ }
369
+ // Start to find highest and lowest number recursively
370
+ if (findHigh || findLow) {
371
+ recursiveHighLow(data);
372
+ }
373
+ // Overrides of high / low based on reference value, it will make sure that the invisible reference value is
374
+ // used to generate the chart. This is useful when the chart always needs to contain the position of the
375
+ // invisible reference value in the view i.e. for bipolar scales.
376
+ if (options.referenceValue || options.referenceValue === 0) {
377
+ highLow.high = Math.max(options.referenceValue, highLow.high);
378
+ highLow.low = Math.min(options.referenceValue, highLow.low);
379
+ }
380
+ // If high and low are the same because of misconfiguration or flat data (only the same value) we need
381
+ // to set the high or low to 0 depending on the polarity
382
+ if (highLow.high <= highLow.low) {
383
+ // If both values are 0 we set high to 1
384
+ if (highLow.low === 0) {
385
+ highLow.high = 1;
386
+ } else if (highLow.low < 0) {
387
+ // If we have the same negative value for the bounds we set bounds.high to 0
388
+ highLow.high = 0;
389
+ } else if (highLow.high > 0) {
390
+ // If we have the same positive value for the bounds we set bounds.low to 0
391
+ highLow.low = 0;
392
+ } else {
393
+ // If data array was empty, values are Number.MAX_VALUE and -Number.MAX_VALUE. Set bounds to prevent errors
394
+ highLow.high = 1;
395
+ highLow.low = 0;
396
+ }
397
+ }
398
+ return highLow;
399
+ }
400
+
401
+ function normalizeData(data) {
402
+ let reverse = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, multi = arguments.length > 2 ? arguments[2] : void 0, distributed = arguments.length > 3 ? arguments[3] : void 0;
403
+ let labelCount;
404
+ const normalized = {
405
+ labels: [],
406
+ series: normalizeSeries(data.series, multi, distributed)
407
+ };
408
+ // If all elements of the normalized data array are arrays we're dealing with
409
+ // multi series data and we need to find the largest series if they are un-even
410
+ if (isArrayOfArrays(normalized.series)) {
411
+ // Getting the series with the the most elements
412
+ labelCount = Math.max(...normalized.series.map((series)=>series.length
413
+ ));
414
+ } else {
415
+ // We're dealing with Pie data so we just take the normalized array length
416
+ labelCount = normalized.series.length;
417
+ }
418
+ normalized.labels = (data.labels || []).slice();
419
+ // Padding the labels to labelCount with empty strings
420
+ normalized.labels.push(...times(Math.max(0, labelCount - normalized.labels.length)).map(()=>""
421
+ ));
422
+ if (reverse) {
423
+ reverseData(normalized);
424
+ }
425
+ return normalized;
426
+ }
427
+ /**
428
+ * Reverses the series, labels and series data arrays.
429
+ */ function reverseData(data) {
430
+ var ref;
431
+ (ref = data.labels) === null || ref === void 0 ? void 0 : ref.reverse();
432
+ data.series.reverse();
433
+ for (const series of data.series){
434
+ if (safeHasProperty(series, "data")) {
435
+ series.data.reverse();
436
+ } else if (Array.isArray(series)) {
437
+ series.reverse();
438
+ }
439
+ }
440
+ }
441
+ function normalizeMulti(value, multi) {
442
+ // We need to prepare multi value output (x and y data)
443
+ let x;
444
+ let y;
445
+ // Single series value arrays are assumed to specify the Y-Axis value
446
+ // For example: [1, 2] => [{x: undefined, y: 1}, {x: undefined, y: 2}]
447
+ // If multi is a string then it's assumed that it specified which dimension should be filled as default
448
+ if (typeof value !== "object") {
449
+ const num = getNumberOrUndefined(value);
450
+ if (multi === "x") {
451
+ x = num;
452
+ } else {
453
+ y = num;
454
+ }
455
+ } else {
456
+ if (safeHasProperty(value, "x")) {
457
+ x = getNumberOrUndefined(value.x);
458
+ }
459
+ if (safeHasProperty(value, "y")) {
460
+ y = getNumberOrUndefined(value.y);
461
+ }
462
+ }
463
+ if (x === undefined && y === undefined) {
464
+ return undefined;
465
+ }
466
+ return {
467
+ x,
468
+ y
469
+ };
470
+ }
471
+ function normalizePrimitive(value, multi) {
472
+ if (isDataHoleValue(value)) {
473
+ // We're dealing with a hole in the data and therefore need to return undefined
474
+ // We're also returning undefined for multi value output
475
+ return undefined;
476
+ }
477
+ if (multi) {
478
+ return normalizeMulti(value, multi);
479
+ }
480
+ return getNumberOrUndefined(value);
481
+ }
482
+ function normalizeSingleSeries(series, multi) {
483
+ if (!Array.isArray(series)) {
484
+ // We are dealing with series object notation so we need to recurse on data property
485
+ return normalizeSingleSeries(series.data, multi);
486
+ }
487
+ return series.map((value)=>{
488
+ if (safeHasProperty(value, "value")) {
489
+ // We are dealing with value object notation so we need to recurse on value property
490
+ return normalizePrimitive(value.value, multi);
491
+ }
492
+ return normalizePrimitive(value, multi);
493
+ });
494
+ }
495
+ function normalizeSeries(series, multi, distributed) {
496
+ if (isArrayOfSeries(series)) {
497
+ return series.map((_)=>normalizeSingleSeries(_, multi)
498
+ );
499
+ }
500
+ const normalizedSeries = normalizeSingleSeries(series, multi);
501
+ if (distributed) {
502
+ return normalizedSeries.map((value)=>[
503
+ value
504
+ ]
505
+ );
506
+ }
507
+ return normalizedSeries;
508
+ }
509
+
510
+ /**
511
+ * Splits a list of coordinates and associated values into segments. Each returned segment contains a pathCoordinates
512
+ * valueData property describing the segment.
513
+ *
514
+ * With the default options, segments consist of contiguous sets of points that do not have an undefined value. Any
515
+ * points with undefined values are discarded.
516
+ *
517
+ * **Options**
518
+ * The following options are used to determine how segments are formed
519
+ * ```javascript
520
+ * var options = {
521
+ * // If fillHoles is true, undefined values are simply discarded without creating a new segment. Assuming other options are default, this returns single segment.
522
+ * fillHoles: false,
523
+ * // If increasingX is true, the coordinates in all segments have strictly increasing x-values.
524
+ * increasingX: false
525
+ * };
526
+ * ```
527
+ *
528
+ * @param pathCoordinates List of point coordinates to be split in the form [x1, y1, x2, y2 ... xn, yn]
529
+ * @param valueData List of associated point values in the form [v1, v2 .. vn]
530
+ * @param options Options set by user
531
+ * @return List of segments, each containing a pathCoordinates and valueData property.
532
+ */ function splitIntoSegments(pathCoordinates, valueData, options) {
533
+ const finalOptions = {
534
+ increasingX: false,
535
+ fillHoles: false,
536
+ ...options
537
+ };
538
+ const segments = [];
539
+ let hole = true;
540
+ for(let i = 0; i < pathCoordinates.length; i += 2){
541
+ // If this value is a "hole" we set the hole flag
542
+ if (getMultiValue(valueData[i / 2].value) === undefined) {
543
+ // if(valueData[i / 2].value === undefined) {
544
+ if (!finalOptions.fillHoles) {
545
+ hole = true;
546
+ }
547
+ } else {
548
+ if (finalOptions.increasingX && i >= 2 && pathCoordinates[i] <= pathCoordinates[i - 2]) {
549
+ // X is not increasing, so we need to make sure we start a new segment
550
+ hole = true;
551
+ }
552
+ // If it's a valid value we need to check if we're coming out of a hole and create a new empty segment
553
+ if (hole) {
554
+ segments.push({
555
+ pathCoordinates: [],
556
+ valueData: []
557
+ });
558
+ // As we have a valid value now, we are not in a "hole" anymore
559
+ hole = false;
560
+ }
561
+ // Add to the segment pathCoordinates and valueData
562
+ segments[segments.length - 1].pathCoordinates.push(pathCoordinates[i], pathCoordinates[i + 1]);
563
+ segments[segments.length - 1].valueData.push(valueData[i / 2]);
564
+ }
565
+ }
566
+ return segments;
567
+ }
568
+
569
+ function serialize(data) {
570
+ let serialized = "";
571
+ if (data === null || data === undefined) {
572
+ return data;
573
+ } else if (typeof data === "number") {
574
+ serialized = "" + data;
575
+ } else if (typeof data === "object") {
576
+ serialized = JSON.stringify({
577
+ data: data
578
+ });
579
+ } else {
580
+ serialized = String(data);
581
+ }
582
+ return Object.keys(escapingMap).reduce((result, key)=>result.replaceAll(key, escapingMap[key])
583
+ , serialized);
584
+ }
585
+ function deserialize(data) {
586
+ if (typeof data !== "string") {
587
+ return data;
588
+ }
589
+ if (data === "NaN") {
590
+ return NaN;
591
+ }
592
+ data = Object.keys(escapingMap).reduce((result, key)=>result.replaceAll(escapingMap[key], key)
593
+ , data);
594
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
595
+ let parsedData = data;
596
+ if (typeof data === "string") {
597
+ try {
598
+ parsedData = JSON.parse(data);
599
+ parsedData = parsedData.data !== undefined ? parsedData.data : parsedData;
600
+ } catch (e) {
601
+ /* Ingore */ }
602
+ }
603
+ return parsedData;
604
+ }
605
+
606
+ /**
607
+ * This helper class is to wrap multiple `Svg` elements into a list where you can call the `Svg` functions on all elements in the list with one call. This is helpful when you'd like to perform calls with `Svg` on multiple elements.
608
+ * An instance of this class is also returned by `Svg.querySelectorAll`.
609
+ */ class SvgList {
610
+ call(method, args) {
611
+ this.svgElements.forEach((element)=>Reflect.apply(element[method], element, args)
612
+ );
613
+ return this;
614
+ }
615
+ attr() {
616
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
617
+ args[_key] = arguments[_key];
618
+ }
619
+ return this.call("attr", args);
620
+ }
621
+ elem() {
622
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
623
+ args[_key] = arguments[_key];
624
+ }
625
+ return this.call("elem", args);
626
+ }
627
+ root() {
628
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
629
+ args[_key] = arguments[_key];
630
+ }
631
+ return this.call("root", args);
632
+ }
633
+ getNode() {
634
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
635
+ args[_key] = arguments[_key];
636
+ }
637
+ return this.call("getNode", args);
638
+ }
639
+ foreignObject() {
640
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
641
+ args[_key] = arguments[_key];
642
+ }
643
+ return this.call("foreignObject", args);
644
+ }
645
+ text() {
646
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
647
+ args[_key] = arguments[_key];
648
+ }
649
+ return this.call("text", args);
650
+ }
651
+ empty() {
652
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
653
+ args[_key] = arguments[_key];
654
+ }
655
+ return this.call("empty", args);
656
+ }
657
+ remove() {
658
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
659
+ args[_key] = arguments[_key];
660
+ }
661
+ return this.call("remove", args);
662
+ }
663
+ addClass() {
664
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
665
+ args[_key] = arguments[_key];
666
+ }
667
+ return this.call("addClass", args);
668
+ }
669
+ removeClass() {
670
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
671
+ args[_key] = arguments[_key];
672
+ }
673
+ return this.call("removeClass", args);
674
+ }
675
+ removeAllClasses() {
676
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
677
+ args[_key] = arguments[_key];
678
+ }
679
+ return this.call("removeAllClasses", args);
680
+ }
681
+ animate() {
682
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
683
+ args[_key] = arguments[_key];
684
+ }
685
+ return this.call("animate", args);
686
+ }
687
+ /**
688
+ * @param nodeList An Array of SVG DOM nodes or a SVG DOM NodeList (as returned by document.querySelectorAll)
689
+ */ constructor(nodeList){
690
+ this.svgElements = [];
691
+ for(let i = 0; i < nodeList.length; i++){
692
+ this.svgElements.push(new Svg(nodeList[i]));
693
+ }
694
+ }
695
+ }
696
+
697
+ /**
698
+ * This Object contains some standard easing cubic bezier curves.
699
+ * Then can be used with their name in the `Svg.animate`.
700
+ * You can also extend the list and use your own name in the `animate` function.
701
+ * Click the show code button to see the available bezier functions.
702
+ */ const easings = {
703
+ easeInSine: [
704
+ 0.47,
705
+ 0,
706
+ 0.745,
707
+ 0.715
708
+ ],
709
+ easeOutSine: [
710
+ 0.39,
711
+ 0.575,
712
+ 0.565,
713
+ 1
714
+ ],
715
+ easeInOutSine: [
716
+ 0.445,
717
+ 0.05,
718
+ 0.55,
719
+ 0.95
720
+ ],
721
+ easeInQuad: [
722
+ 0.55,
723
+ 0.085,
724
+ 0.68,
725
+ 0.53
726
+ ],
727
+ easeOutQuad: [
728
+ 0.25,
729
+ 0.46,
730
+ 0.45,
731
+ 0.94
732
+ ],
733
+ easeInOutQuad: [
734
+ 0.455,
735
+ 0.03,
736
+ 0.515,
737
+ 0.955
738
+ ],
739
+ easeInCubic: [
740
+ 0.55,
741
+ 0.055,
742
+ 0.675,
743
+ 0.19
744
+ ],
745
+ easeOutCubic: [
746
+ 0.215,
747
+ 0.61,
748
+ 0.355,
749
+ 1
750
+ ],
751
+ easeInOutCubic: [
752
+ 0.645,
753
+ 0.045,
754
+ 0.355,
755
+ 1
756
+ ],
757
+ easeInQuart: [
758
+ 0.895,
759
+ 0.03,
760
+ 0.685,
761
+ 0.22
762
+ ],
763
+ easeOutQuart: [
764
+ 0.165,
765
+ 0.84,
766
+ 0.44,
767
+ 1
768
+ ],
769
+ easeInOutQuart: [
770
+ 0.77,
771
+ 0,
772
+ 0.175,
773
+ 1
774
+ ],
775
+ easeInQuint: [
776
+ 0.755,
777
+ 0.05,
778
+ 0.855,
779
+ 0.06
780
+ ],
781
+ easeOutQuint: [
782
+ 0.23,
783
+ 1,
784
+ 0.32,
785
+ 1
786
+ ],
787
+ easeInOutQuint: [
788
+ 0.86,
789
+ 0,
790
+ 0.07,
791
+ 1
792
+ ],
793
+ easeInExpo: [
794
+ 0.95,
795
+ 0.05,
796
+ 0.795,
797
+ 0.035
798
+ ],
799
+ easeOutExpo: [
800
+ 0.19,
801
+ 1,
802
+ 0.22,
803
+ 1
804
+ ],
805
+ easeInOutExpo: [
806
+ 1,
807
+ 0,
808
+ 0,
809
+ 1
810
+ ],
811
+ easeInCirc: [
812
+ 0.6,
813
+ 0.04,
814
+ 0.98,
815
+ 0.335
816
+ ],
817
+ easeOutCirc: [
818
+ 0.075,
819
+ 0.82,
820
+ 0.165,
821
+ 1
822
+ ],
823
+ easeInOutCirc: [
824
+ 0.785,
825
+ 0.135,
826
+ 0.15,
827
+ 0.86
828
+ ],
829
+ easeInBack: [
830
+ 0.6,
831
+ -0.28,
832
+ 0.735,
833
+ 0.045
834
+ ],
835
+ easeOutBack: [
836
+ 0.175,
837
+ 0.885,
838
+ 0.32,
839
+ 1.275
840
+ ],
841
+ easeInOutBack: [
842
+ 0.68,
843
+ -0.55,
844
+ 0.265,
845
+ 1.55
846
+ ]
847
+ };
848
+ function createAnimation(element, attribute, animationDefinition) {
849
+ let createGuided = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false, eventEmitter = arguments.length > 4 ? arguments[4] : void 0;
850
+ const { easing , ...def } = animationDefinition;
851
+ const attributeProperties = {};
852
+ let animationEasing;
853
+ let timeout;
854
+ // Check if an easing is specified in the definition object and delete it from the object as it will not
855
+ // be part of the animate element attributes.
856
+ if (easing) {
857
+ // If already an easing Bézier curve array we take it or we lookup a easing array in the Easing object
858
+ animationEasing = Array.isArray(easing) ? easing : easings[easing];
859
+ }
860
+ // If numeric dur or begin was provided we assume milli seconds
861
+ def.begin = ensureUnit(def.begin, "ms");
862
+ def.dur = ensureUnit(def.dur, "ms");
863
+ if (animationEasing) {
864
+ def.calcMode = "spline";
865
+ def.keySplines = animationEasing.join(" ");
866
+ def.keyTimes = "0;1";
867
+ }
868
+ // Adding "fill: freeze" if we are in guided mode and set initial attribute values
869
+ if (createGuided) {
870
+ def.fill = "freeze";
871
+ // Animated property on our element should already be set to the animation from value in guided mode
872
+ attributeProperties[attribute] = def.from;
873
+ element.attr(attributeProperties);
874
+ // In guided mode we also set begin to indefinite so we can trigger the start manually and put the begin
875
+ // which needs to be in ms aside
876
+ timeout = quantity(def.begin || 0).value;
877
+ def.begin = "indefinite";
878
+ }
879
+ const animate = element.elem("animate", {
880
+ attributeName: attribute,
881
+ ...def
882
+ });
883
+ if (createGuided) {
884
+ // If guided we take the value that was put aside in timeout and trigger the animation manually with a timeout
885
+ setTimeout(()=>{
886
+ // If beginElement fails we set the animated attribute to the end position and remove the animate element
887
+ // This happens if the SMIL ElementTimeControl interface is not supported or any other problems occurred in
888
+ // the browser. (Currently FF 34 does not support animate elements in foreignObjects)
889
+ try {
890
+ // @ts-expect-error Try legacy API.
891
+ animate._node.beginElement();
892
+ } catch (err) {
893
+ // Set animated attribute to current animated value
894
+ attributeProperties[attribute] = def.to;
895
+ element.attr(attributeProperties);
896
+ // Remove the animate element as it's no longer required
897
+ animate.remove();
898
+ }
899
+ }, timeout);
900
+ }
901
+ const animateNode = animate.getNode();
902
+ if (eventEmitter) {
903
+ animateNode.addEventListener("beginEvent", ()=>eventEmitter.emit("animationBegin", {
904
+ element: element,
905
+ animate: animateNode,
906
+ params: animationDefinition
907
+ })
908
+ );
909
+ }
910
+ animateNode.addEventListener("endEvent", ()=>{
911
+ if (eventEmitter) {
912
+ eventEmitter.emit("animationEnd", {
913
+ element: element,
914
+ animate: animateNode,
915
+ params: animationDefinition
916
+ });
917
+ }
918
+ if (createGuided) {
919
+ // Set animated attribute to current animated value
920
+ attributeProperties[attribute] = def.to;
921
+ element.attr(attributeProperties);
922
+ // Remove the animate element as it's no longer required
923
+ animate.remove();
924
+ }
925
+ });
926
+ }
927
+
928
+ /**
929
+ * Svg creates a new SVG object wrapper with a starting element. You can use the wrapper to fluently create sub-elements and modify them.
930
+ */ class Svg {
931
+ attr(attributes, ns) {
932
+ if (typeof attributes === "string") {
933
+ if (ns) {
934
+ return this._node.getAttributeNS(ns, attributes);
935
+ } else {
936
+ return this._node.getAttribute(attributes);
937
+ }
938
+ }
939
+ Object.keys(attributes).forEach((key)=>{
940
+ // If the attribute value is undefined we can skip this one
941
+ if (attributes[key] === undefined) {
942
+ return;
943
+ }
944
+ if (key.indexOf(":") !== -1) {
945
+ const namespacedAttribute = key.split(":");
946
+ this._node.setAttributeNS(namespaces[namespacedAttribute[0]], key, String(attributes[key]));
947
+ } else {
948
+ this._node.setAttribute(key, String(attributes[key]));
949
+ }
950
+ });
951
+ return this;
952
+ }
953
+ /**
954
+ * Create a new SVG element whose wrapper object will be selected for further operations. This way you can also create nested groups easily.
955
+ * @param name The name of the SVG element that should be created as child element of the currently selected element wrapper
956
+ * @param attributes An object with properties that will be added as attributes to the SVG element that is created. Attributes with undefined values will not be added.
957
+ * @param className This class or class list will be added to the SVG element
958
+ * @param insertFirst If this param is set to true in conjunction with a parent element the newly created element will be added as first child element in the parent element
959
+ * @return Returns a Svg wrapper object that can be used to modify the containing SVG data
960
+ */ elem(name, attributes, className) {
961
+ let insertFirst = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
962
+ return new Svg(name, attributes, className, this, insertFirst);
963
+ }
964
+ /**
965
+ * Returns the parent Chartist.SVG wrapper object
966
+ * @return Returns a Svg wrapper around the parent node of the current node. If the parent node is not existing or it's not an SVG node then this function will return null.
967
+ */ parent() {
968
+ return this._node.parentNode instanceof SVGElement ? new Svg(this._node.parentNode) : null;
969
+ }
970
+ /**
971
+ * This method returns a Svg wrapper around the root SVG element of the current tree.
972
+ * @return The root SVG element wrapped in a Svg element
973
+ */ root() {
974
+ let node = this._node;
975
+ while(node.nodeName !== "svg"){
976
+ if (node.parentElement) {
977
+ node = node.parentElement;
978
+ } else {
979
+ break;
980
+ }
981
+ }
982
+ return new Svg(node);
983
+ }
984
+ /**
985
+ * Find the first child SVG element of the current element that matches a CSS selector. The returned object is a Svg wrapper.
986
+ * @param selector A CSS selector that is used to query for child SVG elements
987
+ * @return The SVG wrapper for the element found or null if no element was found
988
+ */ querySelector(selector) {
989
+ const foundNode = this._node.querySelector(selector);
990
+ return foundNode ? new Svg(foundNode) : null;
991
+ }
992
+ /**
993
+ * Find the all child SVG elements of the current element that match a CSS selector. The returned object is a Svg.List wrapper.
994
+ * @param selector A CSS selector that is used to query for child SVG elements
995
+ * @return The SVG wrapper list for the element found or null if no element was found
996
+ */ querySelectorAll(selector) {
997
+ const foundNodes = this._node.querySelectorAll(selector);
998
+ return new SvgList(foundNodes);
999
+ }
1000
+ /**
1001
+ * Returns the underlying SVG node for the current element.
1002
+ */ getNode() {
1003
+ return this._node;
1004
+ }
1005
+ /**
1006
+ * This method creates a foreignObject (see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject) that allows to embed HTML content into a SVG graphic. With the help of foreignObjects you can enable the usage of regular HTML elements inside of SVG where they are subject for SVG positioning and transformation but the Browser will use the HTML rendering capabilities for the containing DOM.
1007
+ * @param content The DOM Node, or HTML string that will be converted to a DOM Node, that is then placed into and wrapped by the foreignObject
1008
+ * @param attributes An object with properties that will be added as attributes to the foreignObject element that is created. Attributes with undefined values will not be added.
1009
+ * @param className This class or class list will be added to the SVG element
1010
+ * @param insertFirst Specifies if the foreignObject should be inserted as first child
1011
+ * @return New wrapper object that wraps the foreignObject element
1012
+ */ foreignObject(content, attributes, className) {
1013
+ let insertFirst = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
1014
+ let contentNode;
1015
+ // If content is string then we convert it to DOM
1016
+ // TODO: Handle case where content is not a string nor a DOM Node
1017
+ if (typeof content === "string") {
1018
+ const container = document.createElement("div");
1019
+ container.innerHTML = content;
1020
+ contentNode = container.firstChild;
1021
+ } else {
1022
+ contentNode = content;
1023
+ }
1024
+ if (contentNode instanceof Element) {
1025
+ // Adding namespace to content element
1026
+ contentNode.setAttribute("xmlns", namespaces.xmlns);
1027
+ }
1028
+ // Creating the foreignObject without required extension attribute (as described here
1029
+ // http://www.w3.org/TR/SVG/extend.html#ForeignObjectElement)
1030
+ const fnObj = this.elem("foreignObject", attributes, className, insertFirst);
1031
+ // Add content to foreignObjectElement
1032
+ fnObj._node.appendChild(contentNode);
1033
+ return fnObj;
1034
+ }
1035
+ /**
1036
+ * This method adds a new text element to the current Svg wrapper.
1037
+ * @param t The text that should be added to the text element that is created
1038
+ * @return The same wrapper object that was used to add the newly created element
1039
+ */ text(t) {
1040
+ this._node.appendChild(document.createTextNode(t));
1041
+ return this;
1042
+ }
1043
+ /**
1044
+ * This method will clear all child nodes of the current wrapper object.
1045
+ * @return The same wrapper object that got emptied
1046
+ */ empty() {
1047
+ while(this._node.firstChild){
1048
+ this._node.removeChild(this._node.firstChild);
1049
+ }
1050
+ return this;
1051
+ }
1052
+ /**
1053
+ * This method will cause the current wrapper to remove itself from its parent wrapper. Use this method if you'd like to get rid of an element in a given DOM structure.
1054
+ * @return The parent wrapper object of the element that got removed
1055
+ */ remove() {
1056
+ var ref;
1057
+ (ref = this._node.parentNode) === null || ref === void 0 ? void 0 : ref.removeChild(this._node);
1058
+ return this.parent();
1059
+ }
1060
+ /**
1061
+ * This method will replace the element with a new element that can be created outside of the current DOM.
1062
+ * @param newElement The new Svg object that will be used to replace the current wrapper object
1063
+ * @return The wrapper of the new element
1064
+ */ replace(newElement) {
1065
+ var ref;
1066
+ (ref = this._node.parentNode) === null || ref === void 0 ? void 0 : ref.replaceChild(newElement._node, this._node);
1067
+ return newElement;
1068
+ }
1069
+ /**
1070
+ * This method will append an element to the current element as a child.
1071
+ * @param element The Svg element that should be added as a child
1072
+ * @param insertFirst Specifies if the element should be inserted as first child
1073
+ * @return The wrapper of the appended object
1074
+ */ append(element) {
1075
+ let insertFirst = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1076
+ if (insertFirst && this._node.firstChild) {
1077
+ this._node.insertBefore(element._node, this._node.firstChild);
1078
+ } else {
1079
+ this._node.appendChild(element._node);
1080
+ }
1081
+ return this;
1082
+ }
1083
+ /**
1084
+ * Returns an array of class names that are attached to the current wrapper element. This method can not be chained further.
1085
+ * @return A list of classes or an empty array if there are no classes on the current element
1086
+ */ classes() {
1087
+ const classNames = this._node.getAttribute("class");
1088
+ return classNames ? classNames.trim().split(/\s+/) : [];
1089
+ }
1090
+ /**
1091
+ * Adds one or a space separated list of classes to the current element and ensures the classes are only existing once.
1092
+ * @param names A white space separated list of class names
1093
+ * @return The wrapper of the current element
1094
+ */ addClass(names) {
1095
+ this._node.setAttribute("class", this.classes().concat(names.trim().split(/\s+/)).filter(function(elem, pos, self) {
1096
+ return self.indexOf(elem) === pos;
1097
+ }).join(" "));
1098
+ return this;
1099
+ }
1100
+ /**
1101
+ * Removes one or a space separated list of classes from the current element.
1102
+ * @param names A white space separated list of class names
1103
+ * @return The wrapper of the current element
1104
+ */ removeClass(names) {
1105
+ const removedClasses = names.trim().split(/\s+/);
1106
+ this._node.setAttribute("class", this.classes().filter((name)=>removedClasses.indexOf(name) === -1
1107
+ ).join(" "));
1108
+ return this;
1109
+ }
1110
+ /**
1111
+ * Removes all classes from the current element.
1112
+ * @return The wrapper of the current element
1113
+ */ removeAllClasses() {
1114
+ this._node.setAttribute("class", "");
1115
+ return this;
1116
+ }
1117
+ /**
1118
+ * Get element height using `getBoundingClientRect`
1119
+ * @return The elements height in pixels
1120
+ */ height() {
1121
+ return this._node.getBoundingClientRect().height;
1122
+ }
1123
+ /**
1124
+ * Get element width using `getBoundingClientRect`
1125
+ * @return The elements width in pixels
1126
+ */ width() {
1127
+ return this._node.getBoundingClientRect().width;
1128
+ }
1129
+ /**
1130
+ * The animate function lets you animate the current element with SMIL animations. You can add animations for multiple attributes at the same time by using an animation definition object. This object should contain SMIL animation attributes. Please refer to http://www.w3.org/TR/SVG/animate.html for a detailed specification about the available animation attributes. Additionally an easing property can be passed in the animation definition object. This can be a string with a name of an easing function in `Svg.Easing` or an array with four numbers specifying a cubic Bézier curve.
1131
+ * **An animations object could look like this:**
1132
+ * ```javascript
1133
+ * element.animate({
1134
+ * opacity: {
1135
+ * dur: 1000,
1136
+ * from: 0,
1137
+ * to: 1
1138
+ * },
1139
+ * x1: {
1140
+ * dur: '1000ms',
1141
+ * from: 100,
1142
+ * to: 200,
1143
+ * easing: 'easeOutQuart'
1144
+ * },
1145
+ * y1: {
1146
+ * dur: '2s',
1147
+ * from: 0,
1148
+ * to: 100
1149
+ * }
1150
+ * });
1151
+ * ```
1152
+ * **Automatic unit conversion**
1153
+ * For the `dur` and the `begin` animate attribute you can also omit a unit by passing a number. The number will automatically be converted to milli seconds.
1154
+ * **Guided mode**
1155
+ * The default behavior of SMIL animations with offset using the `begin` attribute is that the attribute will keep it's original value until the animation starts. Mostly this behavior is not desired as you'd like to have your element attributes already initialized with the animation `from` value even before the animation starts. Also if you don't specify `fill="freeze"` on an animate element or if you delete the animation after it's done (which is done in guided mode) the attribute will switch back to the initial value. This behavior is also not desired when performing simple one-time animations. For one-time animations you'd want to trigger animations immediately instead of relative to the document begin time. That's why in guided mode Svg will also use the `begin` property to schedule a timeout and manually start the animation after the timeout. If you're using multiple SMIL definition objects for an attribute (in an array), guided mode will be disabled for this attribute, even if you explicitly enabled it.
1156
+ * If guided mode is enabled the following behavior is added:
1157
+ * - Before the animation starts (even when delayed with `begin`) the animated attribute will be set already to the `from` value of the animation
1158
+ * - `begin` is explicitly set to `indefinite` so it can be started manually without relying on document begin time (creation)
1159
+ * - The animate element will be forced to use `fill="freeze"`
1160
+ * - The animation will be triggered with `beginElement()` in a timeout where `begin` of the definition object is interpreted in milli seconds. If no `begin` was specified the timeout is triggered immediately.
1161
+ * - After the animation the element attribute value will be set to the `to` value of the animation
1162
+ * - The animate element is deleted from the DOM
1163
+ * @param animations An animations object where the property keys are the attributes you'd like to animate. The properties should be objects again that contain the SMIL animation attributes (usually begin, dur, from, and to). The property begin and dur is auto converted (see Automatic unit conversion). You can also schedule multiple animations for the same attribute by passing an Array of SMIL definition objects. Attributes that contain an array of SMIL definition objects will not be executed in guided mode.
1164
+ * @param guided Specify if guided mode should be activated for this animation (see Guided mode). If not otherwise specified, guided mode will be activated.
1165
+ * @param eventEmitter If specified, this event emitter will be notified when an animation starts or ends.
1166
+ * @return The current element where the animation was added
1167
+ */ animate(animations) {
1168
+ let guided = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true, eventEmitter = arguments.length > 2 ? arguments[2] : void 0;
1169
+ Object.keys(animations).forEach((attribute)=>{
1170
+ const attributeAnimation = animations[attribute];
1171
+ // If current attribute is an array of definition objects we create an animate for each and disable guided mode
1172
+ if (Array.isArray(attributeAnimation)) {
1173
+ attributeAnimation.forEach((animationDefinition)=>createAnimation(this, attribute, animationDefinition, false, eventEmitter)
1174
+ );
1175
+ } else {
1176
+ createAnimation(this, attribute, attributeAnimation, guided, eventEmitter);
1177
+ }
1178
+ });
1179
+ return this;
1180
+ }
1181
+ /**
1182
+ * @param name The name of the SVG element to create or an SVG dom element which should be wrapped into Svg
1183
+ * @param attributes An object with properties that will be added as attributes to the SVG element that is created. Attributes with undefined values will not be added.
1184
+ * @param className This class or class list will be added to the SVG element
1185
+ * @param parent The parent SVG wrapper object where this newly created wrapper and it's element will be attached to as child
1186
+ * @param insertFirst If this param is set to true in conjunction with a parent element the newly created element will be added as first child element in the parent element
1187
+ */ constructor(name, attributes, className, parent, insertFirst = false){
1188
+ // If Svg is getting called with an SVG element we just return the wrapper
1189
+ if (name instanceof Element) {
1190
+ this._node = name;
1191
+ } else {
1192
+ this._node = document.createElementNS(namespaces.svg, name);
1193
+ // If this is an SVG element created then custom namespace
1194
+ if (name === "svg") {
1195
+ this.attr({
1196
+ "xmlns:ct": namespaces.ct
1197
+ });
1198
+ }
1199
+ }
1200
+ if (attributes) {
1201
+ this.attr(attributes);
1202
+ }
1203
+ if (className) {
1204
+ this.addClass(className);
1205
+ }
1206
+ if (parent) {
1207
+ if (insertFirst && parent._node.firstChild) {
1208
+ parent._node.insertBefore(this._node, parent._node.firstChild);
1209
+ } else {
1210
+ parent._node.appendChild(this._node);
1211
+ }
1212
+ }
1213
+ }
1214
+ }
1215
+ /**
1216
+ * @todo Only there for chartist <1 compatibility. Remove after deprecation warining.
1217
+ * @deprecated Use the animation module export `easings` directly.
1218
+ */ Svg.Easing = easings;
1219
+
1220
+ /**
1221
+ * Create or reinitialize the SVG element for the chart
1222
+ * @param container The containing DOM Node object that will be used to plant the SVG element
1223
+ * @param width Set the width of the SVG element. Default is 100%
1224
+ * @param height Set the height of the SVG element. Default is 100%
1225
+ * @param className Specify a class to be added to the SVG element
1226
+ * @return The created/reinitialized SVG element
1227
+ */ function createSvg(container) {
1228
+ let width = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "100%", height = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "100%", className = arguments.length > 3 ? arguments[3] : void 0;
1229
+ // Check if there is a previous SVG element in the container that contains the Chartist XML namespace and remove it
1230
+ // Since the DOM API does not support namespaces we need to manually search the returned list http://www.w3.org/TR/selectors-api/
1231
+ Array.from(container.querySelectorAll("svg")).filter((svg)=>svg.getAttributeNS(namespaces.xmlns, "ct")
1232
+ ).forEach((svg)=>container.removeChild(svg)
1233
+ );
1234
+ // Create svg object with width and height or use 100% as default
1235
+ const svg1 = new Svg("svg").attr({
1236
+ width,
1237
+ height
1238
+ }).attr({
1239
+ // TODO: Check better solution (browser support) and remove inline styles due to CSP
1240
+ style: "width: ".concat(width, "; height: ").concat(height, ";")
1241
+ });
1242
+ if (className) {
1243
+ svg1.addClass(className);
1244
+ }
1245
+ // Add the DOM node to our container
1246
+ container.appendChild(svg1.getNode());
1247
+ return svg1;
1248
+ }
1249
+ /**
1250
+ * Converts a number into a padding object.
1251
+ * @param padding
1252
+ * @param fallback This value is used to fill missing values if a incomplete padding object was passed
1253
+ * @returns Returns a padding object containing top, right, bottom, left properties filled with the padding number passed in as argument. If the argument is something else than a number (presumably already a correct padding object) then this argument is directly returned.
1254
+ */ function normalizePadding(padding) {
1255
+ return typeof padding === "number" ? {
1256
+ top: padding,
1257
+ right: padding,
1258
+ bottom: padding,
1259
+ left: padding
1260
+ } : padding === undefined ? {
1261
+ top: 0,
1262
+ right: 0,
1263
+ bottom: 0,
1264
+ left: 0
1265
+ } : {
1266
+ top: typeof padding.top === "number" ? padding.top : 0,
1267
+ right: typeof padding.right === "number" ? padding.right : 0,
1268
+ bottom: typeof padding.bottom === "number" ? padding.bottom : 0,
1269
+ left: typeof padding.left === "number" ? padding.left : 0
1270
+ };
1271
+ }
1272
+ /**
1273
+ * Initialize chart drawing rectangle (area where chart is drawn) x1,y1 = bottom left / x2,y2 = top right
1274
+ * @param svg The svg element for the chart
1275
+ * @param options The Object that contains all the optional values for the chart
1276
+ * @return The chart rectangles coordinates inside the svg element plus the rectangles measurements
1277
+ */ function createChartRect(svg, options) {
1278
+ var ref, ref1, ref2, ref3;
1279
+ const hasAxis = Boolean(options.axisX || options.axisY);
1280
+ const yAxisOffset = ((ref = options.axisY) === null || ref === void 0 ? void 0 : ref.offset) || 0;
1281
+ const xAxisOffset = ((ref1 = options.axisX) === null || ref1 === void 0 ? void 0 : ref1.offset) || 0;
1282
+ const yAxisPosition = (ref2 = options.axisY) === null || ref2 === void 0 ? void 0 : ref2.position;
1283
+ const xAxisPosition = (ref3 = options.axisX) === null || ref3 === void 0 ? void 0 : ref3.position;
1284
+ // If width or height results in invalid value (including 0) we fallback to the unitless settings or even 0
1285
+ let width = svg.width() || quantity(options.width).value || 0;
1286
+ let height = svg.height() || quantity(options.height).value || 0;
1287
+ const normalizedPadding = normalizePadding(options.chartPadding);
1288
+ // If settings were to small to cope with offset (legacy) and padding, we'll adjust
1289
+ width = Math.max(width, yAxisOffset + normalizedPadding.left + normalizedPadding.right);
1290
+ height = Math.max(height, xAxisOffset + normalizedPadding.top + normalizedPadding.bottom);
1291
+ const chartRect = {
1292
+ x1: 0,
1293
+ x2: 0,
1294
+ y1: 0,
1295
+ y2: 0,
1296
+ padding: normalizedPadding,
1297
+ width () {
1298
+ return this.x2 - this.x1;
1299
+ },
1300
+ height () {
1301
+ return this.y1 - this.y2;
1302
+ }
1303
+ };
1304
+ if (hasAxis) {
1305
+ if (xAxisPosition === "start") {
1306
+ chartRect.y2 = normalizedPadding.top + xAxisOffset;
1307
+ chartRect.y1 = Math.max(height - normalizedPadding.bottom, chartRect.y2 + 1);
1308
+ } else {
1309
+ chartRect.y2 = normalizedPadding.top;
1310
+ chartRect.y1 = Math.max(height - normalizedPadding.bottom - xAxisOffset, chartRect.y2 + 1);
1311
+ }
1312
+ if (yAxisPosition === "start") {
1313
+ chartRect.x1 = normalizedPadding.left + yAxisOffset;
1314
+ chartRect.x2 = Math.max(width - normalizedPadding.right, chartRect.x1 + 1);
1315
+ } else {
1316
+ chartRect.x1 = normalizedPadding.left;
1317
+ chartRect.x2 = Math.max(width - normalizedPadding.right - yAxisOffset, chartRect.x1 + 1);
1318
+ }
1319
+ } else {
1320
+ chartRect.x1 = normalizedPadding.left;
1321
+ chartRect.x2 = Math.max(width - normalizedPadding.right, chartRect.x1 + 1);
1322
+ chartRect.y2 = normalizedPadding.top;
1323
+ chartRect.y1 = Math.max(height - normalizedPadding.bottom, chartRect.y2 + 1);
1324
+ }
1325
+ return chartRect;
1326
+ }
1327
+ /**
1328
+ * Creates a grid line based on a projected value.
1329
+ */ function createGrid(position, index, axis, offset, length, group, classes, eventEmitter) {
1330
+ const positionalData = {
1331
+ ["".concat(axis.units.pos, "1")]: position,
1332
+ ["".concat(axis.units.pos, "2")]: position,
1333
+ ["".concat(axis.counterUnits.pos, "1")]: offset,
1334
+ ["".concat(axis.counterUnits.pos, "2")]: offset + length
1335
+ };
1336
+ const gridElement = group.elem("line", positionalData, classes.join(" "));
1337
+ // Event for grid draw
1338
+ eventEmitter.emit("draw", {
1339
+ type: "grid",
1340
+ axis,
1341
+ index,
1342
+ group,
1343
+ element: gridElement,
1344
+ ...positionalData
1345
+ });
1346
+ }
1347
+ /**
1348
+ * Creates a grid background rect and emits the draw event.
1349
+ */ function createGridBackground(gridGroup, chartRect, className, eventEmitter) {
1350
+ const gridBackground = gridGroup.elem("rect", {
1351
+ x: chartRect.x1,
1352
+ y: chartRect.y2,
1353
+ width: chartRect.width(),
1354
+ height: chartRect.height()
1355
+ }, className, true);
1356
+ // Event for grid background draw
1357
+ eventEmitter.emit("draw", {
1358
+ type: "gridBackground",
1359
+ group: gridGroup,
1360
+ element: gridBackground
1361
+ });
1362
+ }
1363
+ /**
1364
+ * Creates a label based on a projected value and an axis.
1365
+ */ function createLabel(position, length, index, label, axis, axisOffset, labelOffset, group, classes, eventEmitter) {
1366
+ const positionalData = {
1367
+ [axis.units.pos]: position + labelOffset[axis.units.pos],
1368
+ [axis.counterUnits.pos]: labelOffset[axis.counterUnits.pos],
1369
+ [axis.units.len]: length,
1370
+ [axis.counterUnits.len]: Math.max(0, axisOffset - 10)
1371
+ };
1372
+ // We need to set width and height explicitly to px as span will not expand with width and height being
1373
+ // 100% in all browsers
1374
+ const stepLength = Math.round(positionalData[axis.units.len]);
1375
+ const stepCounterLength = Math.round(positionalData[axis.counterUnits.len]);
1376
+ const content = document.createElement("span");
1377
+ content.className = classes.join(" ");
1378
+ content.style[axis.units.len] = stepLength + "px";
1379
+ content.style[axis.counterUnits.len] = stepCounterLength + "px";
1380
+ content.textContent = String(label);
1381
+ const labelElement = group.foreignObject(content, {
1382
+ style: "overflow: visible;",
1383
+ ...positionalData
1384
+ });
1385
+ eventEmitter.emit("draw", {
1386
+ type: "label",
1387
+ axis,
1388
+ index,
1389
+ group,
1390
+ element: labelElement,
1391
+ text: label,
1392
+ ...positionalData
1393
+ });
1394
+ }
1395
+
1396
+ /**
1397
+ * Provides options handling functionality with callback for options changes triggered by responsive options and media query matches
1398
+ * @param options Options set by user
1399
+ * @param responsiveOptions Optional functions to add responsive behavior to chart
1400
+ * @param eventEmitter The event emitter that will be used to emit the options changed events
1401
+ * @return The consolidated options object from the defaults, base and matching responsive options
1402
+ */ function optionsProvider(options, responsiveOptions, eventEmitter) {
1403
+ let currentOptions;
1404
+ const mediaQueryListeners = [];
1405
+ function updateCurrentOptions(mediaEvent) {
1406
+ const previousOptions = currentOptions;
1407
+ currentOptions = extend({}, options);
1408
+ if (responsiveOptions) {
1409
+ responsiveOptions.forEach((responsiveOption)=>{
1410
+ const mql = window.matchMedia(responsiveOption[0]);
1411
+ if (mql.matches) {
1412
+ currentOptions = extend(currentOptions, responsiveOption[1]);
1413
+ }
1414
+ });
1415
+ }
1416
+ if (eventEmitter && mediaEvent) {
1417
+ eventEmitter.emit("optionsChanged", {
1418
+ previousOptions,
1419
+ currentOptions
1420
+ });
1421
+ }
1422
+ }
1423
+ function removeMediaQueryListeners() {
1424
+ mediaQueryListeners.forEach((mql)=>mql.removeEventListener("change", updateCurrentOptions)
1425
+ );
1426
+ }
1427
+ if (!window.matchMedia) {
1428
+ throw new Error("window.matchMedia not found! Make sure you're using a polyfill.");
1429
+ } else if (responsiveOptions) {
1430
+ responsiveOptions.forEach((responsiveOption)=>{
1431
+ const mql = window.matchMedia(responsiveOption[0]);
1432
+ mql.addEventListener("change", updateCurrentOptions);
1433
+ mediaQueryListeners.push(mql);
1434
+ });
1435
+ }
1436
+ // Execute initially without an event argument so we get the correct options
1437
+ updateCurrentOptions();
1438
+ return {
1439
+ removeMediaQueryListeners,
1440
+ getCurrentOptions () {
1441
+ return currentOptions;
1442
+ }
1443
+ };
1444
+ }
1445
+
1446
+ /**
1447
+ * Contains the descriptors of supported element types in a SVG path. Currently only move, line and curve are supported.
1448
+ */ const elementDescriptions = {
1449
+ m: [
1450
+ "x",
1451
+ "y"
1452
+ ],
1453
+ l: [
1454
+ "x",
1455
+ "y"
1456
+ ],
1457
+ c: [
1458
+ "x1",
1459
+ "y1",
1460
+ "x2",
1461
+ "y2",
1462
+ "x",
1463
+ "y"
1464
+ ],
1465
+ a: [
1466
+ "rx",
1467
+ "ry",
1468
+ "xAr",
1469
+ "lAf",
1470
+ "sf",
1471
+ "x",
1472
+ "y"
1473
+ ]
1474
+ };
1475
+ /**
1476
+ * Default options for newly created SVG path objects.
1477
+ */ const defaultOptions$3 = {
1478
+ // The accuracy in digit count after the decimal point. This will be used to round numbers in the SVG path. If this option is set to false then no rounding will be performed.
1479
+ accuracy: 3
1480
+ };
1481
+ function element(command, params, pathElements, pos, relative, data) {
1482
+ const pathElement = {
1483
+ command: relative ? command.toLowerCase() : command.toUpperCase(),
1484
+ ...params,
1485
+ ...data ? {
1486
+ data
1487
+ } : {}
1488
+ };
1489
+ pathElements.splice(pos, 0, pathElement);
1490
+ }
1491
+ function forEachParam(pathElements, cb) {
1492
+ pathElements.forEach((pathElement, pathElementIndex)=>{
1493
+ elementDescriptions[pathElement.command.toLowerCase()].forEach((paramName, paramIndex)=>{
1494
+ cb(pathElement, paramName, pathElementIndex, paramIndex, pathElements);
1495
+ });
1496
+ });
1497
+ }
1498
+ class SvgPath {
1499
+ /**
1500
+ * This static function on `SvgPath` is joining multiple paths together into one paths.
1501
+ * @param paths A list of paths to be joined together. The order is important.
1502
+ * @param close If the newly created path should be a closed path
1503
+ * @param options Path options for the newly created path.
1504
+ */ static join(paths) {
1505
+ let close = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, options = arguments.length > 2 ? arguments[2] : void 0;
1506
+ const joinedPath = new SvgPath(close, options);
1507
+ for(let i = 0; i < paths.length; i++){
1508
+ const path = paths[i];
1509
+ for(let j = 0; j < path.pathElements.length; j++){
1510
+ joinedPath.pathElements.push(path.pathElements[j]);
1511
+ }
1512
+ }
1513
+ return joinedPath;
1514
+ }
1515
+ position(pos) {
1516
+ if (pos !== undefined) {
1517
+ this.pos = Math.max(0, Math.min(this.pathElements.length, pos));
1518
+ return this;
1519
+ } else {
1520
+ return this.pos;
1521
+ }
1522
+ }
1523
+ /**
1524
+ * Removes elements from the path starting at the current position.
1525
+ * @param count Number of path elements that should be removed from the current position.
1526
+ * @return The current path object for easy call chaining.
1527
+ */ remove(count) {
1528
+ this.pathElements.splice(this.pos, count);
1529
+ return this;
1530
+ }
1531
+ /**
1532
+ * Use this function to add a new move SVG path element.
1533
+ * @param x The x coordinate for the move element.
1534
+ * @param y The y coordinate for the move element.
1535
+ * @param relative If set to true the move element will be created with relative coordinates (lowercase letter)
1536
+ * @param data Any data that should be stored with the element object that will be accessible in pathElement
1537
+ * @return The current path object for easy call chaining.
1538
+ */ move(x, y) {
1539
+ let relative = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false, data = arguments.length > 3 ? arguments[3] : void 0;
1540
+ element("M", {
1541
+ x: +x,
1542
+ y: +y
1543
+ }, this.pathElements, this.pos++, relative, data);
1544
+ return this;
1545
+ }
1546
+ /**
1547
+ * Use this function to add a new line SVG path element.
1548
+ * @param x The x coordinate for the line element.
1549
+ * @param y The y coordinate for the line element.
1550
+ * @param relative If set to true the line element will be created with relative coordinates (lowercase letter)
1551
+ * @param data Any data that should be stored with the element object that will be accessible in pathElement
1552
+ * @return The current path object for easy call chaining.
1553
+ */ line(x, y) {
1554
+ let relative = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false, data = arguments.length > 3 ? arguments[3] : void 0;
1555
+ element("L", {
1556
+ x: +x,
1557
+ y: +y
1558
+ }, this.pathElements, this.pos++, relative, data);
1559
+ return this;
1560
+ }
1561
+ /**
1562
+ * Use this function to add a new curve SVG path element.
1563
+ * @param x1 The x coordinate for the first control point of the bezier curve.
1564
+ * @param y1 The y coordinate for the first control point of the bezier curve.
1565
+ * @param x2 The x coordinate for the second control point of the bezier curve.
1566
+ * @param y2 The y coordinate for the second control point of the bezier curve.
1567
+ * @param x The x coordinate for the target point of the curve element.
1568
+ * @param y The y coordinate for the target point of the curve element.
1569
+ * @param relative If set to true the curve element will be created with relative coordinates (lowercase letter)
1570
+ * @param data Any data that should be stored with the element object that will be accessible in pathElement
1571
+ * @return The current path object for easy call chaining.
1572
+ */ curve(x1, y1, x2, y2, x, y) {
1573
+ let relative = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : false, data = arguments.length > 7 ? arguments[7] : void 0;
1574
+ element("C", {
1575
+ x1: +x1,
1576
+ y1: +y1,
1577
+ x2: +x2,
1578
+ y2: +y2,
1579
+ x: +x,
1580
+ y: +y
1581
+ }, this.pathElements, this.pos++, relative, data);
1582
+ return this;
1583
+ }
1584
+ /**
1585
+ * Use this function to add a new non-bezier curve SVG path element.
1586
+ * @param rx The radius to be used for the x-axis of the arc.
1587
+ * @param ry The radius to be used for the y-axis of the arc.
1588
+ * @param xAr Defines the orientation of the arc
1589
+ * @param lAf Large arc flag
1590
+ * @param sf Sweep flag
1591
+ * @param x The x coordinate for the target point of the curve element.
1592
+ * @param y The y coordinate for the target point of the curve element.
1593
+ * @param relative If set to true the curve element will be created with relative coordinates (lowercase letter)
1594
+ * @param data Any data that should be stored with the element object that will be accessible in pathElement
1595
+ * @return The current path object for easy call chaining.
1596
+ */ arc(rx, ry, xAr, lAf, sf, x, y) {
1597
+ let relative = arguments.length > 7 && arguments[7] !== void 0 ? arguments[7] : false, data = arguments.length > 8 ? arguments[8] : void 0;
1598
+ element("A", {
1599
+ rx,
1600
+ ry,
1601
+ xAr,
1602
+ lAf,
1603
+ sf,
1604
+ x,
1605
+ y
1606
+ }, this.pathElements, this.pos++, relative, data);
1607
+ return this;
1608
+ }
1609
+ /**
1610
+ * Parses an SVG path seen in the d attribute of path elements, and inserts the parsed elements into the existing path object at the current cursor position. Any closing path indicators (Z at the end of the path) will be ignored by the parser as this is provided by the close option in the options of the path object.
1611
+ * @param path Any SVG path that contains move (m), line (l) or curve (c) components.
1612
+ * @return The current path object for easy call chaining.
1613
+ */ parse(path) {
1614
+ // Parsing the SVG path string into an array of arrays [['M', '10', '10'], ['L', '100', '100']]
1615
+ const chunks = path.replace(/([A-Za-z])([0-9])/g, "$1 $2").replace(/([0-9])([A-Za-z])/g, "$1 $2").split(/[\s,]+/).reduce((result, pathElement)=>{
1616
+ if (pathElement.match(/[A-Za-z]/)) {
1617
+ result.push([]);
1618
+ }
1619
+ result[result.length - 1].push(pathElement);
1620
+ return result;
1621
+ }, []);
1622
+ // If this is a closed path we remove the Z at the end because this is determined by the close option
1623
+ if (chunks[chunks.length - 1][0].toUpperCase() === "Z") {
1624
+ chunks.pop();
1625
+ }
1626
+ // Using svgPathElementDescriptions to map raw path arrays into objects that contain the command and the parameters
1627
+ // For example {command: 'M', x: '10', y: '10'}
1628
+ const elements = chunks.map((chunk)=>{
1629
+ const command = chunk.shift();
1630
+ const description = elementDescriptions[command.toLowerCase()];
1631
+ return {
1632
+ command,
1633
+ ...description.reduce((result, paramName, index)=>{
1634
+ result[paramName] = +chunk[index];
1635
+ return result;
1636
+ }, {})
1637
+ };
1638
+ });
1639
+ // Preparing a splice call with the elements array as var arg params and insert the parsed elements at the current position
1640
+ this.pathElements.splice(this.pos, 0, ...elements);
1641
+ // Increase the internal position by the element count
1642
+ this.pos += elements.length;
1643
+ return this;
1644
+ }
1645
+ /**
1646
+ * This function renders to current SVG path object into a final SVG string that can be used in the d attribute of SVG path elements. It uses the accuracy option to round big decimals. If the close parameter was set in the constructor of this path object then a path closing Z will be appended to the output string.
1647
+ */ stringify() {
1648
+ const accuracyMultiplier = Math.pow(10, this.options.accuracy);
1649
+ return this.pathElements.reduce((path, pathElement)=>{
1650
+ const params = elementDescriptions[pathElement.command.toLowerCase()].map((paramName)=>{
1651
+ const value = pathElement[paramName];
1652
+ return this.options.accuracy ? Math.round(value * accuracyMultiplier) / accuracyMultiplier : value;
1653
+ });
1654
+ return path + pathElement.command + params.join(",");
1655
+ }, "") + (this.close ? "Z" : "");
1656
+ }
1657
+ /**
1658
+ * Scales all elements in the current SVG path object. There is an individual parameter for each coordinate. Scaling will also be done for control points of curves, affecting the given coordinate.
1659
+ * @param x The number which will be used to scale the x, x1 and x2 of all path elements.
1660
+ * @param y The number which will be used to scale the y, y1 and y2 of all path elements.
1661
+ * @return The current path object for easy call chaining.
1662
+ */ scale(x, y) {
1663
+ forEachParam(this.pathElements, (pathElement, paramName)=>{
1664
+ pathElement[paramName] *= paramName[0] === "x" ? x : y;
1665
+ });
1666
+ return this;
1667
+ }
1668
+ /**
1669
+ * Translates all elements in the current SVG path object. The translation is relative and there is an individual parameter for each coordinate. Translation will also be done for control points of curves, affecting the given coordinate.
1670
+ * @param x The number which will be used to translate the x, x1 and x2 of all path elements.
1671
+ * @param y The number which will be used to translate the y, y1 and y2 of all path elements.
1672
+ * @return The current path object for easy call chaining.
1673
+ */ translate(x, y) {
1674
+ forEachParam(this.pathElements, (pathElement, paramName)=>{
1675
+ pathElement[paramName] += paramName[0] === "x" ? x : y;
1676
+ });
1677
+ return this;
1678
+ }
1679
+ /**
1680
+ * This function will run over all existing path elements and then loop over their attributes. The callback function will be called for every path element attribute that exists in the current path.
1681
+ * The method signature of the callback function looks like this:
1682
+ * ```javascript
1683
+ * function(pathElement, paramName, pathElementIndex, paramIndex, pathElements)
1684
+ * ```
1685
+ * If something else than undefined is returned by the callback function, this value will be used to replace the old value. This allows you to build custom transformations of path objects that can't be achieved using the basic transformation functions scale and translate.
1686
+ * @param transformFnc The callback function for the transformation. Check the signature in the function description.
1687
+ * @return The current path object for easy call chaining.
1688
+ */ transform(transformFnc) {
1689
+ forEachParam(this.pathElements, (pathElement, paramName, pathElementIndex, paramIndex, pathElements)=>{
1690
+ const transformed = transformFnc(pathElement, paramName, pathElementIndex, paramIndex, pathElements);
1691
+ if (transformed || transformed === 0) {
1692
+ pathElement[paramName] = transformed;
1693
+ }
1694
+ });
1695
+ return this;
1696
+ }
1697
+ /**
1698
+ * This function clones a whole path object with all its properties. This is a deep clone and path element objects will also be cloned.
1699
+ * @param close Optional option to set the new cloned path to closed. If not specified or false, the original path close option will be used.
1700
+ */ clone() {
1701
+ let close = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
1702
+ const clone = new SvgPath(close || this.close);
1703
+ clone.pos = this.pos;
1704
+ clone.pathElements = this.pathElements.slice().map((pathElement)=>({
1705
+ ...pathElement
1706
+ })
1707
+ );
1708
+ clone.options = {
1709
+ ...this.options
1710
+ };
1711
+ return clone;
1712
+ }
1713
+ /**
1714
+ * Split a Svg.Path object by a specific command in the path chain. The path chain will be split and an array of newly created paths objects will be returned. This is useful if you'd like to split an SVG path by it's move commands, for example, in order to isolate chunks of drawings.
1715
+ * @param command The command you'd like to use to split the path
1716
+ */ splitByCommand(command) {
1717
+ const split = [
1718
+ new SvgPath()
1719
+ ];
1720
+ this.pathElements.forEach((pathElement)=>{
1721
+ if (pathElement.command === command.toUpperCase() && split[split.length - 1].pathElements.length !== 0) {
1722
+ split.push(new SvgPath());
1723
+ }
1724
+ split[split.length - 1].pathElements.push(pathElement);
1725
+ });
1726
+ return split;
1727
+ }
1728
+ /**
1729
+ * Used to construct a new path object.
1730
+ * @param close If set to true then this path will be closed when stringified (with a Z at the end)
1731
+ * @param options Options object that overrides the default objects. See default options for more details.
1732
+ */ constructor(close = false, options){
1733
+ this.close = close;
1734
+ this.pathElements = [];
1735
+ this.pos = 0;
1736
+ this.options = {
1737
+ ...defaultOptions$3,
1738
+ ...options
1739
+ };
1740
+ }
1741
+ }
1742
+
1743
+ /**
1744
+ * This interpolation function does not smooth the path and the result is only containing lines and no curves.
1745
+ *
1746
+ * @example
1747
+ * const chart = new LineChart('.ct-chart', {
1748
+ * labels: [1, 2, 3, 4, 5],
1749
+ * series: [[1, 2, 8, 1, 7]]
1750
+ * }, {
1751
+ * lineSmooth: Interpolation.none({
1752
+ * fillHoles: false
1753
+ * })
1754
+ * });
1755
+ */ function none(options) {
1756
+ const finalOptions = {
1757
+ fillHoles: false,
1758
+ ...options
1759
+ };
1760
+ return function noneInterpolation(pathCoordinates, valueData) {
1761
+ const path = new SvgPath();
1762
+ let hole = true;
1763
+ for(let i = 0; i < pathCoordinates.length; i += 2){
1764
+ const currX = pathCoordinates[i];
1765
+ const currY = pathCoordinates[i + 1];
1766
+ const currData = valueData[i / 2];
1767
+ if (getMultiValue(currData.value) !== undefined) {
1768
+ if (hole) {
1769
+ path.move(currX, currY, false, currData);
1770
+ } else {
1771
+ path.line(currX, currY, false, currData);
1772
+ }
1773
+ hole = false;
1774
+ } else if (!finalOptions.fillHoles) {
1775
+ hole = true;
1776
+ }
1777
+ }
1778
+ return path;
1779
+ };
1780
+ }
1781
+
1782
+ /**
1783
+ * Simple smoothing creates horizontal handles that are positioned with a fraction of the length between two data points. You can use the divisor option to specify the amount of smoothing.
1784
+ *
1785
+ * Simple smoothing can be used instead of `Chartist.Smoothing.cardinal` if you'd like to get rid of the artifacts it produces sometimes. Simple smoothing produces less flowing lines but is accurate by hitting the points and it also doesn't swing below or above the given data point.
1786
+ *
1787
+ * All smoothing functions within Chartist are factory functions that accept an options parameter. The simple interpolation function accepts one configuration parameter `divisor`, between 1 and ∞, which controls the smoothing characteristics.
1788
+ *
1789
+ * @example
1790
+ * const chart = new LineChart('.ct-chart', {
1791
+ * labels: [1, 2, 3, 4, 5],
1792
+ * series: [[1, 2, 8, 1, 7]]
1793
+ * }, {
1794
+ * lineSmooth: Interpolation.simple({
1795
+ * divisor: 2,
1796
+ * fillHoles: false
1797
+ * })
1798
+ * });
1799
+ *
1800
+ * @param options The options of the simple interpolation factory function.
1801
+ */ function simple(options) {
1802
+ const finalOptions = {
1803
+ divisor: 2,
1804
+ fillHoles: false,
1805
+ ...options
1806
+ };
1807
+ const d = 1 / Math.max(1, finalOptions.divisor);
1808
+ return function simpleInterpolation(pathCoordinates, valueData) {
1809
+ const path = new SvgPath();
1810
+ let prevX = 0;
1811
+ let prevY = 0;
1812
+ let prevData;
1813
+ for(let i = 0; i < pathCoordinates.length; i += 2){
1814
+ const currX = pathCoordinates[i];
1815
+ const currY = pathCoordinates[i + 1];
1816
+ const length = (currX - prevX) * d;
1817
+ const currData = valueData[i / 2];
1818
+ if (currData.value !== undefined) {
1819
+ if (prevData === undefined) {
1820
+ path.move(currX, currY, false, currData);
1821
+ } else {
1822
+ path.curve(prevX + length, prevY, currX - length, currY, currX, currY, false, currData);
1823
+ }
1824
+ prevX = currX;
1825
+ prevY = currY;
1826
+ prevData = currData;
1827
+ } else if (!finalOptions.fillHoles) {
1828
+ prevX = prevY = 0;
1829
+ prevData = undefined;
1830
+ }
1831
+ }
1832
+ return path;
1833
+ };
1834
+ }
1835
+
1836
+ /**
1837
+ * Step interpolation will cause the line chart to move in steps rather than diagonal or smoothed lines. This interpolation will create additional points that will also be drawn when the `showPoint` option is enabled.
1838
+ *
1839
+ * All smoothing functions within Chartist are factory functions that accept an options parameter. The step interpolation function accepts one configuration parameter `postpone`, that can be `true` or `false`. The default value is `true` and will cause the step to occur where the value actually changes. If a different behaviour is needed where the step is shifted to the left and happens before the actual value, this option can be set to `false`.
1840
+ *
1841
+ * @example
1842
+ * var chart = new Chartist.Line('.ct-chart', {
1843
+ * labels: [1, 2, 3, 4, 5],
1844
+ * series: [[1, 2, 8, 1, 7]]
1845
+ * }, {
1846
+ * lineSmooth: Interpolation.step({
1847
+ * postpone: true,
1848
+ * fillHoles: false
1849
+ * })
1850
+ * });
1851
+ */ function step(options) {
1852
+ const finalOptions = {
1853
+ postpone: true,
1854
+ fillHoles: false,
1855
+ ...options
1856
+ };
1857
+ return function stepInterpolation(pathCoordinates, valueData) {
1858
+ const path = new SvgPath();
1859
+ let prevX = 0;
1860
+ let prevY = 0;
1861
+ let prevData;
1862
+ for(let i = 0; i < pathCoordinates.length; i += 2){
1863
+ const currX = pathCoordinates[i];
1864
+ const currY = pathCoordinates[i + 1];
1865
+ const currData = valueData[i / 2];
1866
+ // If the current point is also not a hole we can draw the step lines
1867
+ if (currData.value !== undefined) {
1868
+ if (prevData === undefined) {
1869
+ path.move(currX, currY, false, currData);
1870
+ } else {
1871
+ if (finalOptions.postpone) {
1872
+ // If postponed we should draw the step line with the value of the previous value
1873
+ path.line(currX, prevY, false, prevData);
1874
+ } else {
1875
+ // If not postponed we should draw the step line with the value of the current value
1876
+ path.line(prevX, currY, false, currData);
1877
+ }
1878
+ // Line to the actual point (this should only be a Y-Axis movement
1879
+ path.line(currX, currY, false, currData);
1880
+ }
1881
+ prevX = currX;
1882
+ prevY = currY;
1883
+ prevData = currData;
1884
+ } else if (!finalOptions.fillHoles) {
1885
+ prevX = prevY = 0;
1886
+ prevData = undefined;
1887
+ }
1888
+ }
1889
+ return path;
1890
+ };
1891
+ }
1892
+
1893
+ /**
1894
+ * Cardinal / Catmull-Rome spline interpolation is the default smoothing function in Chartist. It produces nice results where the splines will always meet the points. It produces some artifacts though when data values are increased or decreased rapidly. The line may not follow a very accurate path and if the line should be accurate this smoothing function does not produce the best results.
1895
+ *
1896
+ * Cardinal splines can only be created if there are more than two data points. If this is not the case this smoothing will fallback to `Chartist.Smoothing.none`.
1897
+ *
1898
+ * All smoothing functions within Chartist are factory functions that accept an options parameter. The cardinal interpolation function accepts one configuration parameter `tension`, between 0 and 1, which controls the smoothing intensity.
1899
+ *
1900
+ * @example
1901
+ * const chart = new LineChart('.ct-chart', {
1902
+ * labels: [1, 2, 3, 4, 5],
1903
+ * series: [[1, 2, 8, 1, 7]]
1904
+ * }, {
1905
+ * lineSmooth: Interpolation.cardinal({
1906
+ * tension: 1,
1907
+ * fillHoles: false
1908
+ * })
1909
+ * });
1910
+ *
1911
+ * @param options The options of the cardinal factory function.
1912
+ */ function cardinal(options) {
1913
+ const finalOptions = {
1914
+ tension: 1,
1915
+ fillHoles: false,
1916
+ ...options
1917
+ };
1918
+ const t = Math.min(1, Math.max(0, finalOptions.tension));
1919
+ const c = 1 - t;
1920
+ return function cardinalInterpolation(pathCoordinates, valueData) {
1921
+ // First we try to split the coordinates into segments
1922
+ // This is necessary to treat "holes" in line charts
1923
+ const segments = splitIntoSegments(pathCoordinates, valueData, {
1924
+ fillHoles: finalOptions.fillHoles
1925
+ });
1926
+ if (!segments.length) {
1927
+ // If there were no segments return 'none' interpolation
1928
+ return none()([], []);
1929
+ } else if (segments.length > 1) {
1930
+ // If the split resulted in more that one segment we need to interpolate each segment individually and join them
1931
+ // afterwards together into a single path.
1932
+ // For each segment we will recurse the cardinal function
1933
+ // Join the segment path data into a single path and return
1934
+ return SvgPath.join(segments.map((segment)=>cardinalInterpolation(segment.pathCoordinates, segment.valueData)
1935
+ ));
1936
+ } else {
1937
+ // If there was only one segment we can proceed regularly by using pathCoordinates and valueData from the first
1938
+ // segment
1939
+ pathCoordinates = segments[0].pathCoordinates;
1940
+ valueData = segments[0].valueData;
1941
+ // If less than two points we need to fallback to no smoothing
1942
+ if (pathCoordinates.length <= 4) {
1943
+ return none()(pathCoordinates, valueData);
1944
+ }
1945
+ const path = new SvgPath().move(pathCoordinates[0], pathCoordinates[1], false, valueData[0]);
1946
+ const z = false;
1947
+ for(let i = 0, iLen = pathCoordinates.length; iLen - 2 * Number(!z) > i; i += 2){
1948
+ const p = [
1949
+ {
1950
+ x: +pathCoordinates[i - 2],
1951
+ y: +pathCoordinates[i - 1]
1952
+ },
1953
+ {
1954
+ x: +pathCoordinates[i],
1955
+ y: +pathCoordinates[i + 1]
1956
+ },
1957
+ {
1958
+ x: +pathCoordinates[i + 2],
1959
+ y: +pathCoordinates[i + 3]
1960
+ },
1961
+ {
1962
+ x: +pathCoordinates[i + 4],
1963
+ y: +pathCoordinates[i + 5]
1964
+ }
1965
+ ];
1966
+ {
1967
+ if (iLen - 4 === i) {
1968
+ p[3] = p[2];
1969
+ } else if (!i) {
1970
+ p[0] = {
1971
+ x: +pathCoordinates[i],
1972
+ y: +pathCoordinates[i + 1]
1973
+ };
1974
+ }
1975
+ }
1976
+ path.curve(t * (-p[0].x + 6 * p[1].x + p[2].x) / 6 + c * p[2].x, t * (-p[0].y + 6 * p[1].y + p[2].y) / 6 + c * p[2].y, t * (p[1].x + 6 * p[2].x - p[3].x) / 6 + c * p[2].x, t * (p[1].y + 6 * p[2].y - p[3].y) / 6 + c * p[2].y, p[2].x, p[2].y, false, valueData[(i + 2) / 2]);
1977
+ }
1978
+ return path;
1979
+ }
1980
+ };
1981
+ }
1982
+
1983
+ /**
1984
+ * Monotone Cubic spline interpolation produces a smooth curve which preserves monotonicity. Unlike cardinal splines, the curve will not extend beyond the range of y-values of the original data points.
1985
+ *
1986
+ * Monotone Cubic splines can only be created if there are more than two data points. If this is not the case this smoothing will fallback to `Chartist.Smoothing.none`.
1987
+ *
1988
+ * The x-values of subsequent points must be increasing to fit a Monotone Cubic spline. If this condition is not met for a pair of adjacent points, then there will be a break in the curve between those data points.
1989
+ *
1990
+ * All smoothing functions within Chartist are factory functions that accept an options parameter.
1991
+ *
1992
+ * @example
1993
+ * const chart = new LineChart('.ct-chart', {
1994
+ * labels: [1, 2, 3, 4, 5],
1995
+ * series: [[1, 2, 8, 1, 7]]
1996
+ * }, {
1997
+ * lineSmooth: Interpolation.monotoneCubic({
1998
+ * fillHoles: false
1999
+ * })
2000
+ * });
2001
+ *
2002
+ * @param options The options of the monotoneCubic factory function.
2003
+ */ function monotoneCubic(options) {
2004
+ const finalOptions = {
2005
+ fillHoles: false,
2006
+ ...options
2007
+ };
2008
+ return function monotoneCubicInterpolation(pathCoordinates, valueData) {
2009
+ // First we try to split the coordinates into segments
2010
+ // This is necessary to treat "holes" in line charts
2011
+ const segments = splitIntoSegments(pathCoordinates, valueData, {
2012
+ fillHoles: finalOptions.fillHoles,
2013
+ increasingX: true
2014
+ });
2015
+ if (!segments.length) {
2016
+ // If there were no segments return 'Chartist.Interpolation.none'
2017
+ return none()([], []);
2018
+ } else if (segments.length > 1) {
2019
+ // If the split resulted in more that one segment we need to interpolate each segment individually and join them
2020
+ // afterwards together into a single path.
2021
+ // For each segment we will recurse the monotoneCubic fn function
2022
+ // Join the segment path data into a single path and return
2023
+ return SvgPath.join(segments.map((segment)=>monotoneCubicInterpolation(segment.pathCoordinates, segment.valueData)
2024
+ ));
2025
+ } else {
2026
+ // If there was only one segment we can proceed regularly by using pathCoordinates and valueData from the first
2027
+ // segment
2028
+ pathCoordinates = segments[0].pathCoordinates;
2029
+ valueData = segments[0].valueData;
2030
+ // If less than three points we need to fallback to no smoothing
2031
+ if (pathCoordinates.length <= 4) {
2032
+ return none()(pathCoordinates, valueData);
2033
+ }
2034
+ const xs = [];
2035
+ const ys = [];
2036
+ const n = pathCoordinates.length / 2;
2037
+ const ms = [];
2038
+ const ds = [];
2039
+ const dys = [];
2040
+ const dxs = [];
2041
+ // Populate x and y coordinates into separate arrays, for readability
2042
+ for(let i = 0; i < n; i++){
2043
+ xs[i] = pathCoordinates[i * 2];
2044
+ ys[i] = pathCoordinates[i * 2 + 1];
2045
+ }
2046
+ // Calculate deltas and derivative
2047
+ for(let i1 = 0; i1 < n - 1; i1++){
2048
+ dys[i1] = ys[i1 + 1] - ys[i1];
2049
+ dxs[i1] = xs[i1 + 1] - xs[i1];
2050
+ ds[i1] = dys[i1] / dxs[i1];
2051
+ }
2052
+ // Determine desired slope (m) at each point using Fritsch-Carlson method
2053
+ // See: http://math.stackexchange.com/questions/45218/implementation-of-monotone-cubic-interpolation
2054
+ ms[0] = ds[0];
2055
+ ms[n - 1] = ds[n - 2];
2056
+ for(let i2 = 1; i2 < n - 1; i2++){
2057
+ if (ds[i2] === 0 || ds[i2 - 1] === 0 || ds[i2 - 1] > 0 !== ds[i2] > 0) {
2058
+ ms[i2] = 0;
2059
+ } else {
2060
+ ms[i2] = 3 * (dxs[i2 - 1] + dxs[i2]) / ((2 * dxs[i2] + dxs[i2 - 1]) / ds[i2 - 1] + (dxs[i2] + 2 * dxs[i2 - 1]) / ds[i2]);
2061
+ if (!isFinite(ms[i2])) {
2062
+ ms[i2] = 0;
2063
+ }
2064
+ }
2065
+ }
2066
+ // Now build a path from the slopes
2067
+ const path = new SvgPath().move(xs[0], ys[0], false, valueData[0]);
2068
+ for(let i3 = 0; i3 < n - 1; i3++){
2069
+ path.curve(// First control point
2070
+ xs[i3] + dxs[i3] / 3, ys[i3] + ms[i3] * dxs[i3] / 3, // Second control point
2071
+ xs[i3 + 1] - dxs[i3] / 3, ys[i3 + 1] - ms[i3 + 1] * dxs[i3] / 3, // End point
2072
+ xs[i3 + 1], ys[i3 + 1], false, valueData[i3 + 1]);
2073
+ }
2074
+ return path;
2075
+ }
2076
+ };
2077
+ }
2078
+
2079
+ var index = /*#__PURE__*/Object.freeze({
2080
+ __proto__: null,
2081
+ none: none,
2082
+ simple: simple,
2083
+ step: step,
2084
+ cardinal: cardinal,
2085
+ monotoneCubic: monotoneCubic
2086
+ });
2087
+
2088
+ class EventEmitter {
2089
+ on(event, listener) {
2090
+ const { allListeners , listeners } = this;
2091
+ if (event === "*") {
2092
+ allListeners.add(listener);
2093
+ } else {
2094
+ if (!listeners.has(event)) {
2095
+ listeners.set(event, new Set());
2096
+ }
2097
+ listeners.get(event).add(listener);
2098
+ }
2099
+ }
2100
+ off(event, listener) {
2101
+ const { allListeners , listeners } = this;
2102
+ if (event === "*") {
2103
+ if (listener) {
2104
+ allListeners.delete(listener);
2105
+ } else {
2106
+ allListeners.clear();
2107
+ }
2108
+ } else if (listeners.has(event)) {
2109
+ const eventListeners = listeners.get(event);
2110
+ if (listener) {
2111
+ eventListeners.delete(listener);
2112
+ } else {
2113
+ eventListeners.clear();
2114
+ }
2115
+ if (!eventListeners.size) {
2116
+ listeners.delete(event);
2117
+ }
2118
+ }
2119
+ }
2120
+ /**
2121
+ * Use this function to emit an event. All handlers that are listening for this event will be triggered with the data parameter.
2122
+ * @param event The event name that should be triggered
2123
+ * @param data Arbitrary data that will be passed to the event handler callback functions
2124
+ */ emit(event, data) {
2125
+ const { allListeners , listeners } = this;
2126
+ // Only do something if there are event handlers with this name existing
2127
+ if (listeners.has(event)) {
2128
+ listeners.get(event).forEach((listener)=>listener(data)
2129
+ );
2130
+ }
2131
+ // Emit event to star event handlers
2132
+ allListeners.forEach((listener)=>listener(event, data)
2133
+ );
2134
+ }
2135
+ constructor(){
2136
+ this.listeners = new Map();
2137
+ this.allListeners = new Set();
2138
+ }
2139
+ }
2140
+
2141
+ const instances = new WeakMap();
2142
+ class BaseChart {
2143
+ // TODO: Currently we need to re-draw the chart on window resize. This is usually very bad and will affect performance.
2144
+ // This is done because we can't work with relative coordinates when drawing the chart because SVG Path does not
2145
+ // work with relative positions yet. We need to check if we can do a viewBox hack to switch to percentage.
2146
+ // See http://mozilla.6506.n7.nabble.com/Specyfing-paths-with-percentages-unit-td247474.html
2147
+ // Update: can be done using the above method tested here: http://codepen.io/gionkunz/pen/KDvLj
2148
+ // The problem is with the label offsets that can't be converted into percentage and affecting the chart container
2149
+ /**
2150
+ * Updates the chart which currently does a full reconstruction of the SVG DOM
2151
+ * @param data Optional data you'd like to set for the chart before it will update. If not specified the update method will use the data that is already configured with the chart.
2152
+ * @param options Optional options you'd like to add to the previous options for the chart before it will update. If not specified the update method will use the options that have been already configured with the chart.
2153
+ * @param override If set to true, the passed options will be used to extend the options that have been configured already. Otherwise the chart default options will be used as the base
2154
+ */ update(data, options) {
2155
+ let override = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
2156
+ if (data) {
2157
+ this.data = data || {};
2158
+ this.data.labels = this.data.labels || [];
2159
+ this.data.series = this.data.series || [];
2160
+ // Event for data transformation that allows to manipulate the data before it gets rendered in the charts
2161
+ this.eventEmitter.emit("data", {
2162
+ type: "update",
2163
+ data: this.data
2164
+ });
2165
+ }
2166
+ if (options) {
2167
+ this.options = extend({}, override ? this.options : this.defaultOptions, options);
2168
+ // If chartist was not initialized yet, we just set the options and leave the rest to the initialization
2169
+ // Otherwise we re-create the optionsProvider at this point
2170
+ if (!this.initializeTimeoutId) {
2171
+ var ref;
2172
+ (ref = this.optionsProvider) === null || ref === void 0 ? void 0 : ref.removeMediaQueryListeners();
2173
+ this.optionsProvider = optionsProvider(this.options, this.responsiveOptions, this.eventEmitter);
2174
+ }
2175
+ }
2176
+ // Only re-created the chart if it has been initialized yet
2177
+ if (!this.initializeTimeoutId && this.optionsProvider) {
2178
+ this.createChart(this.optionsProvider.getCurrentOptions());
2179
+ }
2180
+ // Return a reference to the chart object to chain up calls
2181
+ return this;
2182
+ }
2183
+ /**
2184
+ * This method can be called on the API object of each chart and will un-register all event listeners that were added to other components. This currently includes a window.resize listener as well as media query listeners if any responsive options have been provided. Use this function if you need to destroy and recreate Chartist charts dynamically.
2185
+ */ detach() {
2186
+ // Only detach if initialization already occurred on this chart. If this chart still hasn't initialized (therefore
2187
+ // the initializationTimeoutId is still a valid timeout reference, we will clear the timeout
2188
+ if (!this.initializeTimeoutId) {
2189
+ var ref;
2190
+ window.removeEventListener("resize", this.resizeListener);
2191
+ (ref = this.optionsProvider) === null || ref === void 0 ? void 0 : ref.removeMediaQueryListeners();
2192
+ } else {
2193
+ window.clearTimeout(this.initializeTimeoutId);
2194
+ }
2195
+ instances.delete(this.container);
2196
+ return this;
2197
+ }
2198
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2199
+ on(event, listener) {
2200
+ this.eventEmitter.on(event, listener);
2201
+ return this;
2202
+ }
2203
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2204
+ off(event, listener) {
2205
+ this.eventEmitter.off(event, listener);
2206
+ return this;
2207
+ }
2208
+ initialize() {
2209
+ // Add window resize listener that re-creates the chart
2210
+ window.addEventListener("resize", this.resizeListener);
2211
+ // Obtain current options based on matching media queries (if responsive options are given)
2212
+ // This will also register a listener that is re-creating the chart based on media changes
2213
+ this.optionsProvider = optionsProvider(this.options, this.responsiveOptions, this.eventEmitter);
2214
+ // Register options change listener that will trigger a chart update
2215
+ this.eventEmitter.on("optionsChanged", ()=>this.update()
2216
+ );
2217
+ // Before the first chart creation we need to register us with all plugins that are configured
2218
+ // Initialize all relevant plugins with our chart object and the plugin options specified in the config
2219
+ if (this.options.plugins) {
2220
+ this.options.plugins.forEach((plugin)=>{
2221
+ if (Array.isArray(plugin)) {
2222
+ plugin[0](this, plugin[1]);
2223
+ } else {
2224
+ plugin(this);
2225
+ }
2226
+ });
2227
+ }
2228
+ // Event for data transformation that allows to manipulate the data before it gets rendered in the charts
2229
+ this.eventEmitter.emit("data", {
2230
+ type: "initial",
2231
+ data: this.data
2232
+ });
2233
+ // Create the first chart
2234
+ this.createChart(this.optionsProvider.getCurrentOptions());
2235
+ // As chart is initialized from the event loop now we can reset our timeout reference
2236
+ // This is important if the chart gets initialized on the same element twice
2237
+ this.initializeTimeoutId = null;
2238
+ }
2239
+ constructor(query, data, defaultOptions, options, responsiveOptions){
2240
+ this.data = data;
2241
+ this.defaultOptions = defaultOptions;
2242
+ this.options = options;
2243
+ this.responsiveOptions = responsiveOptions;
2244
+ this.eventEmitter = new EventEmitter();
2245
+ this.resizeListener = ()=>this.update()
2246
+ ;
2247
+ this.initializeTimeoutId = setTimeout(()=>this.initialize()
2248
+ , 0);
2249
+ const container = typeof query === "string" ? document.querySelector(query) : query;
2250
+ if (!container) {
2251
+ throw new Error("Target element is not found");
2252
+ }
2253
+ this.container = container;
2254
+ const prevInstance = instances.get(container);
2255
+ // If chartist was already initialized in this container we are detaching all event listeners first
2256
+ if (prevInstance) {
2257
+ prevInstance.detach();
2258
+ }
2259
+ instances.set(container, this);
2260
+ }
2261
+ }
2262
+
2263
+ const axisUnits = {
2264
+ x: {
2265
+ pos: "x",
2266
+ len: "width",
2267
+ dir: "horizontal",
2268
+ rectStart: "x1",
2269
+ rectEnd: "x2",
2270
+ rectOffset: "y2"
2271
+ },
2272
+ y: {
2273
+ pos: "y",
2274
+ len: "height",
2275
+ dir: "vertical",
2276
+ rectStart: "y2",
2277
+ rectEnd: "y1",
2278
+ rectOffset: "x1"
2279
+ }
2280
+ };
2281
+ class Axis {
2282
+ createGridAndLabels(gridGroup, labelGroup, chartOptions, eventEmitter) {
2283
+ const axisOptions = this.units.pos === "x" ? chartOptions.axisX : chartOptions.axisY;
2284
+ const projectedValues = this.ticks.map((tick, i)=>this.projectValue(tick, i)
2285
+ );
2286
+ const labelValues = this.ticks.map(axisOptions.labelInterpolationFnc);
2287
+ projectedValues.forEach((projectedValue, index)=>{
2288
+ const labelValue = labelValues[index];
2289
+ const labelOffset = {
2290
+ x: 0,
2291
+ y: 0
2292
+ };
2293
+ // TODO: Find better solution for solving this problem
2294
+ // Calculate how much space we have available for the label
2295
+ let labelLength;
2296
+ if (projectedValues[index + 1]) {
2297
+ // If we still have one label ahead, we can calculate the distance to the next tick / label
2298
+ labelLength = projectedValues[index + 1] - projectedValue;
2299
+ } else {
2300
+ // If we don't have a label ahead and we have only two labels in total, we just take the remaining distance to
2301
+ // on the whole axis length. We limit that to a minimum of 30 pixel, so that labels close to the border will
2302
+ // still be visible inside of the chart padding.
2303
+ labelLength = Math.max(this.axisLength - projectedValue, 30);
2304
+ }
2305
+ // Skip grid lines and labels where interpolated label values are falsey (except for 0)
2306
+ if (labelValue !== "" && isFalseyButZero(labelValue)) {
2307
+ return;
2308
+ }
2309
+ // Transform to global coordinates using the chartRect
2310
+ // We also need to set the label offset for the createLabel function
2311
+ if (this.units.pos === "x") {
2312
+ projectedValue = this.chartRect.x1 + projectedValue;
2313
+ labelOffset.x = chartOptions.axisX.labelOffset.x;
2314
+ // If the labels should be positioned in start position (top side for vertical axis) we need to set a
2315
+ // different offset as for positioned with end (bottom)
2316
+ if (chartOptions.axisX.position === "start") {
2317
+ labelOffset.y = this.chartRect.padding.top + chartOptions.axisX.labelOffset.y + 5;
2318
+ } else {
2319
+ labelOffset.y = this.chartRect.y1 + chartOptions.axisX.labelOffset.y + 5;
2320
+ }
2321
+ } else {
2322
+ projectedValue = this.chartRect.y1 - projectedValue;
2323
+ labelOffset.y = chartOptions.axisY.labelOffset.y - labelLength;
2324
+ // If the labels should be positioned in start position (left side for horizontal axis) we need to set a
2325
+ // different offset as for positioned with end (right side)
2326
+ if (chartOptions.axisY.position === "start") {
2327
+ labelOffset.x = this.chartRect.padding.left + chartOptions.axisY.labelOffset.x;
2328
+ } else {
2329
+ labelOffset.x = this.chartRect.x2 + chartOptions.axisY.labelOffset.x + 10;
2330
+ }
2331
+ }
2332
+ if (axisOptions.showGrid) {
2333
+ createGrid(projectedValue, index, this, this.gridOffset, this.chartRect[this.counterUnits.len](), gridGroup, [
2334
+ chartOptions.classNames.grid,
2335
+ chartOptions.classNames[this.units.dir]
2336
+ ], eventEmitter);
2337
+ }
2338
+ if (axisOptions.showLabel) {
2339
+ createLabel(projectedValue, labelLength, index, labelValue, this, axisOptions.offset, labelOffset, labelGroup, [
2340
+ chartOptions.classNames.label,
2341
+ chartOptions.classNames[this.units.dir],
2342
+ axisOptions.position === "start" ? chartOptions.classNames[axisOptions.position] : chartOptions.classNames.end
2343
+ ], eventEmitter);
2344
+ }
2345
+ });
2346
+ }
2347
+ constructor(units, chartRect, ticks){
2348
+ this.units = units;
2349
+ this.chartRect = chartRect;
2350
+ this.ticks = ticks;
2351
+ this.counterUnits = units === axisUnits.x ? axisUnits.y : axisUnits.x;
2352
+ this.axisLength = chartRect[this.units.rectEnd] - chartRect[this.units.rectStart];
2353
+ this.gridOffset = chartRect[this.units.rectOffset];
2354
+ }
2355
+ }
2356
+
2357
+ class AutoScaleAxis extends Axis {
2358
+ projectValue(value) {
2359
+ const finalValue = Number(getMultiValue(value, this.units.pos));
2360
+ return this.axisLength * (finalValue - this.bounds.min) / this.bounds.range;
2361
+ }
2362
+ constructor(axisUnit, data, chartRect, options){
2363
+ // Usually we calculate highLow based on the data but this can be overriden by a highLow object in the options
2364
+ const highLow = options.highLow || getHighLow(data, options, axisUnit.pos);
2365
+ const bounds = getBounds(chartRect[axisUnit.rectEnd] - chartRect[axisUnit.rectStart], highLow, options.scaleMinSpace || 20, options.onlyInteger);
2366
+ const range = {
2367
+ min: bounds.min,
2368
+ max: bounds.max
2369
+ };
2370
+ super(axisUnit, chartRect, bounds.values);
2371
+ this.bounds = bounds;
2372
+ this.range = range;
2373
+ }
2374
+ }
2375
+
2376
+ class FixedScaleAxis extends Axis {
2377
+ projectValue(value) {
2378
+ const finalValue = Number(getMultiValue(value, this.units.pos));
2379
+ return this.axisLength * (finalValue - this.range.min) / (this.range.max - this.range.min);
2380
+ }
2381
+ constructor(axisUnit, data, chartRect, options){
2382
+ const highLow = options.highLow || getHighLow(data, options, axisUnit.pos);
2383
+ const divisor = options.divisor || 1;
2384
+ const ticks = (options.ticks || times(divisor).map((_value, index)=>highLow.low + (highLow.high - highLow.low) / divisor * index
2385
+ )).sort((a, b)=>Number(a) - Number(b)
2386
+ );
2387
+ const range = {
2388
+ min: highLow.low,
2389
+ max: highLow.high
2390
+ };
2391
+ super(axisUnit, chartRect, ticks);
2392
+ this.range = range;
2393
+ }
2394
+ }
2395
+
2396
+ class StepAxis extends Axis {
2397
+ projectValue(_value, index) {
2398
+ return this.stepLength * index;
2399
+ }
2400
+ constructor(axisUnit, _data, chartRect, options){
2401
+ const ticks = options.ticks || [];
2402
+ super(axisUnit, chartRect, ticks);
2403
+ const calc = Math.max(1, ticks.length - (options.stretch ? 1 : 0));
2404
+ this.stepLength = this.axisLength / calc;
2405
+ this.stretch = Boolean(options.stretch);
2406
+ }
2407
+ }
2408
+
2409
+ function getSeriesOption(series, options, key) {
2410
+ var ref;
2411
+ if (safeHasProperty(series, "name") && series.name && ((ref = options.series) === null || ref === void 0 ? void 0 : ref[series.name])) {
2412
+ const seriesOptions = options === null || options === void 0 ? void 0 : options.series[series.name];
2413
+ const value = seriesOptions[key];
2414
+ const result = value === undefined ? options[key] : value;
2415
+ return result;
2416
+ } else {
2417
+ return options[key];
2418
+ }
2419
+ }
2420
+ /**
2421
+ * Default options in line charts. Expand the code view to see a detailed list of options with comments.
2422
+ */ const defaultOptions$2 = {
2423
+ // Options for X-Axis
2424
+ axisX: {
2425
+ // The offset of the labels to the chart area
2426
+ offset: 30,
2427
+ // Position where labels are placed. Can be set to `start` or `end` where `start` is equivalent to left or top on vertical axis and `end` is equivalent to right or bottom on horizontal axis.
2428
+ position: "end",
2429
+ // Allows you to correct label positioning on this axis by positive or negative x and y offset.
2430
+ labelOffset: {
2431
+ x: 0,
2432
+ y: 0
2433
+ },
2434
+ // If labels should be shown or not
2435
+ showLabel: true,
2436
+ // If the axis grid should be drawn or not
2437
+ showGrid: true,
2438
+ // Interpolation function that allows you to intercept the value from the axis label
2439
+ labelInterpolationFnc: noop,
2440
+ // Set the axis type to be used to project values on this axis. If not defined, Chartist.StepAxis will be used for the X-Axis, where the ticks option will be set to the labels in the data and the stretch option will be set to the global fullWidth option. This type can be changed to any axis constructor available (e.g. Chartist.FixedScaleAxis), where all axis options should be present here.
2441
+ type: undefined
2442
+ },
2443
+ // Options for Y-Axis
2444
+ axisY: {
2445
+ // The offset of the labels to the chart area
2446
+ offset: 40,
2447
+ // Position where labels are placed. Can be set to `start` or `end` where `start` is equivalent to left or top on vertical axis and `end` is equivalent to right or bottom on horizontal axis.
2448
+ position: "start",
2449
+ // Allows you to correct label positioning on this axis by positive or negative x and y offset.
2450
+ labelOffset: {
2451
+ x: 0,
2452
+ y: 0
2453
+ },
2454
+ // If labels should be shown or not
2455
+ showLabel: true,
2456
+ // If the axis grid should be drawn or not
2457
+ showGrid: true,
2458
+ // Interpolation function that allows you to intercept the value from the axis label
2459
+ labelInterpolationFnc: noop,
2460
+ // Set the axis type to be used to project values on this axis. If not defined, Chartist.AutoScaleAxis will be used for the Y-Axis, where the high and low options will be set to the global high and low options. This type can be changed to any axis constructor available (e.g. Chartist.FixedScaleAxis), where all axis options should be present here.
2461
+ type: undefined,
2462
+ // This value specifies the minimum height in pixel of the scale steps
2463
+ scaleMinSpace: 20,
2464
+ // Use only integer values (whole numbers) for the scale steps
2465
+ onlyInteger: false
2466
+ },
2467
+ // Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
2468
+ width: undefined,
2469
+ // Specify a fixed height for the chart as a string (i.e. '100px' or '50%')
2470
+ height: undefined,
2471
+ // If the line should be drawn or not
2472
+ showLine: true,
2473
+ // If dots should be drawn or not
2474
+ showPoint: true,
2475
+ // If the line chart should draw an area
2476
+ showArea: false,
2477
+ // The base for the area chart that will be used to close the area shape (is normally 0)
2478
+ areaBase: 0,
2479
+ // Specify if the lines should be smoothed. This value can be true or false where true will result in smoothing using the default smoothing interpolation function Chartist.Interpolation.cardinal and false results in Chartist.Interpolation.none. You can also choose other smoothing / interpolation functions available in the Chartist.Interpolation module, or write your own interpolation function. Check the examples for a brief description.
2480
+ lineSmooth: true,
2481
+ // If the line chart should add a background fill to the .ct-grids group.
2482
+ showGridBackground: false,
2483
+ // Overriding the natural low of the chart allows you to zoom in or limit the charts lowest displayed value
2484
+ low: undefined,
2485
+ // Overriding the natural high of the chart allows you to zoom in or limit the charts highest displayed value
2486
+ high: undefined,
2487
+ // Padding of the chart drawing area to the container element and labels as a number or padding object {top: 5, right: 5, bottom: 5, left: 5}
2488
+ chartPadding: {
2489
+ top: 15,
2490
+ right: 15,
2491
+ bottom: 5,
2492
+ left: 10
2493
+ },
2494
+ // When set to true, the last grid line on the x-axis is not drawn and the chart elements will expand to the full available width of the chart. For the last label to be drawn correctly you might need to add chart padding or offset the last label with a draw event handler.
2495
+ fullWidth: false,
2496
+ // If true the whole data is reversed including labels, the series order as well as the whole series data arrays.
2497
+ reverseData: false,
2498
+ // Override the class names that get used to generate the SVG structure of the chart
2499
+ classNames: {
2500
+ chart: "ct-chart-line",
2501
+ label: "ct-label",
2502
+ labelGroup: "ct-labels",
2503
+ series: "ct-series",
2504
+ line: "ct-line",
2505
+ point: "ct-point",
2506
+ area: "ct-area",
2507
+ grid: "ct-grid",
2508
+ gridGroup: "ct-grids",
2509
+ gridBackground: "ct-grid-background",
2510
+ vertical: "ct-vertical",
2511
+ horizontal: "ct-horizontal",
2512
+ start: "ct-start",
2513
+ end: "ct-end"
2514
+ }
2515
+ };
2516
+ class LineChart extends BaseChart {
2517
+ /**
2518
+ * Creates a new chart
2519
+ */ createChart(options) {
2520
+ const { data } = this;
2521
+ const normalizedData = normalizeData(data, options.reverseData, true);
2522
+ // Create new svg object
2523
+ const svg = createSvg(this.container, options.width, options.height, options.classNames.chart);
2524
+ this.svg = svg;
2525
+ // Create groups for labels, grid and series
2526
+ const gridGroup = svg.elem("g").addClass(options.classNames.gridGroup);
2527
+ const seriesGroup = svg.elem("g");
2528
+ const labelGroup = svg.elem("g").addClass(options.classNames.labelGroup);
2529
+ const chartRect = createChartRect(svg, options);
2530
+ let axisX;
2531
+ let axisY;
2532
+ if (options.axisX.type === undefined) {
2533
+ axisX = new StepAxis(axisUnits.x, normalizedData.series, chartRect, {
2534
+ ...options.axisX,
2535
+ ticks: normalizedData.labels,
2536
+ stretch: options.fullWidth
2537
+ });
2538
+ } else {
2539
+ // eslint-disable-next-line new-cap
2540
+ axisX = new options.axisX.type(axisUnits.x, normalizedData.series, chartRect, options.axisX);
2541
+ }
2542
+ if (options.axisY.type === undefined) {
2543
+ axisY = new AutoScaleAxis(axisUnits.y, normalizedData.series, chartRect, {
2544
+ ...options.axisY,
2545
+ high: isNumeric(options.high) ? options.high : options.axisY.high,
2546
+ low: isNumeric(options.low) ? options.low : options.axisY.low
2547
+ });
2548
+ } else {
2549
+ // eslint-disable-next-line new-cap
2550
+ axisY = new options.axisY.type(axisUnits.y, normalizedData.series, chartRect, options.axisY);
2551
+ }
2552
+ axisX.createGridAndLabels(gridGroup, labelGroup, options, this.eventEmitter);
2553
+ axisY.createGridAndLabels(gridGroup, labelGroup, options, this.eventEmitter);
2554
+ if (options.showGridBackground) {
2555
+ createGridBackground(gridGroup, chartRect, options.classNames.gridBackground, this.eventEmitter);
2556
+ }
2557
+ // Draw the series
2558
+ data.series.forEach((series, seriesIndex)=>{
2559
+ const seriesElement = seriesGroup.elem("g");
2560
+ const seriesName = safeHasProperty(series, "name") && series.name;
2561
+ const seriesClassName = safeHasProperty(series, "className") && series.className;
2562
+ const seriesMeta = safeHasProperty(series, "meta") ? series.meta : undefined;
2563
+ // Write attributes to series group element. If series name or meta is undefined the attributes will not be written
2564
+ if (seriesName) {
2565
+ seriesElement.attr({
2566
+ "ct:series-name": seriesName
2567
+ });
2568
+ }
2569
+ if (seriesMeta) {
2570
+ seriesElement.attr({
2571
+ "ct:meta": serialize(seriesMeta)
2572
+ });
2573
+ }
2574
+ // Use series class from series data or if not set generate one
2575
+ seriesElement.addClass([
2576
+ options.classNames.series,
2577
+ seriesClassName || "".concat(options.classNames.series, "-").concat(alphaNumerate(seriesIndex))
2578
+ ].join(" "));
2579
+ const pathCoordinates = [];
2580
+ const pathData = [];
2581
+ normalizedData.series[seriesIndex].forEach((value, valueIndex)=>{
2582
+ const p = {
2583
+ x: chartRect.x1 + axisX.projectValue(value, valueIndex, normalizedData.series[seriesIndex]),
2584
+ y: chartRect.y1 - axisY.projectValue(value, valueIndex, normalizedData.series[seriesIndex])
2585
+ };
2586
+ pathCoordinates.push(p.x, p.y);
2587
+ pathData.push({
2588
+ value,
2589
+ valueIndex,
2590
+ meta: getMetaData(series, valueIndex)
2591
+ });
2592
+ });
2593
+ const seriesOptions = {
2594
+ lineSmooth: getSeriesOption(series, options, "lineSmooth"),
2595
+ showPoint: getSeriesOption(series, options, "showPoint"),
2596
+ showLine: getSeriesOption(series, options, "showLine"),
2597
+ showArea: getSeriesOption(series, options, "showArea"),
2598
+ areaBase: getSeriesOption(series, options, "areaBase")
2599
+ };
2600
+ let smoothing;
2601
+ if (typeof seriesOptions.lineSmooth === "function") {
2602
+ smoothing = seriesOptions.lineSmooth;
2603
+ } else {
2604
+ smoothing = seriesOptions.lineSmooth ? monotoneCubic() : none();
2605
+ }
2606
+ // Interpolating path where pathData will be used to annotate each path element so we can trace back the original
2607
+ // index, value and meta data
2608
+ const path = smoothing(pathCoordinates, pathData);
2609
+ // If we should show points we need to create them now to avoid secondary loop
2610
+ // Points are drawn from the pathElements returned by the interpolation function
2611
+ // Small offset for Firefox to render squares correctly
2612
+ if (seriesOptions.showPoint) {
2613
+ path.pathElements.forEach((pathElement)=>{
2614
+ const { data: pathElementData } = pathElement;
2615
+ const point = seriesElement.elem("line", {
2616
+ x1: pathElement.x,
2617
+ y1: pathElement.y,
2618
+ x2: pathElement.x + 0.01,
2619
+ y2: pathElement.y
2620
+ }, options.classNames.point);
2621
+ if (pathElementData) {
2622
+ let x;
2623
+ let y;
2624
+ if (safeHasProperty(pathElementData.value, "x")) {
2625
+ x = pathElementData.value.x;
2626
+ }
2627
+ if (safeHasProperty(pathElementData.value, "y")) {
2628
+ y = pathElementData.value.y;
2629
+ }
2630
+ point.attr({
2631
+ "ct:value": [
2632
+ x,
2633
+ y
2634
+ ].filter(isNumeric).join(","),
2635
+ "ct:meta": serialize(pathElementData.meta)
2636
+ });
2637
+ }
2638
+ this.eventEmitter.emit("draw", {
2639
+ type: "point",
2640
+ value: pathElementData === null || pathElementData === void 0 ? void 0 : pathElementData.value,
2641
+ index: (pathElementData === null || pathElementData === void 0 ? void 0 : pathElementData.valueIndex) || 0,
2642
+ meta: pathElementData === null || pathElementData === void 0 ? void 0 : pathElementData.meta,
2643
+ series,
2644
+ seriesIndex,
2645
+ axisX,
2646
+ axisY,
2647
+ group: seriesElement,
2648
+ element: point,
2649
+ x: pathElement.x,
2650
+ y: pathElement.y,
2651
+ chartRect
2652
+ });
2653
+ });
2654
+ }
2655
+ if (seriesOptions.showLine) {
2656
+ const line = seriesElement.elem("path", {
2657
+ d: path.stringify()
2658
+ }, options.classNames.line, true);
2659
+ this.eventEmitter.emit("draw", {
2660
+ type: "line",
2661
+ values: normalizedData.series[seriesIndex],
2662
+ path: path.clone(),
2663
+ chartRect,
2664
+ // TODO: Remove redundant
2665
+ index: seriesIndex,
2666
+ series,
2667
+ seriesIndex,
2668
+ meta: seriesMeta,
2669
+ axisX,
2670
+ axisY,
2671
+ group: seriesElement,
2672
+ element: line
2673
+ });
2674
+ }
2675
+ // Area currently only works with axes that support a range!
2676
+ if (seriesOptions.showArea && axisY.range) {
2677
+ // If areaBase is outside the chart area (< min or > max) we need to set it respectively so that
2678
+ // the area is not drawn outside the chart area.
2679
+ const areaBase = Math.max(Math.min(seriesOptions.areaBase, axisY.range.max), axisY.range.min);
2680
+ // We project the areaBase value into screen coordinates
2681
+ const areaBaseProjected = chartRect.y1 - axisY.projectValue(areaBase);
2682
+ // In order to form the area we'll first split the path by move commands so we can chunk it up into segments
2683
+ path.splitByCommand("M")// We filter only "solid" segments that contain more than one point. Otherwise there's no need for an area
2684
+ .filter((pathSegment)=>pathSegment.pathElements.length > 1
2685
+ ).map((solidPathSegments)=>{
2686
+ // Receiving the filtered solid path segments we can now convert those segments into fill areas
2687
+ const firstElement = solidPathSegments.pathElements[0];
2688
+ const lastElement = solidPathSegments.pathElements[solidPathSegments.pathElements.length - 1];
2689
+ // Cloning the solid path segment with closing option and removing the first move command from the clone
2690
+ // We then insert a new move that should start at the area base and draw a straight line up or down
2691
+ // at the end of the path we add an additional straight line to the projected area base value
2692
+ // As the closing option is set our path will be automatically closed
2693
+ return solidPathSegments.clone(true).position(0).remove(1).move(firstElement.x, areaBaseProjected).line(firstElement.x, firstElement.y).position(solidPathSegments.pathElements.length + 1).line(lastElement.x, areaBaseProjected);
2694
+ }).forEach((areaPath)=>{
2695
+ // For each of our newly created area paths, we'll now create path elements by stringifying our path objects
2696
+ // and adding the created DOM elements to the correct series group
2697
+ const area = seriesElement.elem("path", {
2698
+ d: areaPath.stringify()
2699
+ }, options.classNames.area, true);
2700
+ // Emit an event for each area that was drawn
2701
+ this.eventEmitter.emit("draw", {
2702
+ type: "area",
2703
+ values: normalizedData.series[seriesIndex],
2704
+ path: areaPath.clone(),
2705
+ series,
2706
+ seriesIndex,
2707
+ axisX,
2708
+ axisY,
2709
+ chartRect,
2710
+ // TODO: Remove redundant
2711
+ index: seriesIndex,
2712
+ group: seriesElement,
2713
+ element: area,
2714
+ meta: seriesMeta
2715
+ });
2716
+ });
2717
+ }
2718
+ });
2719
+ this.eventEmitter.emit("created", {
2720
+ chartRect,
2721
+ axisX,
2722
+ axisY,
2723
+ svg,
2724
+ options
2725
+ });
2726
+ }
2727
+ /**
2728
+ * This method creates a new line chart.
2729
+ * @param query A selector query string or directly a DOM element
2730
+ * @param data The data object that needs to consist of a labels and a series array
2731
+ * @param options The options object with options that override the default options. Check the examples for a detailed list.
2732
+ * @param responsiveOptions Specify an array of responsive option arrays which are a media query and options object pair => [[mediaQueryString, optionsObject],[more...]]
2733
+ * @return An object which exposes the API for the created chart
2734
+ *
2735
+ * @example
2736
+ * // Create a simple line chart
2737
+ * const data = {
2738
+ * // A labels array that can contain any sort of values
2739
+ * labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
2740
+ * // Our series array that contains series objects or in this case series data arrays
2741
+ * series: [
2742
+ * [5, 2, 4, 2, 0]
2743
+ * ]
2744
+ * };
2745
+ *
2746
+ * // As options we currently only set a static size of 300x200 px
2747
+ * const options = {
2748
+ * width: '300px',
2749
+ * height: '200px'
2750
+ * };
2751
+ *
2752
+ * // In the global name space Chartist we call the Line function to initialize a line chart. As a first parameter we pass in a selector where we would like to get our chart created. Second parameter is the actual data object and as a third parameter we pass in our options
2753
+ * new LineChart('.ct-chart', data, options);
2754
+ *
2755
+ * @example
2756
+ * // Use specific interpolation function with configuration from the Chartist.Interpolation module
2757
+ *
2758
+ * const chart = new LineChart('.ct-chart', {
2759
+ * labels: [1, 2, 3, 4, 5],
2760
+ * series: [
2761
+ * [1, 1, 8, 1, 7]
2762
+ * ]
2763
+ * }, {
2764
+ * lineSmooth: Chartist.Interpolation.cardinal({
2765
+ * tension: 0.2
2766
+ * })
2767
+ * });
2768
+ *
2769
+ * @example
2770
+ * // Create a line chart with responsive options
2771
+ *
2772
+ * const data = {
2773
+ * // A labels array that can contain any sort of values
2774
+ * labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
2775
+ * // Our series array that contains series objects or in this case series data arrays
2776
+ * series: [
2777
+ * [5, 2, 4, 2, 0]
2778
+ * ]
2779
+ * };
2780
+ *
2781
+ * // In addition to the regular options we specify responsive option overrides that will override the default configutation based on the matching media queries.
2782
+ * const responsiveOptions = [
2783
+ * ['screen and (min-width: 641px) and (max-width: 1024px)', {
2784
+ * showPoint: false,
2785
+ * axisX: {
2786
+ * labelInterpolationFnc: function(value) {
2787
+ * // Will return Mon, Tue, Wed etc. on medium screens
2788
+ * return value.slice(0, 3);
2789
+ * }
2790
+ * }
2791
+ * }],
2792
+ * ['screen and (max-width: 640px)', {
2793
+ * showLine: false,
2794
+ * axisX: {
2795
+ * labelInterpolationFnc: function(value) {
2796
+ * // Will return M, T, W etc. on small screens
2797
+ * return value[0];
2798
+ * }
2799
+ * }
2800
+ * }]
2801
+ * ];
2802
+ *
2803
+ * new LineChart('.ct-chart', data, null, responsiveOptions);
2804
+ *
2805
+ */ constructor(query, data, options, responsiveOptions){
2806
+ super(query, data, defaultOptions$2, extend({}, defaultOptions$2, options), responsiveOptions);
2807
+ this.data = data;
2808
+ }
2809
+ }
2810
+
2811
+ function getSerialSums(series) {
2812
+ return serialMap(series, function() {
2813
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
2814
+ args[_key] = arguments[_key];
2815
+ }
2816
+ return Array.from(args).reduce((prev, curr)=>{
2817
+ return {
2818
+ x: prev.x + (safeHasProperty(curr, "x") ? curr.x : 0),
2819
+ y: prev.y + (safeHasProperty(curr, "y") ? curr.y : 0)
2820
+ };
2821
+ }, {
2822
+ x: 0,
2823
+ y: 0
2824
+ });
2825
+ });
2826
+ }
2827
+ /**
2828
+ * Default options in bar charts. Expand the code view to see a detailed list of options with comments.
2829
+ */ const defaultOptions$1 = {
2830
+ // Options for X-Axis
2831
+ axisX: {
2832
+ // The offset of the chart drawing area to the border of the container
2833
+ offset: 30,
2834
+ // Position where labels are placed. Can be set to `start` or `end` where `start` is equivalent to left or top on vertical axis and `end` is equivalent to right or bottom on horizontal axis.
2835
+ position: "end",
2836
+ // Allows you to correct label positioning on this axis by positive or negative x and y offset.
2837
+ labelOffset: {
2838
+ x: 0,
2839
+ y: 0
2840
+ },
2841
+ // If labels should be shown or not
2842
+ showLabel: true,
2843
+ // If the axis grid should be drawn or not
2844
+ showGrid: true,
2845
+ // Interpolation function that allows you to intercept the value from the axis label
2846
+ labelInterpolationFnc: noop,
2847
+ // This value specifies the minimum width in pixel of the scale steps
2848
+ scaleMinSpace: 30,
2849
+ // Use only integer values (whole numbers) for the scale steps
2850
+ onlyInteger: false
2851
+ },
2852
+ // Options for Y-Axis
2853
+ axisY: {
2854
+ // The offset of the chart drawing area to the border of the container
2855
+ offset: 40,
2856
+ // Position where labels are placed. Can be set to `start` or `end` where `start` is equivalent to left or top on vertical axis and `end` is equivalent to right or bottom on horizontal axis.
2857
+ position: "start",
2858
+ // Allows you to correct label positioning on this axis by positive or negative x and y offset.
2859
+ labelOffset: {
2860
+ x: 0,
2861
+ y: 0
2862
+ },
2863
+ // If labels should be shown or not
2864
+ showLabel: true,
2865
+ // If the axis grid should be drawn or not
2866
+ showGrid: true,
2867
+ // Interpolation function that allows you to intercept the value from the axis label
2868
+ labelInterpolationFnc: noop,
2869
+ // This value specifies the minimum height in pixel of the scale steps
2870
+ scaleMinSpace: 20,
2871
+ // Use only integer values (whole numbers) for the scale steps
2872
+ onlyInteger: false
2873
+ },
2874
+ // Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
2875
+ width: undefined,
2876
+ // Specify a fixed height for the chart as a string (i.e. '100px' or '50%')
2877
+ height: undefined,
2878
+ // Overriding the natural high of the chart allows you to zoom in or limit the charts highest displayed value
2879
+ high: undefined,
2880
+ // Overriding the natural low of the chart allows you to zoom in or limit the charts lowest displayed value
2881
+ low: undefined,
2882
+ // Unless low/high are explicitly set, bar chart will be centered at zero by default. Set referenceValue to null to auto scale.
2883
+ referenceValue: 0,
2884
+ // Padding of the chart drawing area to the container element and labels as a number or padding object {top: 5, right: 5, bottom: 5, left: 5}
2885
+ chartPadding: {
2886
+ top: 15,
2887
+ right: 15,
2888
+ bottom: 5,
2889
+ left: 10
2890
+ },
2891
+ // Specify the distance in pixel of bars in a group
2892
+ seriesBarDistance: 15,
2893
+ // If set to true this property will cause the series bars to be stacked. Check the `stackMode` option for further stacking options.
2894
+ stackBars: false,
2895
+ // If set to 'overlap' this property will force the stacked bars to draw from the zero line.
2896
+ // If set to 'accumulate' this property will form a total for each series point. This will also influence the y-axis and the overall bounds of the chart. In stacked mode the seriesBarDistance property will have no effect.
2897
+ stackMode: "accumulate",
2898
+ // Inverts the axes of the bar chart in order to draw a horizontal bar chart. Be aware that you also need to invert your axis settings as the Y Axis will now display the labels and the X Axis the values.
2899
+ horizontalBars: false,
2900
+ // If set to true then each bar will represent a series and the data array is expected to be a one dimensional array of data values rather than a series array of series. This is useful if the bar chart should represent a profile rather than some data over time.
2901
+ distributeSeries: false,
2902
+ // If true the whole data is reversed including labels, the series order as well as the whole series data arrays.
2903
+ reverseData: false,
2904
+ // If the bar chart should add a background fill to the .ct-grids group.
2905
+ showGridBackground: false,
2906
+ // Override the class names that get used to generate the SVG structure of the chart
2907
+ classNames: {
2908
+ chart: "ct-chart-bar",
2909
+ horizontalBars: "ct-horizontal-bars",
2910
+ label: "ct-label",
2911
+ labelGroup: "ct-labels",
2912
+ series: "ct-series",
2913
+ bar: "ct-bar",
2914
+ grid: "ct-grid",
2915
+ gridGroup: "ct-grids",
2916
+ gridBackground: "ct-grid-background",
2917
+ vertical: "ct-vertical",
2918
+ horizontal: "ct-horizontal",
2919
+ start: "ct-start",
2920
+ end: "ct-end"
2921
+ }
2922
+ };
2923
+ class BarChart extends BaseChart {
2924
+ /**
2925
+ * Creates a new chart
2926
+ */ createChart(options) {
2927
+ const { data } = this;
2928
+ const normalizedData = normalizeData(data, options.reverseData, options.horizontalBars ? "x" : "y", true);
2929
+ // Create new svg element
2930
+ const svg = createSvg(this.container, options.width, options.height, options.classNames.chart + (options.horizontalBars ? " " + options.classNames.horizontalBars : ""));
2931
+ const highLow = options.stackBars && options.stackMode !== true && normalizedData.series.length ? getHighLow([
2932
+ getSerialSums(normalizedData.series)
2933
+ ], options, options.horizontalBars ? "x" : "y") : getHighLow(normalizedData.series, options, options.horizontalBars ? "x" : "y");
2934
+ this.svg = svg;
2935
+ // Drawing groups in correct order
2936
+ const gridGroup = svg.elem("g").addClass(options.classNames.gridGroup);
2937
+ const seriesGroup = svg.elem("g");
2938
+ const labelGroup = svg.elem("g").addClass(options.classNames.labelGroup);
2939
+ // Overrides of high / low from settings
2940
+ if (typeof options.high === "number") {
2941
+ highLow.high = options.high;
2942
+ }
2943
+ if (typeof options.low === "number") {
2944
+ highLow.low = options.low;
2945
+ }
2946
+ const chartRect = createChartRect(svg, options);
2947
+ let valueAxis;
2948
+ const labelAxisTicks = options.distributeSeries && options.stackBars ? // use only the first label for the step axis
2949
+ normalizedData.labels.slice(0, 1) : // If we are drawing a regular bar chart with two dimensional series data, we just use the labels array
2950
+ // as the bars are normalized
2951
+ normalizedData.labels;
2952
+ let labelAxis;
2953
+ let axisX;
2954
+ let axisY;
2955
+ // Set labelAxis and valueAxis based on the horizontalBars setting. This setting will flip the axes if necessary.
2956
+ if (options.horizontalBars) {
2957
+ if (options.axisX.type === undefined) {
2958
+ valueAxis = axisX = new AutoScaleAxis(axisUnits.x, normalizedData.series, chartRect, {
2959
+ ...options.axisX,
2960
+ highLow: highLow,
2961
+ referenceValue: 0
2962
+ });
2963
+ } else {
2964
+ // eslint-disable-next-line new-cap
2965
+ valueAxis = axisX = new options.axisX.type(axisUnits.x, normalizedData.series, chartRect, {
2966
+ ...options.axisX,
2967
+ highLow: highLow,
2968
+ referenceValue: 0
2969
+ });
2970
+ }
2971
+ if (options.axisY.type === undefined) {
2972
+ labelAxis = axisY = new StepAxis(axisUnits.y, normalizedData.series, chartRect, {
2973
+ ticks: labelAxisTicks
2974
+ });
2975
+ } else {
2976
+ // eslint-disable-next-line new-cap
2977
+ labelAxis = axisY = new options.axisY.type(axisUnits.y, normalizedData.series, chartRect, options.axisY);
2978
+ }
2979
+ } else {
2980
+ if (options.axisX.type === undefined) {
2981
+ labelAxis = axisX = new StepAxis(axisUnits.x, normalizedData.series, chartRect, {
2982
+ ticks: labelAxisTicks
2983
+ });
2984
+ } else {
2985
+ // eslint-disable-next-line new-cap
2986
+ labelAxis = axisX = new options.axisX.type(axisUnits.x, normalizedData.series, chartRect, options.axisX);
2987
+ }
2988
+ if (options.axisY.type === undefined) {
2989
+ valueAxis = axisY = new AutoScaleAxis(axisUnits.y, normalizedData.series, chartRect, {
2990
+ ...options.axisY,
2991
+ highLow: highLow,
2992
+ referenceValue: 0
2993
+ });
2994
+ } else {
2995
+ // eslint-disable-next-line new-cap
2996
+ valueAxis = axisY = new options.axisY.type(axisUnits.y, normalizedData.series, chartRect, {
2997
+ ...options.axisY,
2998
+ highLow: highLow,
2999
+ referenceValue: 0
3000
+ });
3001
+ }
3002
+ }
3003
+ // Projected 0 point
3004
+ const zeroPoint = options.horizontalBars ? chartRect.x1 + valueAxis.projectValue(0) : chartRect.y1 - valueAxis.projectValue(0);
3005
+ // Used to track the screen coordinates of stacked bars
3006
+ const stackedBarValues = [];
3007
+ labelAxis.createGridAndLabels(gridGroup, labelGroup, options, this.eventEmitter);
3008
+ valueAxis.createGridAndLabels(gridGroup, labelGroup, options, this.eventEmitter);
3009
+ if (options.showGridBackground) {
3010
+ createGridBackground(gridGroup, chartRect, options.classNames.gridBackground, this.eventEmitter);
3011
+ }
3012
+ // Draw the series
3013
+ data.series.forEach((series, seriesIndex)=>{
3014
+ // Calculating bi-polar value of index for seriesOffset. For i = 0..4 biPol will be -1.5, -0.5, 0.5, 1.5 etc.
3015
+ const biPol = seriesIndex - (data.series.length - 1) / 2;
3016
+ // Half of the period width between vertical grid lines used to position bars
3017
+ let periodHalfLength;
3018
+ // We need to set periodHalfLength based on some options combinations
3019
+ if (options.distributeSeries && !options.stackBars) {
3020
+ // If distributed series are enabled but stacked bars aren't, we need to use the length of the normaizedData array
3021
+ // which is the series count and divide by 2
3022
+ periodHalfLength = labelAxis.axisLength / normalizedData.series.length / 2;
3023
+ } else if (options.distributeSeries && options.stackBars) {
3024
+ // If distributed series and stacked bars are enabled we'll only get one bar so we should just divide the axis
3025
+ // length by 2
3026
+ periodHalfLength = labelAxis.axisLength / 2;
3027
+ } else {
3028
+ // On regular bar charts we should just use the series length
3029
+ periodHalfLength = labelAxis.axisLength / normalizedData.series[seriesIndex].length / 2;
3030
+ }
3031
+ // Adding the series group to the series element
3032
+ const seriesElement = seriesGroup.elem("g");
3033
+ const seriesName = safeHasProperty(series, "name") && series.name;
3034
+ const seriesClassName = safeHasProperty(series, "className") && series.className;
3035
+ const seriesMeta = safeHasProperty(series, "meta") ? series.meta : undefined;
3036
+ // Write attributes to series group element. If series name or meta is undefined the attributes will not be written
3037
+ if (seriesName) {
3038
+ seriesElement.attr({
3039
+ "ct:series-name": seriesName
3040
+ });
3041
+ }
3042
+ if (seriesMeta) {
3043
+ seriesElement.attr({
3044
+ "ct:meta": serialize(seriesMeta)
3045
+ });
3046
+ }
3047
+ // Use series class from series data or if not set generate one
3048
+ seriesElement.addClass([
3049
+ options.classNames.series,
3050
+ seriesClassName || "".concat(options.classNames.series, "-").concat(alphaNumerate(seriesIndex))
3051
+ ].join(" "));
3052
+ normalizedData.series[seriesIndex].forEach((value, valueIndex)=>{
3053
+ let labelAxisValueIndex;
3054
+ // We need to set labelAxisValueIndex based on some options combinations
3055
+ if (options.distributeSeries && !options.stackBars) {
3056
+ // If distributed series are enabled but stacked bars aren't, we can use the seriesIndex for later projection
3057
+ // on the step axis for label positioning
3058
+ labelAxisValueIndex = seriesIndex;
3059
+ } else if (options.distributeSeries && options.stackBars) {
3060
+ // If distributed series and stacked bars are enabled, we will only get one bar and therefore always use
3061
+ // 0 for projection on the label step axis
3062
+ labelAxisValueIndex = 0;
3063
+ } else {
3064
+ // On regular bar charts we just use the value index to project on the label step axis
3065
+ labelAxisValueIndex = valueIndex;
3066
+ }
3067
+ let projected;
3068
+ // We need to transform coordinates differently based on the chart layout
3069
+ if (options.horizontalBars) {
3070
+ projected = {
3071
+ x: chartRect.x1 + valueAxis.projectValue(safeHasProperty(value, "x") ? value.x : 0, valueIndex, normalizedData.series[seriesIndex]),
3072
+ y: chartRect.y1 - labelAxis.projectValue(safeHasProperty(value, "y") ? value.y : 0, labelAxisValueIndex, normalizedData.series[seriesIndex])
3073
+ };
3074
+ } else {
3075
+ projected = {
3076
+ x: chartRect.x1 + labelAxis.projectValue(safeHasProperty(value, "x") ? value.x : 0, labelAxisValueIndex, normalizedData.series[seriesIndex]),
3077
+ y: chartRect.y1 - valueAxis.projectValue(safeHasProperty(value, "y") ? value.y : 0, valueIndex, normalizedData.series[seriesIndex])
3078
+ };
3079
+ }
3080
+ // If the label axis is a step based axis we will offset the bar into the middle of between two steps using
3081
+ // the periodHalfLength value. Also we do arrange the different series so that they align up to each other using
3082
+ // the seriesBarDistance. If we don't have a step axis, the bar positions can be chosen freely so we should not
3083
+ // add any automated positioning.
3084
+ if (labelAxis instanceof StepAxis) {
3085
+ // Offset to center bar between grid lines, but only if the step axis is not stretched
3086
+ if (!labelAxis.stretch) {
3087
+ projected[labelAxis.units.pos] += periodHalfLength * (options.horizontalBars ? -1 : 1);
3088
+ }
3089
+ // Using bi-polar offset for multiple series if no stacked bars or series distribution is used
3090
+ projected[labelAxis.units.pos] += options.stackBars || options.distributeSeries ? 0 : biPol * options.seriesBarDistance * (options.horizontalBars ? -1 : 1);
3091
+ }
3092
+ // Enter value in stacked bar values used to remember previous screen value for stacking up bars
3093
+ const previousStack = stackedBarValues[valueIndex] || zeroPoint;
3094
+ stackedBarValues[valueIndex] = previousStack - (zeroPoint - projected[labelAxis.counterUnits.pos]);
3095
+ // Skip if value is undefined
3096
+ if (value === undefined) {
3097
+ return;
3098
+ }
3099
+ const positions = {
3100
+ ["".concat(labelAxis.units.pos, "1")]: projected[labelAxis.units.pos],
3101
+ ["".concat(labelAxis.units.pos, "2")]: projected[labelAxis.units.pos]
3102
+ };
3103
+ if (options.stackBars && (options.stackMode === "accumulate" || !options.stackMode)) {
3104
+ // Stack mode: accumulate (default)
3105
+ // If bars are stacked we use the stackedBarValues reference and otherwise base all bars off the zero line
3106
+ // We want backwards compatibility, so the expected fallback without the 'stackMode' option
3107
+ // to be the original behaviour (accumulate)
3108
+ positions["".concat(labelAxis.counterUnits.pos, "1")] = previousStack;
3109
+ positions["".concat(labelAxis.counterUnits.pos, "2")] = stackedBarValues[valueIndex];
3110
+ } else {
3111
+ // Draw from the zero line normally
3112
+ // This is also the same code for Stack mode: overlap
3113
+ positions["".concat(labelAxis.counterUnits.pos, "1")] = zeroPoint;
3114
+ positions["".concat(labelAxis.counterUnits.pos, "2")] = projected[labelAxis.counterUnits.pos];
3115
+ }
3116
+ // Limit x and y so that they are within the chart rect
3117
+ positions.x1 = Math.min(Math.max(positions.x1, chartRect.x1), chartRect.x2);
3118
+ positions.x2 = Math.min(Math.max(positions.x2, chartRect.x1), chartRect.x2);
3119
+ positions.y1 = Math.min(Math.max(positions.y1, chartRect.y2), chartRect.y1);
3120
+ positions.y2 = Math.min(Math.max(positions.y2, chartRect.y2), chartRect.y1);
3121
+ const metaData = getMetaData(series, valueIndex);
3122
+ // Create bar element
3123
+ const bar = seriesElement.elem("line", positions, options.classNames.bar).attr({
3124
+ "ct:value": [
3125
+ safeHasProperty(value, "x") && value.x,
3126
+ safeHasProperty(value, "y") && value.y
3127
+ ].filter(isNumeric).join(","),
3128
+ "ct:meta": serialize(metaData)
3129
+ });
3130
+ this.eventEmitter.emit("draw", {
3131
+ type: "bar",
3132
+ value,
3133
+ index: valueIndex,
3134
+ meta: metaData,
3135
+ series,
3136
+ seriesIndex,
3137
+ axisX,
3138
+ axisY,
3139
+ chartRect,
3140
+ group: seriesElement,
3141
+ element: bar,
3142
+ ...positions
3143
+ });
3144
+ });
3145
+ });
3146
+ this.eventEmitter.emit("created", {
3147
+ chartRect,
3148
+ axisX,
3149
+ axisY,
3150
+ svg,
3151
+ options
3152
+ });
3153
+ }
3154
+ /**
3155
+ * This method creates a new bar chart and returns API object that you can use for later changes.
3156
+ * @param query A selector query string or directly a DOM element
3157
+ * @param data The data object that needs to consist of a labels and a series array
3158
+ * @param options The options object with options that override the default options. Check the examples for a detailed list.
3159
+ * @param responsiveOptions Specify an array of responsive option arrays which are a media query and options object pair => [[mediaQueryString, optionsObject],[more...]]
3160
+ * @return An object which exposes the API for the created chart
3161
+ *
3162
+ * @example
3163
+ * // Create a simple bar chart
3164
+ * const data = {
3165
+ * labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
3166
+ * series: [
3167
+ * [5, 2, 4, 2, 0]
3168
+ * ]
3169
+ * };
3170
+ *
3171
+ * // In the global name space Chartist we call the Bar function to initialize a bar chart. As a first parameter we pass in a selector where we would like to get our chart created and as a second parameter we pass our data object.
3172
+ * new BarChart('.ct-chart', data);
3173
+ *
3174
+ * @example
3175
+ * // This example creates a bipolar grouped bar chart where the boundaries are limitted to -10 and 10
3176
+ * new BarChart('.ct-chart', {
3177
+ * labels: [1, 2, 3, 4, 5, 6, 7],
3178
+ * series: [
3179
+ * [1, 3, 2, -5, -3, 1, -6],
3180
+ * [-5, -2, -4, -1, 2, -3, 1]
3181
+ * ]
3182
+ * }, {
3183
+ * seriesBarDistance: 12,
3184
+ * low: -10,
3185
+ * high: 10
3186
+ * });
3187
+ *
3188
+ */ constructor(query, data, options, responsiveOptions){
3189
+ super(query, data, defaultOptions$1, extend({}, defaultOptions$1, options), responsiveOptions);
3190
+ this.data = data;
3191
+ }
3192
+ }
3193
+
3194
+ /**
3195
+ * Default options in line charts. Expand the code view to see a detailed list of options with comments.
3196
+ */ const defaultOptions = {
3197
+ // Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
3198
+ width: undefined,
3199
+ // Specify a fixed height for the chart as a string (i.e. '100px' or '50%')
3200
+ height: undefined,
3201
+ // Padding of the chart drawing area to the container element and labels as a number or padding object {top: 5, right: 5, bottom: 5, left: 5}
3202
+ chartPadding: 5,
3203
+ // Override the class names that are used to generate the SVG structure of the chart
3204
+ classNames: {
3205
+ chartPie: "ct-chart-pie",
3206
+ chartDonut: "ct-chart-donut",
3207
+ series: "ct-series",
3208
+ slicePie: "ct-slice-pie",
3209
+ sliceDonut: "ct-slice-donut",
3210
+ label: "ct-label"
3211
+ },
3212
+ // The start angle of the pie chart in degrees where 0 points north. A higher value offsets the start angle clockwise.
3213
+ startAngle: 0,
3214
+ // An optional total you can specify. By specifying a total value, the sum of the values in the series must be this total in order to draw a full pie. You can use this parameter to draw only parts of a pie or gauge charts.
3215
+ total: undefined,
3216
+ // If specified the donut CSS classes will be used and strokes will be drawn instead of pie slices.
3217
+ donut: false,
3218
+ // Specify the donut stroke width, currently done in javascript for convenience. May move to CSS styles in the future.
3219
+ // This option can be set as number or string to specify a relative width (i.e. 100 or '30%').
3220
+ donutWidth: 60,
3221
+ // If a label should be shown or not
3222
+ showLabel: true,
3223
+ // Label position offset from the standard position which is half distance of the radius. This value can be either positive or negative. Positive values will position the label away from the center.
3224
+ labelOffset: 0,
3225
+ // This option can be set to 'inside', 'outside' or 'center'. Positioned with 'inside' the labels will be placed on half the distance of the radius to the border of the Pie by respecting the 'labelOffset'. The 'outside' option will place the labels at the border of the pie and 'center' will place the labels in the absolute center point of the chart. The 'center' option only makes sense in conjunction with the 'labelOffset' option.
3226
+ labelPosition: "inside",
3227
+ // An interpolation function for the label value
3228
+ labelInterpolationFnc: noop,
3229
+ // Label direction can be 'neutral', 'explode' or 'implode'. The labels anchor will be positioned based on those settings as well as the fact if the labels are on the right or left side of the center of the chart. Usually explode is useful when labels are positioned far away from the center.
3230
+ labelDirection: "neutral",
3231
+ // If true the whole data is reversed including labels, the series order as well as the whole series data arrays.
3232
+ reverseData: false,
3233
+ // If true empty values will be ignored to avoid drawing unnecessary slices and labels
3234
+ ignoreEmptyValues: false
3235
+ };
3236
+ /**
3237
+ * Determines SVG anchor position based on direction and center parameter
3238
+ */ function determineAnchorPosition(center, label, direction) {
3239
+ const toTheRight = label.x > center.x;
3240
+ if (toTheRight && direction === "explode" || !toTheRight && direction === "implode") {
3241
+ return "start";
3242
+ } else if (toTheRight && direction === "implode" || !toTheRight && direction === "explode") {
3243
+ return "end";
3244
+ } else {
3245
+ return "middle";
3246
+ }
3247
+ }
3248
+ class PieChart extends BaseChart {
3249
+ /**
3250
+ * Creates the pie chart
3251
+ *
3252
+ * @param options
3253
+ */ createChart(options) {
3254
+ const { data } = this;
3255
+ const normalizedData = normalizeData(data);
3256
+ const seriesGroups = [];
3257
+ let labelsGroup;
3258
+ let labelRadius;
3259
+ let startAngle = options.startAngle;
3260
+ // Create SVG.js draw
3261
+ const svg = createSvg(this.container, options.width, options.height, options.donut ? options.classNames.chartDonut : options.classNames.chartPie);
3262
+ this.svg = svg;
3263
+ // Calculate charting rect
3264
+ const chartRect = createChartRect(svg, options);
3265
+ // Get biggest circle radius possible within chartRect
3266
+ let radius = Math.min(chartRect.width() / 2, chartRect.height() / 2);
3267
+ // Calculate total of all series to get reference value or use total reference from optional options
3268
+ const totalDataSum = options.total || normalizedData.series.reduce(sum, 0);
3269
+ const donutWidth = quantity(options.donutWidth);
3270
+ if (donutWidth.unit === "%") {
3271
+ donutWidth.value *= radius / 100;
3272
+ }
3273
+ // If this is a donut chart we need to adjust our radius to enable strokes to be drawn inside
3274
+ // Unfortunately this is not possible with the current SVG Spec
3275
+ // See this proposal for more details: http://lists.w3.org/Archives/Public/www-svg/2003Oct/0000.html
3276
+ radius -= options.donut ? donutWidth.value / 2 : 0;
3277
+ // If labelPosition is set to `outside` or a donut chart is drawn then the label position is at the radius,
3278
+ // if regular pie chart it's half of the radius
3279
+ if (options.labelPosition === "outside" || options.donut) {
3280
+ labelRadius = radius;
3281
+ } else if (options.labelPosition === "center") {
3282
+ // If labelPosition is center we start with 0 and will later wait for the labelOffset
3283
+ labelRadius = 0;
3284
+ } else {
3285
+ // Default option is 'inside' where we use half the radius so the label will be placed in the center of the pie
3286
+ // slice
3287
+ labelRadius = radius / 2;
3288
+ }
3289
+ // Add the offset to the labelRadius where a negative offset means closed to the center of the chart
3290
+ if (options.labelOffset) {
3291
+ labelRadius += options.labelOffset;
3292
+ }
3293
+ // Calculate end angle based on total sum and current data value and offset with padding
3294
+ const center = {
3295
+ x: chartRect.x1 + chartRect.width() / 2,
3296
+ y: chartRect.y2 + chartRect.height() / 2
3297
+ };
3298
+ // Check if there is only one non-zero value in the series array.
3299
+ const hasSingleValInSeries = data.series.filter((val)=>safeHasProperty(val, "value") ? val.value !== 0 : val !== 0
3300
+ ).length === 1;
3301
+ // Creating the series groups
3302
+ data.series.forEach((_, index)=>seriesGroups[index] = svg.elem("g")
3303
+ );
3304
+ // if we need to show labels we create the label group now
3305
+ if (options.showLabel) {
3306
+ labelsGroup = svg.elem("g");
3307
+ }
3308
+ // Draw the series
3309
+ // initialize series groups
3310
+ data.series.forEach((series, index)=>{
3311
+ var ref, ref1;
3312
+ // If current value is zero and we are ignoring empty values then skip to next value
3313
+ if (normalizedData.series[index] === 0 && options.ignoreEmptyValues) {
3314
+ return;
3315
+ }
3316
+ const seriesName = safeHasProperty(series, "name") && series.name;
3317
+ const seriesClassName = safeHasProperty(series, "className") && series.className;
3318
+ const seriesMeta = safeHasProperty(series, "meta") ? series.meta : undefined;
3319
+ // If the series is an object and contains a name or meta data we add a custom attribute
3320
+ if (seriesName) {
3321
+ seriesGroups[index].attr({
3322
+ "ct:series-name": seriesName
3323
+ });
3324
+ }
3325
+ // Use series class from series data or if not set generate one
3326
+ seriesGroups[index].addClass([
3327
+ (ref = options.classNames) === null || ref === void 0 ? void 0 : ref.series,
3328
+ seriesClassName || "".concat((ref1 = options.classNames) === null || ref1 === void 0 ? void 0 : ref1.series, "-").concat(alphaNumerate(index))
3329
+ ].join(" "));
3330
+ // If the whole dataset is 0 endAngle should be zero. Can't divide by 0.
3331
+ let endAngle = totalDataSum > 0 ? startAngle + normalizedData.series[index] / totalDataSum * 360 : 0;
3332
+ // Use slight offset so there are no transparent hairline issues
3333
+ const overlappigStartAngle = Math.max(0, startAngle - (index === 0 || hasSingleValInSeries ? 0 : 0.2));
3334
+ // If we need to draw the arc for all 360 degrees we need to add a hack where we close the circle
3335
+ // with Z and use 359.99 degrees
3336
+ if (endAngle - overlappigStartAngle >= 359.99) {
3337
+ endAngle = overlappigStartAngle + 359.99;
3338
+ }
3339
+ const start = polarToCartesian(center.x, center.y, radius, overlappigStartAngle);
3340
+ const end = polarToCartesian(center.x, center.y, radius, endAngle);
3341
+ // Create a new path element for the pie chart. If this isn't a donut chart we should close the path for a correct stroke
3342
+ const path = new SvgPath(!options.donut).move(end.x, end.y).arc(radius, radius, 0, Number(endAngle - startAngle > 180), 0, start.x, start.y);
3343
+ // If regular pie chart (no donut) we add a line to the center of the circle for completing the pie
3344
+ if (!options.donut) {
3345
+ path.line(center.x, center.y);
3346
+ }
3347
+ // Create the SVG path
3348
+ // If this is a donut chart we add the donut class, otherwise just a regular slice
3349
+ const pathElement = seriesGroups[index].elem("path", {
3350
+ d: path.stringify()
3351
+ }, options.donut ? options.classNames.sliceDonut : options.classNames.slicePie);
3352
+ // Adding the pie series value to the path
3353
+ pathElement.attr({
3354
+ "ct:value": normalizedData.series[index],
3355
+ "ct:meta": serialize(seriesMeta)
3356
+ });
3357
+ // If this is a donut, we add the stroke-width as style attribute
3358
+ if (options.donut) {
3359
+ pathElement.attr({
3360
+ style: "stroke-width: " + donutWidth.value + "px"
3361
+ });
3362
+ }
3363
+ // Fire off draw event
3364
+ this.eventEmitter.emit("draw", {
3365
+ type: "slice",
3366
+ value: normalizedData.series[index],
3367
+ totalDataSum: totalDataSum,
3368
+ index,
3369
+ meta: seriesMeta,
3370
+ series,
3371
+ group: seriesGroups[index],
3372
+ element: pathElement,
3373
+ path: path.clone(),
3374
+ center,
3375
+ radius,
3376
+ startAngle,
3377
+ endAngle,
3378
+ chartRect
3379
+ });
3380
+ // If we need to show labels we need to add the label for this slice now
3381
+ if (options.showLabel) {
3382
+ let labelPosition;
3383
+ if (data.series.length === 1) {
3384
+ // If we have only 1 series, we can position the label in the center of the pie
3385
+ labelPosition = {
3386
+ x: center.x,
3387
+ y: center.y
3388
+ };
3389
+ } else {
3390
+ // Position at the labelRadius distance from center and between start and end angle
3391
+ labelPosition = polarToCartesian(center.x, center.y, labelRadius, startAngle + (endAngle - startAngle) / 2);
3392
+ }
3393
+ let rawValue;
3394
+ if (normalizedData.labels && !isFalseyButZero(normalizedData.labels[index])) {
3395
+ rawValue = normalizedData.labels[index];
3396
+ } else {
3397
+ rawValue = normalizedData.series[index];
3398
+ }
3399
+ const interpolatedValue = options.labelInterpolationFnc(rawValue, index);
3400
+ if (interpolatedValue || interpolatedValue === 0) {
3401
+ const labelElement = labelsGroup.elem("text", {
3402
+ dx: labelPosition.x,
3403
+ dy: labelPosition.y,
3404
+ "text-anchor": determineAnchorPosition(center, labelPosition, options.labelDirection)
3405
+ }, options.classNames.label).text(String(interpolatedValue));
3406
+ // Fire off draw event
3407
+ this.eventEmitter.emit("draw", {
3408
+ type: "label",
3409
+ index,
3410
+ group: labelsGroup,
3411
+ element: labelElement,
3412
+ text: "" + interpolatedValue,
3413
+ chartRect,
3414
+ series,
3415
+ meta: seriesMeta,
3416
+ ...labelPosition
3417
+ });
3418
+ }
3419
+ }
3420
+ // Set next startAngle to current endAngle.
3421
+ // (except for last slice)
3422
+ startAngle = endAngle;
3423
+ });
3424
+ this.eventEmitter.emit("created", {
3425
+ chartRect,
3426
+ svg: svg,
3427
+ options
3428
+ });
3429
+ }
3430
+ /**
3431
+ * This method creates a new pie chart and returns an object that can be used to redraw the chart.
3432
+ * @param query A selector query string or directly a DOM element
3433
+ * @param data The data object in the pie chart needs to have a series property with a one dimensional data array. The values will be normalized against each other and don't necessarily need to be in percentage. The series property can also be an array of value objects that contain a value property and a className property to override the CSS class name for the series group.
3434
+ * @param options The options object with options that override the default options. Check the examples for a detailed list.
3435
+ * @param responsiveOptions Specify an array of responsive option arrays which are a media query and options object pair => [[mediaQueryString, optionsObject],[more...]]
3436
+ *
3437
+ * @example
3438
+ * // Simple pie chart example with four series
3439
+ * new PieChart('.ct-chart', {
3440
+ * series: [10, 2, 4, 3]
3441
+ * });
3442
+ *
3443
+ * @example
3444
+ * // Drawing a donut chart
3445
+ * new PieChart('.ct-chart', {
3446
+ * series: [10, 2, 4, 3]
3447
+ * }, {
3448
+ * donut: true
3449
+ * });
3450
+ *
3451
+ * @example
3452
+ * // Using donut, startAngle and total to draw a gauge chart
3453
+ * new PieChart('.ct-chart', {
3454
+ * series: [20, 10, 30, 40]
3455
+ * }, {
3456
+ * donut: true,
3457
+ * donutWidth: 20,
3458
+ * startAngle: 270,
3459
+ * total: 200
3460
+ * });
3461
+ *
3462
+ * @example
3463
+ * // Drawing a pie chart with padding and labels that are outside the pie
3464
+ * new PieChart('.ct-chart', {
3465
+ * series: [20, 10, 30, 40]
3466
+ * }, {
3467
+ * chartPadding: 30,
3468
+ * labelOffset: 50,
3469
+ * labelDirection: 'explode'
3470
+ * });
3471
+ *
3472
+ * @example
3473
+ * // Overriding the class names for individual series as well as a name and meta data.
3474
+ * // The name will be written as ct:series-name attribute and the meta data will be serialized and written
3475
+ * // to a ct:meta attribute.
3476
+ * new PieChart('.ct-chart', {
3477
+ * series: [{
3478
+ * value: 20,
3479
+ * name: 'Series 1',
3480
+ * className: 'my-custom-class-one',
3481
+ * meta: 'Meta One'
3482
+ * }, {
3483
+ * value: 10,
3484
+ * name: 'Series 2',
3485
+ * className: 'my-custom-class-two',
3486
+ * meta: 'Meta Two'
3487
+ * }, {
3488
+ * value: 70,
3489
+ * name: 'Series 3',
3490
+ * className: 'my-custom-class-three',
3491
+ * meta: 'Meta Three'
3492
+ * }]
3493
+ * });
3494
+ */ constructor(query, data, options, responsiveOptions){
3495
+ super(query, data, defaultOptions, extend({}, defaultOptions, options), responsiveOptions);
3496
+ this.data = data;
3497
+ }
3498
+ }
3499
+
3500
+ exports.AutoScaleAxis = AutoScaleAxis;
3501
+ exports.Axis = Axis;
3502
+ exports.BarChart = BarChart;
3503
+ exports.BaseChart = BaseChart;
3504
+ exports.EPSILON = EPSILON;
3505
+ exports.EventEmitter = EventEmitter;
3506
+ exports.FixedScaleAxis = FixedScaleAxis;
3507
+ exports.Interpolation = index;
3508
+ exports.LineChart = LineChart;
3509
+ exports.PieChart = PieChart;
3510
+ exports.StepAxis = StepAxis;
3511
+ exports.Svg = Svg;
3512
+ exports.SvgList = SvgList;
3513
+ exports.SvgPath = SvgPath;
3514
+ exports.alphaNumerate = alphaNumerate;
3515
+ exports.axisUnits = axisUnits;
3516
+ exports.createChartRect = createChartRect;
3517
+ exports.createGrid = createGrid;
3518
+ exports.createGridBackground = createGridBackground;
3519
+ exports.createLabel = createLabel;
3520
+ exports.createSvg = createSvg;
3521
+ exports.deserialize = deserialize;
3522
+ exports.determineAnchorPosition = determineAnchorPosition;
3523
+ exports.easings = easings;
3524
+ exports.ensureUnit = ensureUnit;
3525
+ exports.escapingMap = escapingMap;
3526
+ exports.extend = extend;
3527
+ exports.getBounds = getBounds;
3528
+ exports.getHighLow = getHighLow;
3529
+ exports.getMetaData = getMetaData;
3530
+ exports.getMultiValue = getMultiValue;
3531
+ exports.getNumberOrUndefined = getNumberOrUndefined;
3532
+ exports.getSeriesOption = getSeriesOption;
3533
+ exports.isArrayOfArrays = isArrayOfArrays;
3534
+ exports.isArrayOfSeries = isArrayOfSeries;
3535
+ exports.isDataHoleValue = isDataHoleValue;
3536
+ exports.isFalseyButZero = isFalseyButZero;
3537
+ exports.isMultiValue = isMultiValue;
3538
+ exports.isNumeric = isNumeric;
3539
+ exports.namespaces = namespaces;
3540
+ exports.noop = noop;
3541
+ exports.normalizeData = normalizeData;
3542
+ exports.normalizePadding = normalizePadding;
3543
+ exports.optionsProvider = optionsProvider;
3544
+ exports.orderOfMagnitude = orderOfMagnitude;
3545
+ exports.polarToCartesian = polarToCartesian;
3546
+ exports.precision = precision;
3547
+ exports.projectLength = projectLength;
3548
+ exports.quantity = quantity;
3549
+ exports.rho = rho;
3550
+ exports.roundWithPrecision = roundWithPrecision;
3551
+ exports.safeHasProperty = safeHasProperty;
3552
+ exports.serialMap = serialMap;
3553
+ exports.serialize = serialize;
3554
+ exports.splitIntoSegments = splitIntoSegments;
3555
+ exports.sum = sum;
3556
+ exports.times = times;
3557
+ //# sourceMappingURL=index.cjs.map