Skip to content

Commit

Permalink
apexcharts#4592 Toolbar PNG export with desired scale or width
Browse files Browse the repository at this point in the history
  • Loading branch information
rs-tsc committed Jul 30, 2024
1 parent 0fb45c4 commit 170fd6e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/apexcharts.amd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/apexcharts.common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/apexcharts.esm.js

Large diffs are not rendered by default.

49 changes: 39 additions & 10 deletions dist/apexcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,15 @@
}
}
}
// prevents JS prevision errors when adding
}, {
key: "preciseAddition",
value: function preciseAddition(a, b) {
var aDecimals = (String(a).split('.')[1] || '').length;
var bDecimals = (String(b).split('.')[1] || '').length;
var factor = Math.pow(10, Math.max(aDecimals, bDecimals));
return (Math.round(a * factor) + Math.round(b * factor)) / factor;
}
}, {
key: "isNumber",
value: function isNumber(value) {
Expand Down Expand Up @@ -612,7 +621,7 @@
// other browser
return false;
}
//
//
// Find the Greatest Common Divisor of two numbers
//
}, {
Expand Down Expand Up @@ -9183,7 +9192,14 @@
key: "exportToPng",
value: function exportToPng() {
var _this2 = this;
this.dataURI().then(function (_ref) {
var scale = this.w.config.chart.toolbar.export.png.scale;
var width = this.w.config.chart.toolbar.export.png.width;
var options = scale ? {
scale: scale
} : width ? {
width: width
} : undefined;
this.dataURI(options).then(function (_ref) {
var imgURI = _ref.imgURI,
blob = _ref.blob;
if (blob) {
Expand Down Expand Up @@ -10748,22 +10764,31 @@
var index = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
var step = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
var range = Math.abs(yMax - yMin);
var result = [];
if (yMin === yMax) {
result = [yMin];
return {
result: result,
niceMin: result[0],
niceMax: result[result.length - 1]
};
}
ticks = this._adjustTicksForSmallRange(ticks, index, range);
if (ticks === 'dataPoints') {
ticks = this.w.globals.dataPoints - 1;
}
if (!step) {
step = range / ticks;
}
step = Math.round((step + Number.EPSILON) * 10) / 10;
if (ticks === Number.MAX_VALUE) {
ticks = 5;
step = 1;
}
var result = [];
var v = yMin;
while (ticks >= 0) {
result.push(v);
v = v + step;
v = Utils$1.preciseAddition(v, step);
ticks -= 1;
}
return {
Expand Down Expand Up @@ -10880,7 +10905,11 @@
// no data in the chart. Either all series collapsed or user passed a blank array
gl.xAxisScale = this.linearScale(0, 10, 10);
} else {
gl.xAxisScale = this.linearScale(minX, maxX, w.config.xaxis.tickAmount ? w.config.xaxis.tickAmount : diff < 10 && diff > 1 ? diff + 1 : 10, 0, w.config.xaxis.stepSize);
var ticks = gl.xTickAmount + 1;
if (diff < 10 && diff > 1) {
ticks = diff;
}
gl.xAxisScale = this.linearScale(minX, maxX, ticks, 0, w.config.xaxis.stepSize);
}
return gl.xAxisScale;
}
Expand Down Expand Up @@ -10913,21 +10942,21 @@
// 1: [1,2,3,4]
// If the chart is stacked, it can be assumed that any axis with multiple
// series is stacked.
//
//
// If this is an old chart and we are being backward compatible, it will be
// expected that each series is associated with it's corresponding yaxis
// through their indices, one-to-one.
// If yaxis.seriesName matches series.name, we have indices yi and si.
// A name match where yi != si is interpretted as yaxis[yi] and yaxis[si]
// will both be scaled to fit the combined series[si] and series[yi].
// Consider series named: S0,S1,S2 and yaxes A0,A1,A2.
//
//
// Example 1: A0 and A1 scaled the same.
// A0.seriesName: S0
// A1.seriesName: S0
// A2.seriesName: S2
// Then A1 <-> A0
//
//
// Example 2: A0, A1 and A2 all scaled the same.
// A0.seriesName: S2
// A1.seriesName: S0
Expand Down Expand Up @@ -10972,7 +11001,7 @@
if (!seriesNameArrayStyle || unassignedSeriesIndices.indexOf(si) > -1) {
axisSeriesMap[yi].push([yi, si]);
} else {
console.warn("Series '" + s.name + "' referenced more than once in what looks like the new style." + " That is, when using either seriesName: []," + " or when there are more series than yaxes.");
console.warn("Series '" + s.name + "' referenced more than once in what looks like the new style." + ' That is, when using either seriesName: [],' + ' or when there are more series than yaxes.');
}
} else {
// The series index refers to the target yaxis and the current
Expand Down Expand Up @@ -13923,7 +13952,7 @@
});
var SVGMarker = SVG(elMarker).size('100%', '100%');
var marker = new Graphics(this.ctx).drawMarker(0, 0, _objectSpread2(_objectSpread2({}, markerConfig), {}, {
pointFillColor: Array.isArray(w.config.legend.markers.fillColors) ? fillcolor[i] : markerConfig.pointFillColor,
pointFillColor: Array.isArray(fillcolor) ? fillcolor[i] : markerConfig.pointFillColor,
shape: shape
}));
var shapesEls = SVG.select('.apexcharts-legend-marker.apexcharts-marker').members;
Expand Down
2 changes: 1 addition & 1 deletion dist/apexcharts.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/modules/Exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ class Exports {
}

exportToPng() {
this.dataURI().then(({ imgURI, blob }) => {
const scale = this.w.config.chart.toolbar.export.png.scale
const width = this.w.config.chart.toolbar.export.png.width
const options = scale ? {scale: scale}: width? {width: width}: undefined
this.dataURI(options).then(({ imgURI, blob }) => {
if (blob) {
navigator.msSaveOrOpenBlob(blob, this.w.globals.chartID + '.png')
} else {
Expand Down

0 comments on commit 170fd6e

Please sign in to comment.