chartist 1.3.1 → 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/charts/BarChart/BarChart.d.ts.map +1 -1
- package/dist/charts/LineChart/LineChart.d.ts.map +1 -1
- package/dist/charts/PieChart/PieChart.d.ts +8 -0
- package/dist/charts/PieChart/PieChart.d.ts.map +1 -1
- package/dist/charts/PieChart/PieChart.types.d.ts +5 -1
- package/dist/charts/PieChart/PieChart.types.d.ts.map +1 -1
- package/dist/core/creation.d.ts +2 -2
- package/dist/core/creation.d.ts.map +1 -1
- package/dist/core/types.d.ts +8 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.cjs +37 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -8
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
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");
|
|
@@ -3273,7 +3278,9 @@ class BarChart extends BaseChart {
|
|
|
3273
3278
|
// 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.
|
|
3274
3279
|
labelDirection: "neutral",
|
|
3275
3280
|
// If true empty values will be ignored to avoid drawing unnecessary slices and labels
|
|
3276
|
-
ignoreEmptyValues: false
|
|
3281
|
+
ignoreEmptyValues: false,
|
|
3282
|
+
// If Nonzero check if a label has overlapping text then move it the number of pixels up and left (Should be half of label font size + 1 but you can tweak it as you prefer)
|
|
3283
|
+
preventOverlappingLabelOffset: 0
|
|
3277
3284
|
};
|
|
3278
3285
|
/**
|
|
3279
3286
|
* Determines SVG anchor position based on direction and center parameter
|
|
@@ -3289,6 +3296,19 @@ class BarChart extends BaseChart {
|
|
|
3289
3296
|
}
|
|
3290
3297
|
class PieChart extends BaseChart {
|
|
3291
3298
|
/**
|
|
3299
|
+
* Check if a label has overlapping text then move it the number of pixels up and left based on textSize.
|
|
3300
|
+
* @param labelPos - Label position that chartist will be checking does not overlap with the list of LabelPositions.
|
|
3301
|
+
* @param existingLabelPos - Label position that has already been placed that chartist will check against.
|
|
3302
|
+
* @param textOffset - this is configured with preventOverlappingLabelOffset option.
|
|
3303
|
+
* @param length - How many characters long the label is.
|
|
3304
|
+
*/ moveLabel(labelPos, existingLabelPos, textOffset, length) {
|
|
3305
|
+
if (labelPos.y > existingLabelPos.y - textOffset && labelPos.y < existingLabelPos.y + textOffset && labelPos.x > existingLabelPos.x - length * textOffset && labelPos.x < existingLabelPos.x + length * textOffset) {
|
|
3306
|
+
labelPos.y -= textOffset;
|
|
3307
|
+
labelPos.x -= textOffset;
|
|
3308
|
+
this.moveLabel(labelPos, existingLabelPos, textOffset, length);
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
/**
|
|
3292
3312
|
* Creates the pie chart
|
|
3293
3313
|
*
|
|
3294
3314
|
* @param options
|
|
@@ -3297,10 +3317,11 @@ class PieChart extends BaseChart {
|
|
|
3297
3317
|
const normalizedData = normalizeData(data);
|
|
3298
3318
|
const seriesGroups = [];
|
|
3299
3319
|
let labelsGroup;
|
|
3320
|
+
const labelPositions = [];
|
|
3300
3321
|
let labelRadius;
|
|
3301
3322
|
let startAngle = options.startAngle;
|
|
3302
3323
|
// Create SVG.js draw
|
|
3303
|
-
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);
|
|
3304
3325
|
this.svg = svg;
|
|
3305
3326
|
// Calculate charting rect
|
|
3306
3327
|
const chartRect = createChartRect(svg, options);
|
|
@@ -3440,6 +3461,14 @@ class PieChart extends BaseChart {
|
|
|
3440
3461
|
}
|
|
3441
3462
|
const interpolatedValue = options.labelInterpolationFnc(rawValue, index);
|
|
3442
3463
|
if (interpolatedValue || interpolatedValue === 0) {
|
|
3464
|
+
if (options.preventOverlappingLabelOffset) {
|
|
3465
|
+
const textOffset = options.preventOverlappingLabelOffset;
|
|
3466
|
+
const length = String(normalizedData.labels[index]).length;
|
|
3467
|
+
labelPositions.forEach((item)=>{
|
|
3468
|
+
this.moveLabel(labelPosition, item, textOffset, length);
|
|
3469
|
+
});
|
|
3470
|
+
labelPositions.push(labelPosition);
|
|
3471
|
+
}
|
|
3443
3472
|
const labelElement = labelsGroup.elem("text", {
|
|
3444
3473
|
dx: labelPosition.x,
|
|
3445
3474
|
dy: labelPosition.y,
|