chartist 1.2.1 → 1.3.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/README.md +5 -111
- package/dist/_settings.scss +1 -1
- package/dist/charts/BarChart/BarChart.d.ts.map +1 -1
- package/dist/charts/BarChart/BarChart.types.d.ts +3 -2
- package/dist/charts/BarChart/BarChart.types.d.ts.map +1 -1
- package/dist/charts/BaseChart.d.ts.map +1 -1
- package/dist/core/creation.d.ts.map +1 -1
- package/dist/index.cjs +33 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -15
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/svg/Svg.d.ts +2 -2
- package/package.json +7 -5
package/dist/index.js
CHANGED
|
@@ -225,7 +225,11 @@ function extend() {
|
|
|
225
225
|
}
|
|
226
226
|
for(let i = 0; i < sources.length; i++){
|
|
227
227
|
const source = sources[i];
|
|
228
|
+
const targetProto = Object.getPrototypeOf(target);
|
|
228
229
|
for(const prop in source){
|
|
230
|
+
if (targetProto !== null && prop in targetProto) {
|
|
231
|
+
continue; // prevent prototype pollution
|
|
232
|
+
}
|
|
229
233
|
const sourceProp = source[prop];
|
|
230
234
|
if (typeof sourceProp === "object" && sourceProp !== null && !(sourceProp instanceof Array)) {
|
|
231
235
|
target[prop] = extend(target[prop], sourceProp);
|
|
@@ -1123,16 +1127,16 @@ function createAnimation(element, attribute, animationDefinition) {
|
|
|
1123
1127
|
return this;
|
|
1124
1128
|
}
|
|
1125
1129
|
/**
|
|
1126
|
-
* Get element height using `
|
|
1130
|
+
* Get element height using `clientHeight`
|
|
1127
1131
|
* @return The elements height in pixels
|
|
1128
1132
|
*/ height() {
|
|
1129
|
-
return this._node.
|
|
1133
|
+
return this._node.clientHeight;
|
|
1130
1134
|
}
|
|
1131
1135
|
/**
|
|
1132
|
-
* Get element width using `
|
|
1136
|
+
* Get element width using `clientWidth`
|
|
1133
1137
|
* @return The elements width in pixels
|
|
1134
1138
|
*/ width() {
|
|
1135
|
-
return this._node.
|
|
1139
|
+
return this._node.clientWidth;
|
|
1136
1140
|
}
|
|
1137
1141
|
/**
|
|
1138
1142
|
* 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.
|
|
@@ -1234,6 +1238,9 @@ function createAnimation(element, attribute, animationDefinition) {
|
|
|
1234
1238
|
* @return The created/reinitialized SVG element
|
|
1235
1239
|
*/ function createSvg(container) {
|
|
1236
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;
|
|
1241
|
+
if (!container) {
|
|
1242
|
+
throw new Error("Container element is not found");
|
|
1243
|
+
}
|
|
1237
1244
|
// Check if there is a previous SVG element in the container that contains the Chartist XML namespace and remove it
|
|
1238
1245
|
// Since the DOM API does not support namespaces we need to manually search the returned list http://www.w3.org/TR/selectors-api/
|
|
1239
1246
|
Array.from(container.querySelectorAll("svg")).filter((svg)=>svg.getAttributeNS(namespaces.xmlns, "ct")
|
|
@@ -1417,7 +1424,7 @@ function createAnimation(element, attribute, animationDefinition) {
|
|
|
1417
1424
|
responsiveOptions.forEach((responsiveOption)=>{
|
|
1418
1425
|
const mql = window.matchMedia(responsiveOption[0]);
|
|
1419
1426
|
if (mql.matches) {
|
|
1420
|
-
currentOptions = extend(currentOptions, responsiveOption[1]);
|
|
1427
|
+
currentOptions = extend({}, currentOptions, responsiveOption[1]);
|
|
1421
1428
|
}
|
|
1422
1429
|
});
|
|
1423
1430
|
}
|
|
@@ -2266,7 +2273,7 @@ class BaseChart {
|
|
|
2266
2273
|
, 0);
|
|
2267
2274
|
const container = typeof query === "string" ? document.querySelector(query) : query;
|
|
2268
2275
|
if (!container) {
|
|
2269
|
-
throw new Error("Target element is not found");
|
|
2276
|
+
throw new Error("Target element ".concat(typeof query === "string" ? '"'.concat(query, '"') : "", " is not found"));
|
|
2270
2277
|
}
|
|
2271
2278
|
this.container = container;
|
|
2272
2279
|
const prevInstance = instances.get(container);
|
|
@@ -2915,8 +2922,9 @@ function getSerialSums(series) {
|
|
|
2915
2922
|
seriesBarDistance: 15,
|
|
2916
2923
|
// If set to true this property will cause the series bars to be stacked. Check the `stackMode` option for further stacking options.
|
|
2917
2924
|
stackBars: false,
|
|
2918
|
-
// If set to
|
|
2925
|
+
// If set to true this property will force the stacked bars to draw from the zero line.
|
|
2919
2926
|
// 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.
|
|
2927
|
+
// If set to 'accumulate-relative' positive and negative values will be handled separately.
|
|
2920
2928
|
stackMode: "accumulate",
|
|
2921
2929
|
// 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.
|
|
2922
2930
|
horizontalBars: false,
|
|
@@ -3025,8 +3033,12 @@ class BarChart extends BaseChart {
|
|
|
3025
3033
|
}
|
|
3026
3034
|
// Projected 0 point
|
|
3027
3035
|
const zeroPoint = options.horizontalBars ? chartRect.x1 + valueAxis.projectValue(0) : chartRect.y1 - valueAxis.projectValue(0);
|
|
3036
|
+
const isAccumulateStackMode = options.stackMode === "accumulate";
|
|
3037
|
+
const isAccumulateRelativeStackMode = options.stackMode === "accumulate-relative";
|
|
3028
3038
|
// Used to track the screen coordinates of stacked bars
|
|
3029
|
-
const
|
|
3039
|
+
const posStackedBarValues = [];
|
|
3040
|
+
const negStackedBarValues = [];
|
|
3041
|
+
let stackedBarValues = posStackedBarValues;
|
|
3030
3042
|
labelAxis.createGridAndLabels(gridGroup, labelGroup, options, this.eventEmitter);
|
|
3031
3043
|
valueAxis.createGridAndLabels(gridGroup, labelGroup, options, this.eventEmitter);
|
|
3032
3044
|
if (options.showGridBackground) {
|
|
@@ -3073,6 +3085,8 @@ class BarChart extends BaseChart {
|
|
|
3073
3085
|
seriesClassName || "".concat(options.classNames.series, "-").concat(alphaNumerate(seriesIndex))
|
|
3074
3086
|
].join(" "));
|
|
3075
3087
|
normalizedData.series[seriesIndex].forEach((value, valueIndex)=>{
|
|
3088
|
+
const valueX = safeHasProperty(value, "x") && value.x;
|
|
3089
|
+
const valueY = safeHasProperty(value, "y") && value.y;
|
|
3076
3090
|
let labelAxisValueIndex;
|
|
3077
3091
|
// We need to set labelAxisValueIndex based on some options combinations
|
|
3078
3092
|
if (options.distributeSeries && !options.stackBars) {
|
|
@@ -3091,13 +3105,13 @@ class BarChart extends BaseChart {
|
|
|
3091
3105
|
// We need to transform coordinates differently based on the chart layout
|
|
3092
3106
|
if (options.horizontalBars) {
|
|
3093
3107
|
projected = {
|
|
3094
|
-
x: chartRect.x1 + valueAxis.projectValue(
|
|
3095
|
-
y: chartRect.y1 - labelAxis.projectValue(
|
|
3108
|
+
x: chartRect.x1 + valueAxis.projectValue(valueX || 0, valueIndex, normalizedData.series[seriesIndex]),
|
|
3109
|
+
y: chartRect.y1 - labelAxis.projectValue(valueY || 0, labelAxisValueIndex, normalizedData.series[seriesIndex])
|
|
3096
3110
|
};
|
|
3097
3111
|
} else {
|
|
3098
3112
|
projected = {
|
|
3099
|
-
x: chartRect.x1 + labelAxis.projectValue(
|
|
3100
|
-
y: chartRect.y1 - valueAxis.projectValue(
|
|
3113
|
+
x: chartRect.x1 + labelAxis.projectValue(valueX || 0, labelAxisValueIndex, normalizedData.series[seriesIndex]),
|
|
3114
|
+
y: chartRect.y1 - valueAxis.projectValue(valueY || 0, valueIndex, normalizedData.series[seriesIndex])
|
|
3101
3115
|
};
|
|
3102
3116
|
}
|
|
3103
3117
|
// If the label axis is a step based axis we will offset the bar into the middle of between two steps using
|
|
@@ -3112,6 +3126,10 @@ class BarChart extends BaseChart {
|
|
|
3112
3126
|
// Using bi-polar offset for multiple series if no stacked bars or series distribution is used
|
|
3113
3127
|
projected[labelAxis.units.pos] += options.stackBars || options.distributeSeries ? 0 : biPol * options.seriesBarDistance * (options.horizontalBars ? -1 : 1);
|
|
3114
3128
|
}
|
|
3129
|
+
// distinguish between positive and negative values in relative stack mode
|
|
3130
|
+
if (isAccumulateRelativeStackMode) {
|
|
3131
|
+
stackedBarValues = valueY >= 0 || valueX >= 0 ? posStackedBarValues : negStackedBarValues;
|
|
3132
|
+
}
|
|
3115
3133
|
// Enter value in stacked bar values used to remember previous screen value for stacking up bars
|
|
3116
3134
|
const previousStack = stackedBarValues[valueIndex] || zeroPoint;
|
|
3117
3135
|
stackedBarValues[valueIndex] = previousStack - (zeroPoint - projected[labelAxis.counterUnits.pos]);
|
|
@@ -3123,7 +3141,7 @@ class BarChart extends BaseChart {
|
|
|
3123
3141
|
["".concat(labelAxis.units.pos, "1")]: projected[labelAxis.units.pos],
|
|
3124
3142
|
["".concat(labelAxis.units.pos, "2")]: projected[labelAxis.units.pos]
|
|
3125
3143
|
};
|
|
3126
|
-
if (options.stackBars && (
|
|
3144
|
+
if (options.stackBars && (isAccumulateStackMode || isAccumulateRelativeStackMode || !options.stackMode)) {
|
|
3127
3145
|
// Stack mode: accumulate (default)
|
|
3128
3146
|
// If bars are stacked we use the stackedBarValues reference and otherwise base all bars off the zero line
|
|
3129
3147
|
// We want backwards compatibility, so the expected fallback without the 'stackMode' option
|
|
@@ -3145,8 +3163,8 @@ class BarChart extends BaseChart {
|
|
|
3145
3163
|
// Create bar element
|
|
3146
3164
|
const bar = seriesElement.elem("line", positions, options.classNames.bar).attr({
|
|
3147
3165
|
"ct:value": [
|
|
3148
|
-
|
|
3149
|
-
|
|
3166
|
+
valueX,
|
|
3167
|
+
valueY
|
|
3150
3168
|
].filter(isNumeric).join(","),
|
|
3151
3169
|
"ct:meta": serialize(metaData)
|
|
3152
3170
|
});
|