chartist 1.2.0 → 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.
package/dist/index.js CHANGED
@@ -243,12 +243,13 @@ function extend() {
243
243
  * @return The same value that was provided to the n parameter
244
244
  */ const noop = (n)=>n
245
245
  ;
246
- /**
247
- * Functional style helper to produce array with given length initialized with undefined values
248
- */ const times = (length)=>Array.from({
246
+ function times(length, filler) {
247
+ return Array.from({
249
248
  length
250
- })
251
- ;
249
+ }, filler ? (_, i)=>filler(i)
250
+ : ()=>void 0
251
+ );
252
+ }
252
253
  /**
253
254
  * Sum helper to be used in reduce functions
254
255
  */ const sum = (previous, current)=>previous + (current ? current : 0)
@@ -267,7 +268,7 @@ function extend() {
267
268
  * // 2. call arguments: (2, undefined, undefined)
268
269
  * ```
269
270
  */ const serialMap = (array, callback)=>times(Math.max(...array.map((element)=>element.length
270
- ))).map((_inner, index)=>callback(...array.map((element)=>element[index]
271
+ )), (index)=>callback(...array.map((element)=>element[index]
271
272
  ))
272
273
  )
273
274
  ;
@@ -294,6 +295,14 @@ function getNumberOrUndefined(value) {
294
295
  }
295
296
  return data.every(Array.isArray);
296
297
  }
298
+ /**
299
+ * Loop over array.
300
+ */ function each(list, callback) {
301
+ let reverse = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
302
+ let index = 0;
303
+ list[reverse ? "reduceRight" : "reduce"]((_, item, itemIndex)=>callback(item, index++, itemIndex)
304
+ , void 0);
305
+ }
297
306
 
298
307
  /**
299
308
  * Get meta data of a specific value in a series.
@@ -398,22 +407,25 @@ function normalizeData(data) {
398
407
  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;
399
408
  let labelCount;
400
409
  const normalized = {
401
- labels: [],
410
+ labels: (data.labels || []).slice(),
402
411
  series: normalizeSeries(data.series, multi, distributed)
403
412
  };
413
+ const inputLabelCount = normalized.labels.length;
404
414
  // If all elements of the normalized data array are arrays we're dealing with
405
415
  // multi series data and we need to find the largest series if they are un-even
406
416
  if (isArrayOfArrays(normalized.series)) {
407
417
  // Getting the series with the the most elements
408
- labelCount = Math.max(...normalized.series.map((series)=>series.length
418
+ labelCount = Math.max(inputLabelCount, ...normalized.series.map((series)=>series.length
409
419
  ));
420
+ normalized.series.forEach((series)=>{
421
+ series.push(...times(Math.max(0, labelCount - series.length)));
422
+ });
410
423
  } else {
411
424
  // We're dealing with Pie data so we just take the normalized array length
412
425
  labelCount = normalized.series.length;
413
426
  }
414
- normalized.labels = (data.labels || []).slice();
415
427
  // Padding the labels to labelCount with empty strings
416
- normalized.labels.push(...times(Math.max(0, labelCount - normalized.labels.length)).map(()=>""
428
+ normalized.labels.push(...times(Math.max(0, labelCount - inputLabelCount), ()=>""
417
429
  ));
418
430
  if (reverse) {
419
431
  reverseData(normalized);
@@ -2387,7 +2399,7 @@ class FixedScaleAxis extends Axis {
2387
2399
  constructor(axisUnit, data, chartRect, options){
2388
2400
  const highLow = options.highLow || getHighLow(data, options, axisUnit.pos);
2389
2401
  const divisor = options.divisor || 1;
2390
- const ticks = (options.ticks || times(divisor).map((_value, index)=>highLow.low + (highLow.high - highLow.low) / divisor * index
2402
+ const ticks = (options.ticks || times(divisor, (index)=>highLow.low + (highLow.high - highLow.low) / divisor * index
2391
2403
  )).sort((a, b)=>Number(a) - Number(b)
2392
2404
  );
2393
2405
  const range = {
@@ -2561,7 +2573,7 @@ class LineChart extends BaseChart {
2561
2573
  createGridBackground(gridGroup, chartRect, options.classNames.gridBackground, this.eventEmitter);
2562
2574
  }
2563
2575
  // Draw the series
2564
- data.series.forEach((series, seriesIndex)=>{
2576
+ each(data.series, (series, seriesIndex)=>{
2565
2577
  const seriesElement = seriesGroup.elem("g");
2566
2578
  const seriesName = safeHasProperty(series, "name") && series.name;
2567
2579
  const seriesClassName = safeHasProperty(series, "className") && series.className;
@@ -2721,7 +2733,7 @@ class LineChart extends BaseChart {
2721
2733
  });
2722
2734
  });
2723
2735
  }
2724
- });
2736
+ }, options.reverseData);
2725
2737
  this.eventEmitter.emit("created", {
2726
2738
  chartRect,
2727
2739
  axisX,
@@ -3021,7 +3033,7 @@ class BarChart extends BaseChart {
3021
3033
  createGridBackground(gridGroup, chartRect, options.classNames.gridBackground, this.eventEmitter);
3022
3034
  }
3023
3035
  // Draw the series
3024
- data.series.forEach((series, seriesIndex)=>{
3036
+ each(data.series, (series, seriesIndex)=>{
3025
3037
  // Calculating bi-polar value of index for seriesOffset. For i = 0..4 biPol will be -1.5, -0.5, 0.5, 1.5 etc.
3026
3038
  const biPol = seriesIndex - (data.series.length - 1) / 2;
3027
3039
  // Half of the period width between vertical grid lines used to position bars
@@ -3153,7 +3165,7 @@ class BarChart extends BaseChart {
3153
3165
  ...positions
3154
3166
  });
3155
3167
  });
3156
- });
3168
+ }, options.reverseData);
3157
3169
  this.eventEmitter.emit("created", {
3158
3170
  chartRect,
3159
3171
  axisX,
@@ -3242,8 +3254,6 @@ class BarChart extends BaseChart {
3242
3254
  labelInterpolationFnc: noop,
3243
3255
  // 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.
3244
3256
  labelDirection: "neutral",
3245
- // If true the whole data is reversed including labels, the series order as well as the whole series data arrays.
3246
- reverseData: false,
3247
3257
  // If true empty values will be ignored to avoid drawing unnecessary slices and labels
3248
3258
  ignoreEmptyValues: false
3249
3259
  };
@@ -3521,5 +3531,5 @@ class PieChart extends BaseChart {
3521
3531
  }
3522
3532
  }
3523
3533
 
3524
- export { AutoScaleAxis, Axis, BarChart, BaseChart, EPSILON, EventEmitter, FixedScaleAxis, index as Interpolation, LineChart, PieChart, StepAxis, Svg, SvgList, SvgPath, alphaNumerate, axisUnits, createChartRect, createGrid, createGridBackground, createLabel, createSvg, deserialize, determineAnchorPosition, easings, ensureUnit, escapingMap, extend, getBounds, getHighLow, getMetaData, getMultiValue, getNumberOrUndefined, getSeriesOption, isArrayOfArrays, isArrayOfSeries, isDataHoleValue, isFalseyButZero, isMultiValue, isNumeric, namespaces, noop, normalizeData, normalizePadding, optionsProvider, orderOfMagnitude, polarToCartesian, precision, projectLength, quantity, rho, roundWithPrecision, safeHasProperty, serialMap, serialize, splitIntoSegments, sum, times };
3534
+ export { AutoScaleAxis, Axis, BarChart, BaseChart, EPSILON, EventEmitter, FixedScaleAxis, index as Interpolation, LineChart, PieChart, StepAxis, Svg, SvgList, SvgPath, alphaNumerate, axisUnits, createChartRect, createGrid, createGridBackground, createLabel, createSvg, deserialize, determineAnchorPosition, each, easings, ensureUnit, escapingMap, extend, getBounds, getHighLow, getMetaData, getMultiValue, getNumberOrUndefined, getSeriesOption, isArrayOfArrays, isArrayOfSeries, isDataHoleValue, isFalseyButZero, isMultiValue, isNumeric, namespaces, noop, normalizeData, normalizePadding, optionsProvider, orderOfMagnitude, polarToCartesian, precision, projectLength, quantity, rho, roundWithPrecision, safeHasProperty, serialMap, serialize, splitIntoSegments, sum, times };
3525
3535
  //# sourceMappingURL=index.js.map