Skip to content

Commit

Permalink
Update SVG-Crowbar to fix errors (#339)
Browse files Browse the repository at this point in the history
We were originally using SVG-Crowbar v0.6.0, but started experiencing a critical CORS error with internal CSS in exported images, which was patched in #337. This PR updates the dependency version and reverts the patch.
  • Loading branch information
richardwestenra authored Jan 7, 2021
1 parent 97ea795 commit 983b5d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"reselect": "^4.0.0",
"seedrandom": "^3.0.5",
"snyk": "^1.369.2",
"svg-crowbar": "^0.6.0",
"svg-crowbar": "^0.6.5",
"what-input": "^5.2.10"
},
"peerDependencies": {
Expand Down Expand Up @@ -121,4 +121,4 @@
"not op_mini all"
],
"snyk": true
}
}
20 changes: 13 additions & 7 deletions src/components/export-modal/export-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ const exportGraph = ({ format, theme, graphSize, mockFn }) => {
clone.classList.add('kedro', `kui-theme--${theme}`, 'pipeline-graph--export');

// Reset zoom/translate
let width = graphSize.width + graphSize.marginx * 2;
let height = graphSize.height + graphSize.marginy * 2;
clone.setAttribute('viewBox', `0 0 ${width} ${height}`);
let width, height;
const hasGraph = isFinite(graphSize.width) && isFinite(graphSize.height);
if (hasGraph) {
width = graphSize.width + graphSize.marginx * 2;
height = graphSize.height + graphSize.marginy * 2;
clone.setAttribute('viewBox', `0 0 ${width} ${height}`);
}
clone.querySelector('#zoom-wrapper').removeAttribute('transform');

// Impose a maximum size on PNGs because otherwise they break when downloading
Expand All @@ -32,8 +36,10 @@ const exportGraph = ({ format, theme, graphSize, mockFn }) => {
width = Math.min(width, maxWidth);
height = Math.min(height, maxWidth * (height / width));
}
clone.setAttribute('width', width);
clone.setAttribute('height', height);
if (hasGraph) {
clone.setAttribute('width', width);
clone.setAttribute('height', height);
}

const style = document.createElement('style');
if (format === 'svg') {
Expand All @@ -50,8 +56,8 @@ const exportGraph = ({ format, theme, graphSize, mockFn }) => {
clone.prepend(style);

// Download SVG/PNG
download(clone, 'kedro-pipeline');
// @TODO: Replace third { css: 'internal' } argument when CORS issue is fixed
const options = format === 'svg' ? { css: 'internal' } : undefined;
download(clone, 'kedro-pipeline', options);

// Delete cloned SVG
svg.parentNode.removeChild(clone);
Expand Down

0 comments on commit 983b5d8

Please sign in to comment.