chartist 1.4.0 → 1.5.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.
package/dist/index.js CHANGED
@@ -1237,7 +1237,7 @@ function createAnimation(element, attribute, animationDefinition) {
1237
1237
  * @param className Specify a class to be added to the SVG element
1238
1238
  * @return The created/reinitialized SVG element
1239
1239
  */ function createSvg(container) {
1240
- 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;
1240
+ 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, viewBox = arguments.length > 4 ? arguments[4] : void 0;
1241
1241
  if (!container) {
1242
1242
  throw new Error("Container element is not found");
1243
1243
  }
@@ -1257,6 +1257,11 @@ function createAnimation(element, attribute, animationDefinition) {
1257
1257
  if (className) {
1258
1258
  svg1.addClass(className);
1259
1259
  }
1260
+ if (viewBox) {
1261
+ svg1.attr({
1262
+ viewBox: "0 0 ".concat(viewBox.width, " ").concat(viewBox.height)
1263
+ });
1264
+ }
1260
1265
  // Add the DOM node to our container
1261
1266
  container.appendChild(svg1.getNode());
1262
1267
  return svg1;
@@ -1290,15 +1295,15 @@ function createAnimation(element, attribute, animationDefinition) {
1290
1295
  * @param options The Object that contains all the optional values for the chart
1291
1296
  * @return The chart rectangles coordinates inside the svg element plus the rectangles measurements
1292
1297
  */ function createChartRect(svg, options) {
1293
- var ref, ref1, ref2, ref3;
1298
+ var ref, ref1, ref2, ref3, ref4, ref5;
1294
1299
  const hasAxis = Boolean(options.axisX || options.axisY);
1295
1300
  const yAxisOffset = ((ref = options.axisY) === null || ref === void 0 ? void 0 : ref.offset) || 0;
1296
1301
  const xAxisOffset = ((ref1 = options.axisX) === null || ref1 === void 0 ? void 0 : ref1.offset) || 0;
1297
1302
  const yAxisPosition = (ref2 = options.axisY) === null || ref2 === void 0 ? void 0 : ref2.position;
1298
1303
  const xAxisPosition = (ref3 = options.axisX) === null || ref3 === void 0 ? void 0 : ref3.position;
1299
1304
  // If width or height results in invalid value (including 0) we fallback to the unitless settings or even 0
1300
- let width = svg.width() || quantity(options.width).value || 0;
1301
- let height = svg.height() || quantity(options.height).value || 0;
1305
+ let width = ((ref4 = options.viewBox) === null || ref4 === void 0 ? void 0 : ref4.width) || svg.width() || quantity(options.width).value || 0;
1306
+ let height = ((ref5 = options.viewBox) === null || ref5 === void 0 ? void 0 : ref5.height) || svg.height() || quantity(options.height).value || 0;
1302
1307
  const normalizedPadding = normalizePadding(options.chartPadding);
1303
1308
  // If settings were to small to cope with offset (legacy) and padding, we'll adjust
1304
1309
  width = Math.max(width, yAxisOffset + normalizedPadding.left + normalizedPadding.right);
@@ -2545,7 +2550,7 @@ class LineChart extends BaseChart {
2545
2550
  const { data } = this;
2546
2551
  const normalizedData = normalizeData(data, options.reverseData, true);
2547
2552
  // Create new svg object
2548
- const svg = createSvg(this.container, options.width, options.height, options.classNames.chart);
2553
+ const svg = createSvg(this.container, options.width, options.height, options.classNames.chart, options.viewBox);
2549
2554
  this.svg = svg;
2550
2555
  // Create groups for labels, grid and series
2551
2556
  const gridGroup = svg.elem("g").addClass(options.classNames.gridGroup);
@@ -2958,7 +2963,7 @@ class BarChart extends BaseChart {
2958
2963
  const { data } = this;
2959
2964
  const normalizedData = normalizeData(data, options.reverseData, options.horizontalBars ? "x" : "y", true);
2960
2965
  // Create new svg element
2961
- const svg = createSvg(this.container, options.width, options.height, options.classNames.chart + (options.horizontalBars ? " " + options.classNames.horizontalBars : ""));
2966
+ const svg = createSvg(this.container, options.width, options.height, options.classNames.chart + (options.horizontalBars ? " " + options.classNames.horizontalBars : ""), options.viewBox);
2962
2967
  const highLow = options.stackBars && options.stackMode !== true && normalizedData.series.length ? getHighLow([
2963
2968
  getSerialSums(normalizedData.series)
2964
2969
  ], options, options.horizontalBars ? "x" : "y") : getHighLow(normalizedData.series, options, options.horizontalBars ? "x" : "y");
@@ -3316,7 +3321,7 @@ class PieChart extends BaseChart {
3316
3321
  let labelRadius;
3317
3322
  let startAngle = options.startAngle;
3318
3323
  // Create SVG.js draw
3319
- const svg = createSvg(this.container, options.width, options.height, options.donut ? options.classNames.chartDonut : options.classNames.chartPie);
3324
+ const svg = createSvg(this.container, options.width, options.height, options.donut ? options.classNames.chartDonut : options.classNames.chartPie, options.viewBox);
3320
3325
  this.svg = svg;
3321
3326
  // Calculate charting rect
3322
3327
  const chartRect = createChartRect(svg, options);