Skip to content

Commit

Permalink
improve custom width/scale code when exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Aug 23, 2024
1 parent 04c9f86 commit 0b35f7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/modules/Exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ class Exports {
return result
}

getSvgString(scale) {
if (scale == undefined) {
getSvgString() {
const w = this.w
const width = w.config.chart.toolbar.export.width
let scale =
w.config.chart.toolbar.export.scale || width / w.globals.svgWidth

if (!scale) {
scale = 1 // if no scale is specified, don't scale...
}
let svgString = this.w.globals.dom.Paper.svg()
Expand Down Expand Up @@ -122,7 +127,7 @@ class Exports {
ctx.fillStyle = canvasBg
ctx.fillRect(0, 0, canvas.width * scale, canvas.height * scale)

const svgData = this.getSvgString(scale)
const svgData = this.getSvgString()

if (window.canvg && Utils.isIE11()) {
// use canvg as a polyfill to workaround ie11 considering a canvas with loaded svg 'unsafe'
Expand Down Expand Up @@ -173,7 +178,11 @@ class Exports {
exportToPng() {
const scale = this.w.config.chart.toolbar.export.scale
const width = this.w.config.chart.toolbar.export.width
const option = scale ? {scale: scale}: width? {width: width}: undefined
const option = scale
? { scale: scale }
: width
? { width: width }
: undefined
this.dataURI(option).then(({ imgURI, blob }) => {
if (blob) {
navigator.msSaveOrOpenBlob(blob, this.w.globals.chartID + '.png')
Expand Down
2 changes: 2 additions & 0 deletions src/modules/settings/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ export default class Options {
svg: {
filename: undefined,
},
scale: undefined,
width: undefined,
},
autoSelected: 'zoom', // accepts -> zoom, pan, selection
},
Expand Down
2 changes: 2 additions & 0 deletions types/apexcharts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ type ApexChart = {
png?: {
filename?: undefined | string
}
width?: number
scale?: number
}
autoSelected?: 'zoom' | 'selection' | 'pan'
}
Expand Down

0 comments on commit 0b35f7d

Please sign in to comment.