-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 export results to image/JSON
- Loading branch information
Artur Pryka
committed
Sep 24, 2020
1 parent
48298c9
commit 9ff7f12
Showing
14 changed files
with
265 additions
and
50 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
{ | ||
"deleteQuery": "Delete query", | ||
"shareQuery": "Share query" | ||
"shareQuery": "Share query", | ||
"exportResult": "Export result to", | ||
"image": "Image", | ||
"json": "JSON", | ||
"csv": "CSV", | ||
"tooltip": "Run query to export result" | ||
} |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import domtoimage from 'dom-to-image'; | ||
import { saveAs } from 'file-saver'; | ||
import { colors } from '@keen.io/colors'; | ||
|
||
const FILENAME = 'chart'; | ||
const BG_COLOR = colors.white[500]; | ||
|
||
export const exportToImage = ({ | ||
fileName = FILENAME, | ||
quality, | ||
backgroundColor = BG_COLOR, | ||
node, | ||
}: { | ||
fileName: string; | ||
node: HTMLElement; | ||
quality?: number; | ||
backgroundColor?: string; | ||
}) => { | ||
if (quality) { | ||
domtoimage | ||
.toBlob(node, { quality, bgcolor: backgroundColor }) | ||
.then((blob) => { | ||
saveAs(blob, `${fileName}.jpeg`); | ||
}); | ||
} else { | ||
domtoimage.toBlob(node).then((blob) => { | ||
saveAs(blob, `${fileName}.png`); | ||
}); | ||
} | ||
}; |
Oops, something went wrong.