chartist 1.1.3 → 1.2.1

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 (40) hide show
  1. package/README.md +1 -1
  2. package/dist/_settings.scss +89 -0
  3. package/dist/charts/BarChart/BarChart.d.ts +4 -1
  4. package/dist/charts/BarChart/BarChart.d.ts.map +1 -1
  5. package/dist/charts/BarChart/BarChart.types.d.ts +25 -0
  6. package/dist/charts/BarChart/BarChart.types.d.ts.map +1 -1
  7. package/dist/charts/LineChart/LineChart.d.ts +6 -1
  8. package/dist/charts/LineChart/LineChart.d.ts.map +1 -1
  9. package/dist/charts/LineChart/LineChart.types.d.ts +30 -0
  10. package/dist/charts/LineChart/LineChart.types.d.ts.map +1 -1
  11. package/dist/charts/PieChart/PieChart.d.ts +10 -0
  12. package/dist/charts/PieChart/PieChart.d.ts.map +1 -1
  13. package/dist/charts/PieChart/PieChart.types.d.ts +39 -1
  14. package/dist/charts/PieChart/PieChart.types.d.ts.map +1 -1
  15. package/dist/core/types.d.ts +61 -0
  16. package/dist/core/types.d.ts.map +1 -1
  17. package/dist/index.cjs +61 -22
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.css +1 -1
  20. package/dist/index.css.map +1 -1
  21. package/dist/index.js +61 -23
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.scss +204 -0
  24. package/dist/index.umd.js +1 -1
  25. package/dist/index.umd.js.map +1 -1
  26. package/dist/interpolation/cardinal.d.ts +2 -0
  27. package/dist/interpolation/cardinal.d.ts.map +1 -1
  28. package/dist/interpolation/monotoneCubic.d.ts +2 -0
  29. package/dist/interpolation/monotoneCubic.d.ts.map +1 -1
  30. package/dist/interpolation/none.d.ts +2 -0
  31. package/dist/interpolation/none.d.ts.map +1 -1
  32. package/dist/interpolation/simple.d.ts +2 -0
  33. package/dist/interpolation/simple.d.ts.map +1 -1
  34. package/dist/interpolation/step.d.ts +3 -1
  35. package/dist/interpolation/step.d.ts.map +1 -1
  36. package/dist/utils/functional.d.ts +3 -2
  37. package/dist/utils/functional.d.ts.map +1 -1
  38. package/dist/utils/utils.d.ts +4 -0
  39. package/dist/utils/utils.d.ts.map +1 -1
  40. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -247,12 +247,13 @@ function extend() {
247
247
  * @return The same value that was provided to the n parameter
248
248
  */ const noop = (n)=>n
249
249
  ;
250
- /**
251
- * Functional style helper to produce array with given length initialized with undefined values
252
- */ const times = (length)=>Array.from({
250
+ function times(length, filler) {
251
+ return Array.from({
253
252
  length
254
- })
255
- ;
253
+ }, filler ? (_, i)=>filler(i)
254
+ : ()=>void 0
255
+ );
256
+ }
256
257
  /**
257
258
  * Sum helper to be used in reduce functions
258
259
  */ const sum = (previous, current)=>previous + (current ? current : 0)
@@ -262,7 +263,7 @@ function extend() {
262
263
  *
263
264
  * For example:
264
265
  * @example
265
- * ```javascript
266
+ * ```ts
266
267
  * const data = [[1, 2], [3], []];
267
268
  * serialMap(data, cb);
268
269
  *
@@ -271,7 +272,7 @@ function extend() {
271
272
  * // 2. call arguments: (2, undefined, undefined)
272
273
  * ```
273
274
  */ const serialMap = (array, callback)=>times(Math.max(...array.map((element)=>element.length
274
- ))).map((_inner, index)=>callback(...array.map((element)=>element[index]
275
+ )), (index)=>callback(...array.map((element)=>element[index]
275
276
  ))
276
277
  )
277
278
  ;
@@ -298,6 +299,14 @@ function getNumberOrUndefined(value) {
298
299
  }
299
300
  return data.every(Array.isArray);
300
301
  }
302
+ /**
303
+ * Loop over array.
304
+ */ function each(list, callback) {
305
+ let reverse = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
306
+ let index = 0;
307
+ list[reverse ? "reduceRight" : "reduce"]((_, item, itemIndex)=>callback(item, index++, itemIndex)
308
+ , void 0);
309
+ }
301
310
 
302
311
  /**
303
312
  * Get meta data of a specific value in a series.
@@ -402,22 +411,25 @@ function normalizeData(data) {
402
411
  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
412
  let labelCount;
404
413
  const normalized = {
405
- labels: [],
414
+ labels: (data.labels || []).slice(),
406
415
  series: normalizeSeries(data.series, multi, distributed)
407
416
  };
417
+ const inputLabelCount = normalized.labels.length;
408
418
  // If all elements of the normalized data array are arrays we're dealing with
409
419
  // multi series data and we need to find the largest series if they are un-even
410
420
  if (isArrayOfArrays(normalized.series)) {
411
421
  // Getting the series with the the most elements
412
- labelCount = Math.max(...normalized.series.map((series)=>series.length
422
+ labelCount = Math.max(inputLabelCount, ...normalized.series.map((series)=>series.length
413
423
  ));
424
+ normalized.series.forEach((series)=>{
425
+ series.push(...times(Math.max(0, labelCount - series.length)));
426
+ });
414
427
  } else {
415
428
  // We're dealing with Pie data so we just take the normalized array length
416
429
  labelCount = normalized.series.length;
417
430
  }
418
- normalized.labels = (data.labels || []).slice();
419
431
  // Padding the labels to labelCount with empty strings
420
- normalized.labels.push(...times(Math.max(0, labelCount - normalized.labels.length)).map(()=>""
432
+ normalized.labels.push(...times(Math.max(0, labelCount - inputLabelCount), ()=>""
421
433
  ));
422
434
  if (reverse) {
423
435
  reverseData(normalized);
@@ -1612,7 +1624,7 @@ class SvgPath {
1612
1624
  * @return The current path object for easy call chaining.
1613
1625
  */ parse(path) {
1614
1626
  // 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)=>{
1627
+ 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
1628
  if (pathElement.match(/[A-Za-z]/)) {
1617
1629
  result.push([]);
1618
1630
  }
@@ -1744,6 +1756,7 @@ class SvgPath {
1744
1756
  * This interpolation function does not smooth the path and the result is only containing lines and no curves.
1745
1757
  *
1746
1758
  * @example
1759
+ * ```ts
1747
1760
  * const chart = new LineChart('.ct-chart', {
1748
1761
  * labels: [1, 2, 3, 4, 5],
1749
1762
  * series: [[1, 2, 8, 1, 7]]
@@ -1752,6 +1765,7 @@ class SvgPath {
1752
1765
  * fillHoles: false
1753
1766
  * })
1754
1767
  * });
1768
+ * ```
1755
1769
  */ function none(options) {
1756
1770
  const finalOptions = {
1757
1771
  fillHoles: false,
@@ -1787,6 +1801,7 @@ class SvgPath {
1787
1801
  * 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
1802
  *
1789
1803
  * @example
1804
+ * ```ts
1790
1805
  * const chart = new LineChart('.ct-chart', {
1791
1806
  * labels: [1, 2, 3, 4, 5],
1792
1807
  * series: [[1, 2, 8, 1, 7]]
@@ -1796,6 +1811,7 @@ class SvgPath {
1796
1811
  * fillHoles: false
1797
1812
  * })
1798
1813
  * });
1814
+ * ```
1799
1815
  *
1800
1816
  * @param options The options of the simple interpolation factory function.
1801
1817
  */ function simple(options) {
@@ -1839,7 +1855,8 @@ class SvgPath {
1839
1855
  * 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
1856
  *
1841
1857
  * @example
1842
- * var chart = new Chartist.Line('.ct-chart', {
1858
+ * ```ts
1859
+ * const chart = new Chartist.Line('.ct-chart', {
1843
1860
  * labels: [1, 2, 3, 4, 5],
1844
1861
  * series: [[1, 2, 8, 1, 7]]
1845
1862
  * }, {
@@ -1848,6 +1865,7 @@ class SvgPath {
1848
1865
  * fillHoles: false
1849
1866
  * })
1850
1867
  * });
1868
+ * ```
1851
1869
  */ function step(options) {
1852
1870
  const finalOptions = {
1853
1871
  postpone: true,
@@ -1898,6 +1916,7 @@ class SvgPath {
1898
1916
  * 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
1917
  *
1900
1918
  * @example
1919
+ * ```ts
1901
1920
  * const chart = new LineChart('.ct-chart', {
1902
1921
  * labels: [1, 2, 3, 4, 5],
1903
1922
  * series: [[1, 2, 8, 1, 7]]
@@ -1907,6 +1926,7 @@ class SvgPath {
1907
1926
  * fillHoles: false
1908
1927
  * })
1909
1928
  * });
1929
+ * ```
1910
1930
  *
1911
1931
  * @param options The options of the cardinal factory function.
1912
1932
  */ function cardinal(options) {
@@ -1990,6 +2010,7 @@ class SvgPath {
1990
2010
  * All smoothing functions within Chartist are factory functions that accept an options parameter.
1991
2011
  *
1992
2012
  * @example
2013
+ * ```ts
1993
2014
  * const chart = new LineChart('.ct-chart', {
1994
2015
  * labels: [1, 2, 3, 4, 5],
1995
2016
  * series: [[1, 2, 8, 1, 7]]
@@ -1998,6 +2019,7 @@ class SvgPath {
1998
2019
  * fillHoles: false
1999
2020
  * })
2000
2021
  * });
2022
+ * ```
2001
2023
  *
2002
2024
  * @param options The options of the monotoneCubic factory function.
2003
2025
  */ function monotoneCubic(options) {
@@ -2381,7 +2403,7 @@ class FixedScaleAxis extends Axis {
2381
2403
  constructor(axisUnit, data, chartRect, options){
2382
2404
  const highLow = options.highLow || getHighLow(data, options, axisUnit.pos);
2383
2405
  const divisor = options.divisor || 1;
2384
- const ticks = (options.ticks || times(divisor).map((_value, index)=>highLow.low + (highLow.high - highLow.low) / divisor * index
2406
+ const ticks = (options.ticks || times(divisor, (index)=>highLow.low + (highLow.high - highLow.low) / divisor * index
2385
2407
  )).sort((a, b)=>Number(a) - Number(b)
2386
2408
  );
2387
2409
  const range = {
@@ -2555,7 +2577,7 @@ class LineChart extends BaseChart {
2555
2577
  createGridBackground(gridGroup, chartRect, options.classNames.gridBackground, this.eventEmitter);
2556
2578
  }
2557
2579
  // Draw the series
2558
- data.series.forEach((series, seriesIndex)=>{
2580
+ each(data.series, (series, seriesIndex)=>{
2559
2581
  const seriesElement = seriesGroup.elem("g");
2560
2582
  const seriesName = safeHasProperty(series, "name") && series.name;
2561
2583
  const seriesClassName = safeHasProperty(series, "className") && series.className;
@@ -2715,7 +2737,7 @@ class LineChart extends BaseChart {
2715
2737
  });
2716
2738
  });
2717
2739
  }
2718
- });
2740
+ }, options.reverseData);
2719
2741
  this.eventEmitter.emit("created", {
2720
2742
  chartRect,
2721
2743
  axisX,
@@ -2733,6 +2755,7 @@ class LineChart extends BaseChart {
2733
2755
  * @return An object which exposes the API for the created chart
2734
2756
  *
2735
2757
  * @example
2758
+ * ```ts
2736
2759
  * // Create a simple line chart
2737
2760
  * const data = {
2738
2761
  * // A labels array that can contain any sort of values
@@ -2751,8 +2774,10 @@ class LineChart extends BaseChart {
2751
2774
  *
2752
2775
  * // 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
2776
  * new LineChart('.ct-chart', data, options);
2777
+ * ```
2754
2778
  *
2755
2779
  * @example
2780
+ * ```ts
2756
2781
  * // Use specific interpolation function with configuration from the Chartist.Interpolation module
2757
2782
  *
2758
2783
  * const chart = new LineChart('.ct-chart', {
@@ -2765,8 +2790,10 @@ class LineChart extends BaseChart {
2765
2790
  * tension: 0.2
2766
2791
  * })
2767
2792
  * });
2793
+ * ```
2768
2794
  *
2769
2795
  * @example
2796
+ * ```ts
2770
2797
  * // Create a line chart with responsive options
2771
2798
  *
2772
2799
  * const data = {
@@ -2801,7 +2828,7 @@ class LineChart extends BaseChart {
2801
2828
  * ];
2802
2829
  *
2803
2830
  * new LineChart('.ct-chart', data, null, responsiveOptions);
2804
- *
2831
+ * ```
2805
2832
  */ constructor(query, data, options, responsiveOptions){
2806
2833
  super(query, data, defaultOptions$2, extend({}, defaultOptions$2, options), responsiveOptions);
2807
2834
  this.data = data;
@@ -3010,7 +3037,7 @@ class BarChart extends BaseChart {
3010
3037
  createGridBackground(gridGroup, chartRect, options.classNames.gridBackground, this.eventEmitter);
3011
3038
  }
3012
3039
  // Draw the series
3013
- data.series.forEach((series, seriesIndex)=>{
3040
+ each(data.series, (series, seriesIndex)=>{
3014
3041
  // 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
3042
  const biPol = seriesIndex - (data.series.length - 1) / 2;
3016
3043
  // Half of the period width between vertical grid lines used to position bars
@@ -3142,7 +3169,7 @@ class BarChart extends BaseChart {
3142
3169
  ...positions
3143
3170
  });
3144
3171
  });
3145
- });
3172
+ }, options.reverseData);
3146
3173
  this.eventEmitter.emit("created", {
3147
3174
  chartRect,
3148
3175
  axisX,
@@ -3160,6 +3187,7 @@ class BarChart extends BaseChart {
3160
3187
  * @return An object which exposes the API for the created chart
3161
3188
  *
3162
3189
  * @example
3190
+ * ```ts
3163
3191
  * // Create a simple bar chart
3164
3192
  * const data = {
3165
3193
  * labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
@@ -3170,8 +3198,10 @@ class BarChart extends BaseChart {
3170
3198
  *
3171
3199
  * // 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
3200
  * new BarChart('.ct-chart', data);
3201
+ * ```
3173
3202
  *
3174
3203
  * @example
3204
+ * ```ts
3175
3205
  * // This example creates a bipolar grouped bar chart where the boundaries are limitted to -10 and 10
3176
3206
  * new BarChart('.ct-chart', {
3177
3207
  * labels: [1, 2, 3, 4, 5, 6, 7],
@@ -3184,7 +3214,7 @@ class BarChart extends BaseChart {
3184
3214
  * low: -10,
3185
3215
  * high: 10
3186
3216
  * });
3187
- *
3217
+ * ```
3188
3218
  */ constructor(query, data, options, responsiveOptions){
3189
3219
  super(query, data, defaultOptions$1, extend({}, defaultOptions$1, options), responsiveOptions);
3190
3220
  this.data = data;
@@ -3228,8 +3258,6 @@ class BarChart extends BaseChart {
3228
3258
  labelInterpolationFnc: noop,
3229
3259
  // 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
3260
  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
3261
  // If true empty values will be ignored to avoid drawing unnecessary slices and labels
3234
3262
  ignoreEmptyValues: false
3235
3263
  };
@@ -3435,20 +3463,25 @@ class PieChart extends BaseChart {
3435
3463
  * @param responsiveOptions Specify an array of responsive option arrays which are a media query and options object pair => [[mediaQueryString, optionsObject],[more...]]
3436
3464
  *
3437
3465
  * @example
3466
+ * ```ts
3438
3467
  * // Simple pie chart example with four series
3439
3468
  * new PieChart('.ct-chart', {
3440
3469
  * series: [10, 2, 4, 3]
3441
3470
  * });
3471
+ * ```
3442
3472
  *
3443
3473
  * @example
3474
+ * ```ts
3444
3475
  * // Drawing a donut chart
3445
3476
  * new PieChart('.ct-chart', {
3446
3477
  * series: [10, 2, 4, 3]
3447
3478
  * }, {
3448
3479
  * donut: true
3449
3480
  * });
3481
+ * ```
3450
3482
  *
3451
3483
  * @example
3484
+ * ```ts
3452
3485
  * // Using donut, startAngle and total to draw a gauge chart
3453
3486
  * new PieChart('.ct-chart', {
3454
3487
  * series: [20, 10, 30, 40]
@@ -3458,8 +3491,10 @@ class PieChart extends BaseChart {
3458
3491
  * startAngle: 270,
3459
3492
  * total: 200
3460
3493
  * });
3494
+ * ```
3461
3495
  *
3462
3496
  * @example
3497
+ * ```ts
3463
3498
  * // Drawing a pie chart with padding and labels that are outside the pie
3464
3499
  * new PieChart('.ct-chart', {
3465
3500
  * series: [20, 10, 30, 40]
@@ -3468,8 +3503,10 @@ class PieChart extends BaseChart {
3468
3503
  * labelOffset: 50,
3469
3504
  * labelDirection: 'explode'
3470
3505
  * });
3506
+ * ```
3471
3507
  *
3472
3508
  * @example
3509
+ * ```ts
3473
3510
  * // Overriding the class names for individual series as well as a name and meta data.
3474
3511
  * // The name will be written as ct:series-name attribute and the meta data will be serialized and written
3475
3512
  * // to a ct:meta attribute.
@@ -3491,6 +3528,7 @@ class PieChart extends BaseChart {
3491
3528
  * meta: 'Meta Three'
3492
3529
  * }]
3493
3530
  * });
3531
+ * ```
3494
3532
  */ constructor(query, data, options, responsiveOptions){
3495
3533
  super(query, data, defaultOptions, extend({}, defaultOptions, options), responsiveOptions);
3496
3534
  this.data = data;
@@ -3520,6 +3558,7 @@ exports.createLabel = createLabel;
3520
3558
  exports.createSvg = createSvg;
3521
3559
  exports.deserialize = deserialize;
3522
3560
  exports.determineAnchorPosition = determineAnchorPosition;
3561
+ exports.each = each;
3523
3562
  exports.easings = easings;
3524
3563
  exports.ensureUnit = ensureUnit;
3525
3564
  exports.escapingMap = escapingMap;