Commit a8b02333 authored by Yuri Mikhin's avatar Yuri Mikhin Committed by Yuri Mikhin

Add timeout for PNG chart saving.

parent a344becc
...@@ -51,28 +51,31 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight }: Prop ...@@ -51,28 +51,31 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight }: Prop
}, []); }, []);
const handleFileSaveClick = useCallback(() => { const handleFileSaveClick = useCallback(() => {
if (ref.current) { // wait for context menu to close
domToImage.toPng(ref.current, setTimeout(() => {
{ if (ref.current) {
quality: 100, domToImage.toPng(ref.current,
bgcolor: pngBackgroundColor, {
width: ref.current.offsetWidth * DOWNLOAD_IMAGE_SCALE, quality: 100,
height: ref.current.offsetHeight * DOWNLOAD_IMAGE_SCALE, bgcolor: pngBackgroundColor,
filter: (node) => node.nodeName !== 'BUTTON', width: ref.current.offsetWidth * DOWNLOAD_IMAGE_SCALE,
style: { height: ref.current.offsetHeight * DOWNLOAD_IMAGE_SCALE,
borderColor: 'transparent', filter: (node) => node.nodeName !== 'BUTTON',
transform: `scale(${ DOWNLOAD_IMAGE_SCALE })`, style: {
'transform-origin': 'top left', borderColor: 'transparent',
}, transform: `scale(${ DOWNLOAD_IMAGE_SCALE })`,
}) 'transform-origin': 'top left',
.then((dataUrl) => { },
const link = document.createElement('a'); })
link.download = `${ title } (Blockscout chart).png`; .then((dataUrl) => {
link.href = dataUrl; const link = document.createElement('a');
link.click(); link.download = `${ title } (Blockscout chart).png`;
link.remove(); link.href = dataUrl;
}); link.click();
} link.remove();
});
}
}, 100);
}, [ pngBackgroundColor, title ]); }, [ pngBackgroundColor, title ]);
const handleSVGSavingClick = useCallback(() => { const handleSVGSavingClick = useCallback(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment