Skip to content

Commit

Permalink
Make save svg & save png method signatures consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Aug 3, 2024
1 parent c556237 commit 903de96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dev/misc/svg.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
const browser = await igv.createBrowser(document.getElementById('igv-app-container'), bedgraph_options)

// $('#igv-draw-svg-button').on('click', () => browser.renderSVG($('#igv-svg-container')))
$('#igv-draw-svg-button').on('click', () => browser.saveSVGtoFile({ $container: $('#igv-svg-container') }))
$('#igv-draw-svg-button').on('click', () => browser.saveSVGtoFile(null, $('#igv-svg-container')[0]))


})()
Expand Down
20 changes: 11 additions & 9 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,23 +447,25 @@ class Browser {
return context.getSerializedSvg(true)
}

saveSVGtoFile(config) {
saveSVGtoFile(filename, container) {

let svg = this.toSVG()
let svgString = this.toSVG()

// For testing
if (config.$container) {
config.$container.empty()
config.$container.append(svg)
// Append svg t testing, not used in production
if (container) {
const svg = document.createElement("svg");
svg.innerHTML = svgString
container.append(svg)
container.appendChild(svg)
}

const path = config.filename || 'igvjs.svg'
const data = URL.createObjectURL(new Blob([svg], {type: "application/octet-stream"}))
const path = filename || 'igvjs.svg'
const data = URL.createObjectURL(new Blob([svgString], {type: "application/octet-stream"}))
FileUtils.download(path, data)
URL.revokeObjectURL(data) // Important to prevent memory leak
}

savePNGtoFile({filename}) {
savePNGtoFile(filename) {

const svgAsString = this.toSVG()

Expand Down

0 comments on commit 903de96

Please sign in to comment.