Created
February 14, 2020 15:13
-
-
Save tabjy/755444558b51957c4cabe995671b0f50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const svg = document.querySelectorAll('#chart svg')[0] | |
const width = svg.getAttribute("width") | |
const height = svg.getAttribute("height") | |
const image = new Image() | |
image.setAttribute("width", width) | |
image.setAttribute("height", height) | |
const clone = svg.cloneNode(true) | |
const style = document.createElement('style') | |
style.innerHTML = ` | |
.d3-flame-graph rect { | |
stroke: #EEEEEE; | |
fill-opacity: .8; | |
} | |
.d3-flame-graph rect:hover { | |
stroke: #474747; | |
stroke-width: 0.5; | |
cursor: pointer; | |
} | |
.d3-flame-graph-label { | |
pointer-events: none; | |
white-space: nowrap; | |
text-overflow: ellipsis; | |
overflow: hidden; | |
font-size: 12px; | |
font-family: Verdana; | |
margin-left: 4px; | |
margin-right: 4px; | |
line-height: 1.5; | |
padding: 0 0 0; | |
font-weight: 400; | |
color: black; | |
text-align: left; | |
}` | |
clone.appendChild(style) | |
const xml = new XMLSerializer().serializeToString(clone); | |
image.src = 'data:image/svg+xml;base64,' + btoa(xml) | |
// image.onload = console.log("image loaded") | |
image.onload = () => { | |
console.log('image loaded') | |
const canvas = document.createElement('canvas') | |
canvas.setAttribute("width", width) | |
canvas.setAttribute("height", height) | |
canvas.getContext('2d').drawImage(image, 0, 0) | |
const win = window.open(canvas.toDataURL("image/png"),'flamegraph') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment