You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2020/12/01 10:53:21 UTC
[incubator-echarts] 01/05: fix(svg): fix charts cannot be exported
in svg renderer in IE.
This is an automated email from the ASF dual-hosted git repository.
wangzx pushed a commit to branch fix-svg-export
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 4174861d4d603038fb72227056e6ad845f3383e3
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Fri Nov 20 21:45:53 2020 +0800
fix(svg): fix charts cannot be exported in svg renderer in IE.
---
src/component/toolbox/feature/SaveAsImage.ts | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/component/toolbox/feature/SaveAsImage.ts b/src/component/toolbox/feature/SaveAsImage.ts
index b7c335b..86389da 100644
--- a/src/component/toolbox/feature/SaveAsImage.ts
+++ b/src/component/toolbox/feature/SaveAsImage.ts
@@ -74,7 +74,19 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> {
// IE
else {
if (window.navigator.msSaveOrOpenBlob) {
- const bstr = atob(url.split(',')[1]);
+ const parts = url.split(',');
+ // data:[<mime type>][;charset=<charset>][;base64],<encoded data>
+ // see https://css-tricks.com/data-uris/
+ const base64Encoded = parts[0].indexOf('base64') > -1;
+ let bstr = isSvg
+ // should decode the svg data uri first
+ ? decodeURIComponent(parts[1])
+ : parts[1];
+ // only `atob` when the data uri is encoded with base64
+ // otherwise, like `svg` data uri exported by zrender,
+ // there will be an error, for it's not encoded with base64.
+ // (just a url-encoded string through `encodeURIComponent`)
+ base64Encoded && (bstr = atob(bstr));
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n--) {
@@ -91,6 +103,7 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> {
+ '</body>';
const tab = window.open();
tab.document.write(html);
+ tab.document.title = title as string;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org