Created
April 18, 2021 19:16
-
-
Save macro6461/01004f7a0a9df966ef57bbb6f400c1e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import {useState} from 'react'; | |
import Visualization from './Visualization' | |
import * as htmlToImage from 'html-to-image'; | |
const HtmlToImage = ({data, saveAs, }) =>{ | |
const [time, setTime] = useState(null) | |
const exportAsPicture = () => { | |
var t0 = performance.now() | |
var data = document.getElementsByClassName('htmlToImageVis') | |
for (var i = 0; i < data.length; ++i){ | |
htmlToImage.toPng(data[i]).then((dataUrl) => { | |
saveAs(dataUrl, 'my-node.png'); | |
}); | |
} | |
var t1 = performance.now() | |
var t = t1 - t0 | |
setTime(t.toFixed(3)) | |
} | |
return <div> | |
<h1>HTML TO IMAGE</h1> | |
{data.map(vis=>{ | |
return <Visualization visualization={vis} className="htmlToImageVis"/> | |
})} | |
<button onClick={exportAsPicture}>capture</button> | |
<p>TOTAL TIME: {time} ms</p> | |
</div> | |
}; | |
export default HtmlToImage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment