1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

save plotly settings

This commit is contained in:
lana-k
2020-10-24 16:59:44 +02:00
parent fdd50b2f86
commit df54c9086b
3 changed files with 70 additions and 42 deletions

View File

@@ -45,8 +45,8 @@ export default {
const isFromScratch = !this.$store.state.currentTab.initName const isFromScratch = !this.$store.state.currentTab.initName
const value = { const value = {
id: currentQuery.id, id: currentQuery.id,
query: currentQuery.query query: currentQuery.query,
// TODO: save plotly settings plotly: currentQuery.getPlotlySatateForSave()
} }
if (isFromScratch) { if (isFromScratch) {

View File

@@ -6,21 +6,24 @@
:before="{ size: 50, max: 50 }" :before="{ size: 50, max: 50 }"
:after="{ size: 50, max: 100 }" :after="{ size: 50, max: 100 }"
> >
<div slot="left-pane" class="query-editor"> <template #left-pane>
<div class="query-editor">
<div class="codemirror-container"> <div class="codemirror-container">
<codemirror v-model="query" :options="cmOptions" @changes="onCmChange" ref="codemirror" /> <codemirror v-model="query" :options="cmOptions" @changes="onCmChange" ref="codemirror" />
</div> </div>
<div class="run-btn-container"> <div class="run-btn-container">
<button <button
class="primary run-btn" class="primary run-btn"
@click="execEditorContents" @click="execute(query)"
:disabled="!$store.state.schema" :disabled="!$store.state.schema"
> >
Run Run
</button> </button>
</div> </div>
</div> </div>
<div slot="right-pane" id="bottomPane" ref="bottomPane"> </template>
<template #right-pane>
<div id="bottomPane" ref="bottomPane">
<view-switcher :view.sync="view" /> <view-switcher :view.sync="view" />
<div v-show="view === 'table'" class="table-view"> <div v-show="view === 'table'" class="table-view">
<!-- <div id="error" class="error"></div> <!-- <div id="error" class="error"></div>
@@ -42,6 +45,7 @@
:advancedTraceTypeSelector="true" :advancedTraceTypeSelector="true"
/> />
</div> </div>
</template>
</splitpanes> </splitpanes>
</div> </div>
</template> </template>
@@ -64,6 +68,7 @@ import 'codemirror/addon/hint/show-hint.css'
import 'codemirror/addon/hint/sql-hint.js' import 'codemirror/addon/hint/sql-hint.js'
import PlotlyEditor from 'react-chart-editor' import PlotlyEditor from 'react-chart-editor'
import dereference from 'react-chart-editor/lib/lib/dereference'
export default { export default {
name: 'TabContent', name: 'TabContent',
@@ -78,12 +83,12 @@ export default {
data () { data () {
return { return {
plotly: plotly, plotly: plotly,
state: { state: this.initPlotly || {
data: [], data: [],
layout: {}, layout: {},
frames: [] frames: []
}, },
query: 'select * from albums', query: this.initQuery,
cmOptions: { cmOptions: {
// codemirror options // codemirror options
tabSize: 4, tabSize: 4,
@@ -126,7 +131,7 @@ export default {
this.$store.commit('setCurrentTab', this) this.$store.commit('setCurrentTab', this)
}, },
mounted () { mounted () {
new ResizeObserver(this.calculateTableHeight).observe(this.$refs.bottomPane) new ResizeObserver(this.handleResize).observe(this.$refs.bottomPane)
this.calculateTableHeight() this.calculateTableHeight()
}, },
watch: { watch: {
@@ -140,6 +145,11 @@ export default {
}, },
isUnsaved () { isUnsaved () {
this.$store.commit('updateTabState', { index: this.tabIndex, newValue: this.isUnsaved }) this.$store.commit('updateTabState', { index: this.tabIndex, newValue: this.isUnsaved })
},
dataSources () {
// we need to update state.data in order to update the graph
// https://github.com/plotly/react-chart-editor/issues/948
dereference(this.state.data, this.dataSources)
} }
}, },
methods: { methods: {
@@ -170,12 +180,17 @@ export default {
// Run a command in the database // Run a command in the database
execute (commands) { execute (commands) {
// this.$refs.output.textContent = 'Fetching results...' */ // this.$refs.output.textContent = 'Fetching results...' */
this.$db.execute(commands) this.$db.execute(commands + ';')
.then(result => { this.result = result }) .then(result => { this.result = result })
.catch(err => alert(err)) .catch(err => alert(err))
}, },
execEditorContents () { handleResize () {
this.execute(this.query + ';') if (this.view === 'chart') {
// hack react-chart editor: hidden and show in order to make the graph resize
this.view = 'not chart'
this.view = 'chart'
}
this.calculateTableHeight()
}, },
calculateTableHeight () { calculateTableHeight () {
const bottomPane = this.$refs.bottomPane const bottomPane = this.$refs.bottomPane
@@ -186,6 +201,17 @@ export default {
// 40 - height of table header // 40 - height of table header
const freeSpace = bottomPane.offsetHeight - 88 - 42 - 30 - 5 - 40 const freeSpace = bottomPane.offsetHeight - 88 - 42 - 30 - 5 - 40
this.tableViewHeight = freeSpace - (freeSpace % 40) this.tableViewHeight = freeSpace - (freeSpace % 40)
},
getPlotlySatateForSave () {
// we don't need to save the data, only settings
// so we modify state.data using dereference
const stateCopy = JSON.parse(JSON.stringify(this.state))
const emptySources = {}
for (const key in this.dataSources) {
emptySources[key] = []
}
dereference(stateCopy.data, emptySources)
return stateCopy
} }
} }
} }

View File

@@ -34,6 +34,8 @@
:key="tab.id" :key="tab.id"
:id="tab.id" :id="tab.id"
:init-name="tab.name" :init-name="tab.name"
:init-query="tab.query"
:init-plotly="tab.plotly"
:tab-index="index" :tab-index="index"
/> />
<div v-if="tabs.length === 0" id="start-guide"> <div v-if="tabs.length === 0" id="start-guide">