Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/core/echarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ class ECharts extends Eventful<ECEventDefinition> {
const url = this._zr.painter.getType() === 'svg'
? this.getSvgDataURL()
: this.renderToCanvas(opts).toDataURL(
'image/' + (opts && opts.type || 'png')
'image/' + (opts.type || 'png')
);

each(excludesComponentViews, function (view) {
Expand All @@ -1022,6 +1022,10 @@ class ECharts extends Eventful<ECEventDefinition> {
return;
}

// `opts` is optional. Normalize it so the reads below and `getDataURL`
// can access its properties directly.
opts = opts || {};

const isSvg = opts.type === 'svg';
const groupId = this.group;
const mathMin = Math.min;
Expand All @@ -1033,7 +1037,7 @@ class ECharts extends Eventful<ECEventDefinition> {
let right = -MAX_NUMBER;
let bottom = -MAX_NUMBER;
const canvasList: {dom: HTMLCanvasElement | string, left: number, top: number}[] = [];
const dpr = (opts && opts.pixelRatio) || this.getDevicePixelRatio();
const dpr = opts.pixelRatio || this.getDevicePixelRatio();

each(instances, function (chart, id) {
if (chart.group === groupId) {
Expand Down Expand Up @@ -1113,7 +1117,7 @@ class ECharts extends Eventful<ECEventDefinition> {
});
zr.refreshImmediately();

return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
return targetCanvas.toDataURL('image/' + (opts.type || 'png'));
}
}
else {
Expand Down
60 changes: 60 additions & 0 deletions test/ut/spec/api/getConnectedDataURL.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.