Skip to content

Commit

Permalink
toPNG method fix (#38)
Browse files Browse the repository at this point in the history
* Changed data conversion from toDataURL to toBlob (for making able to download files larger then 2MB)

* Fixed SVG loading (using blobs)

* Fixed syntax
  • Loading branch information
daniilsavchuk authored and sidoruka committed Oct 5, 2017
1 parent 3753e74 commit fb5d73a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ processButton('btn-generate', () => {

processButton('btn-get-svg', () => {
const element = document.createElement('a');
element.setAttribute('href', `data:text/plain;charset=utf-8,${diagram.paper.getSVG()}`);
const blob = new Blob([diagram.paper.getSVG()], { type: 'text/plain;charset=utf-8' });
element.setAttribute('href', window.URL.createObjectURL(blob));
element.setAttribute('download', 'diagram.svg');
element.style.display = 'none';
document.body.appendChild(element);
Expand All @@ -86,7 +87,7 @@ processButton('btn-get-svg', () => {
processButton('btn-get-png', () => {
diagram.paper.getPNG((data) => {
const element = document.createElement('a');
element.setAttribute('href', data);
element.setAttribute('href', window.URL.createObjectURL(data));
element.setAttribute('download', 'diagram.png');
element.style.display = 'none';
document.body.appendChild(element);
Expand Down
2 changes: 1 addition & 1 deletion src/visual/Paper.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class Paper extends joint.dia.Paper {
context.fillStyle = opts.bgrColor || '#FFFFFF';
context.fillRect(0, 0, canvas.width, canvas.height);
context.drawImage(image, 0, 0);
callback(canvas.toDataURL('image/png'));
canvas.toBlob(callback, 'image/png');
};
}

Expand Down

0 comments on commit fb5d73a

Please sign in to comment.