1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 10:38:54 +08:00

#89 export to html plolty charts and pivots

This commit is contained in:
lana-k
2021-12-21 22:13:02 +01:00
parent c1cc5bb95e
commit 8669a6a9e5
6 changed files with 138 additions and 7 deletions

View File

@@ -34,8 +34,15 @@ export async function getImageDataUrl (element, type) {
})
}
export function getHtml (element, options) {
export function getChartData (element) {
const chartElement = element.querySelector('.js-plotly-plot')
return {
data: chartElement.data,
layout: chartElement.layout,
}
}
export function getHtml (options) {
const chartId = nanoid()
return `
<head>
@@ -48,12 +55,12 @@ export function getHtml (element, options) {
const el = document.getElementById("${chartId}")
let timeout
function debounceResize() {
function debounceResize() {
clearTimeout(timeout)
timeout = setTimeout(() => {
var r = el.getBoundingClientRect()
Plotly.relayout(el, {width: r.width, height: r.height})
}, 200)
var r = el.getBoundingClientRect()
Plotly.relayout(el, {width: r.width, height: r.height})
}, 200)
}
const resizeObserver = new ResizeObserver(debounceResize)
@@ -69,5 +76,6 @@ export default {
getOptionsFromDataSources,
getOptionsForSave,
getImageDataUrl,
getHtml
getHtml,
getChartData
}