-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KED-2355] Update SVG-Crowbar to fix errors #339
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = graphSize.width && 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 | ||
|
@@ -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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might be worth to rethink about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it works as is without needing an explict height - I don't think we need to think any more about this extreme edge case. I tidied up the console errors for the sake of completeness as I don't like exposing uncaught errors, but I don't think it needs anything else tbh. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure thing, just tested and the errors are gone, so if it works without the need to manually specify a width and height then it's all good. |
||
|
||
const style = document.createElement('style'); | ||
if (format === 'svg') { | ||
|
@@ -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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add the checks for valid values of
width
andheight
to eliminate those console errors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point! fixed 👍