mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-08 02:58:54 +08:00
events
This commit is contained in:
@@ -31,10 +31,15 @@ import PlotlyEditor from 'react-chart-editor'
|
||||
import chartHelper from '@/lib/chartHelper'
|
||||
import dereference from 'react-chart-editor/lib/lib/dereference'
|
||||
import fIo from '@/lib/utils/fileIo'
|
||||
import { send } from '@/lib/utils/events'
|
||||
|
||||
export default {
|
||||
name: 'Chart',
|
||||
props: ['dataSources', 'initOptions', 'importToPngEnabled', 'importToSvgEnabled'],
|
||||
props: [
|
||||
'dataSources', 'initOptions',
|
||||
'importToPngEnabled', 'importToSvgEnabled',
|
||||
'forPivot'
|
||||
],
|
||||
components: {
|
||||
PlotlyEditor
|
||||
},
|
||||
@@ -60,6 +65,19 @@ export default {
|
||||
plotly.setPlotConfig({
|
||||
notifyOnLogging: 1
|
||||
})
|
||||
this.$watch(
|
||||
() => JSON.stringify(
|
||||
this.state.data.map(trace => `${trace.type}-${trace.mode}`)
|
||||
),
|
||||
(value) => {
|
||||
send({
|
||||
category: 'viz_plotly',
|
||||
action: 'render',
|
||||
label: `type=${value} pivot=${this.forPivot ? 'true' : 'false'}`
|
||||
})
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
},
|
||||
mounted () {
|
||||
this.resizeObserver = new ResizeObserver(this.handleResize)
|
||||
|
||||
@@ -23,6 +23,7 @@ import pivotHelper from './pivotHelper'
|
||||
import Chart from '@/views/Main/Workspace/Tabs/Tab/DataView/Chart'
|
||||
import chartHelper from '@/lib/chartHelper'
|
||||
import Vue from 'vue'
|
||||
import { send } from '@/lib/utils/events'
|
||||
const ChartClass = Vue.extend(Chart)
|
||||
|
||||
export default {
|
||||
@@ -89,6 +90,11 @@ export default {
|
||||
handler () {
|
||||
this.$emit('update:importToPngEnabled', this.pivotOptions.rendererName !== 'TSV Export')
|
||||
this.$emit('update:importToSvgEnabled', this.viewStandartChart || this.viewCustomChart)
|
||||
send({
|
||||
category: 'viz_pivot',
|
||||
action: 'render',
|
||||
label: `type=${this.pivotOptions.rendererName}`
|
||||
})
|
||||
}
|
||||
},
|
||||
pivotOptions () {
|
||||
@@ -179,11 +185,11 @@ export default {
|
||||
async prepareCopy () {
|
||||
if (this.viewCustomChart) {
|
||||
return await this.pivotOptions.rendererOptions.customChartComponent.prepareCopy()
|
||||
} else if (this.viewStandartChart) {
|
||||
return await chartHelper.getImageDataUrl(this.$refs.pivotOutput, 'png')
|
||||
} else {
|
||||
return await pivotHelper.getPivotCanvas(this.$refs.pivotOutput)
|
||||
}
|
||||
if (this.viewStandartChart) {
|
||||
return await chartHelper.getImageDataUrl(this.$refs.pivotOutput, 'png')
|
||||
}
|
||||
return await pivotHelper.getPivotCanvas(this.$refs.pivotOutput)
|
||||
},
|
||||
|
||||
async saveAsSvg () {
|
||||
@@ -198,20 +204,23 @@ export default {
|
||||
saveAsHtml () {
|
||||
if (this.viewCustomChart) {
|
||||
this.pivotOptions.rendererOptions.customChartComponent.saveAsHtml()
|
||||
} else if (this.viewStandartChart) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.viewStandartChart) {
|
||||
const chartState = chartHelper.getChartData(this.$refs.pivotOutput)
|
||||
fIo.exportToFile(
|
||||
chartHelper.getHtml(chartState),
|
||||
'chart.html',
|
||||
'text/html'
|
||||
)
|
||||
} else {
|
||||
fIo.exportToFile(
|
||||
pivotHelper.getPivotHtml(this.$refs.pivotOutput),
|
||||
'pivot.html',
|
||||
'text/html'
|
||||
)
|
||||
return
|
||||
}
|
||||
fIo.exportToFile(
|
||||
pivotHelper.getPivotHtml(this.$refs.pivotOutput),
|
||||
'pivot.html',
|
||||
'text/html'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ export function _getDataSources (pivotData) {
|
||||
|
||||
function customChartRenderer (data, options) {
|
||||
options.customChartComponent.dataSources = _getDataSources(data)
|
||||
options.customChartComponent.forPivot = true
|
||||
|
||||
options.customChartComponent.$mount()
|
||||
|
||||
return $(options.customChartComponent.$el)
|
||||
|
||||
@@ -95,6 +95,7 @@ import ClipboardIcon from '@/components/svg/clipboard'
|
||||
import cIo from '@/lib/utils/clipboardIo'
|
||||
import loadingDialog from '@/components/LoadingDialog'
|
||||
import time from '@/lib/utils/time'
|
||||
import { send } from '@/lib/utils/events'
|
||||
|
||||
export default {
|
||||
name: 'DataView',
|
||||
@@ -123,6 +124,11 @@ export default {
|
||||
dataToCopy: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
plotlyInPivot () {
|
||||
return this.mode === 'pivot' && this.$refs.viewComponent.viewCustomChart
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
mode () {
|
||||
this.$emit('update')
|
||||
@@ -148,6 +154,7 @@ export default {
|
||||
*/
|
||||
await time.sleep(0)
|
||||
this.$refs.viewComponent.saveAsPng()
|
||||
this.exportSignal('png')
|
||||
},
|
||||
getOptionsForSave () {
|
||||
return this.$refs.viewComponent.getOptionsForSave()
|
||||
@@ -178,6 +185,7 @@ export default {
|
||||
async copyToClipboard () {
|
||||
cIo.copyImage(this.dataToCopy)
|
||||
this.$modal.hide('prepareCopy')
|
||||
this.exportSignal('clipboard')
|
||||
},
|
||||
cancelCopy () {
|
||||
this.dataToCopy = null
|
||||
@@ -186,9 +194,20 @@ export default {
|
||||
|
||||
saveAsSvg () {
|
||||
this.$refs.viewComponent.saveAsSvg()
|
||||
this.exportSignal('svg')
|
||||
},
|
||||
saveAsHtml () {
|
||||
this.$refs.viewComponent.saveAsHtml()
|
||||
this.exportSignal('html')
|
||||
},
|
||||
exportSignal (to) {
|
||||
send({
|
||||
category: this.plotlyInPivot || this.mode === 'chart'
|
||||
? 'viz_plotly' : 'viz_pivot',
|
||||
action: 'export',
|
||||
label: `type=${to}${this.plotlyInPivot
|
||||
? ' pivot=true' : this.mode === 'chart' ? ' pivot=false' : ''}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ import fIo from '@/lib/utils/fileIo'
|
||||
import cIo from '@/lib/utils/clipboardIo'
|
||||
import time from '@/lib/utils/time'
|
||||
import loadingDialog from '@/components/LoadingDialog'
|
||||
import { send } from '@/lib/utils/events'
|
||||
|
||||
export default {
|
||||
name: 'RunResult',
|
||||
@@ -117,10 +118,28 @@ export default {
|
||||
},
|
||||
|
||||
exportToCsv () {
|
||||
if (this.result && this.result.values) {
|
||||
send({
|
||||
category: 'resultset',
|
||||
action: 'export',
|
||||
value: this.result.values[this.result.columns[0]].length,
|
||||
label: 'to=csv'
|
||||
})
|
||||
}
|
||||
|
||||
fIo.exportToFile(csv.serialize(this.result), 'result_set.csv', 'text/csv')
|
||||
},
|
||||
|
||||
async prepareCopy () {
|
||||
if (this.result && this.result.values) {
|
||||
send({
|
||||
category: 'resultset',
|
||||
action: 'export',
|
||||
value: this.result.values[this.result.columns[0]].length,
|
||||
label: 'to=clipboard'
|
||||
})
|
||||
}
|
||||
|
||||
if ('ClipboardItem' in window) {
|
||||
this.preparingCopy = true
|
||||
this.$modal.show('prepareCSVCopy')
|
||||
|
||||
@@ -56,6 +56,7 @@ import DataView from './DataView'
|
||||
import RunResult from './RunResult'
|
||||
import time from '@/lib/utils/time'
|
||||
import Teleport from 'vue2-teleport'
|
||||
import { send } from '@/lib/utils/events'
|
||||
|
||||
export default {
|
||||
name: 'Tab',
|
||||
@@ -121,11 +122,33 @@ export default {
|
||||
const start = new Date()
|
||||
this.result = await state.db.execute(this.query + ';')
|
||||
this.time = time.getPeriod(start, new Date())
|
||||
|
||||
if (this.result && this.result.values) {
|
||||
send({
|
||||
category: 'resultset',
|
||||
action: 'create',
|
||||
value: this.result.values[this.result.columns[0]].length
|
||||
})
|
||||
}
|
||||
|
||||
send({
|
||||
category: 'query',
|
||||
action: 'run',
|
||||
value: this.time,
|
||||
label: 'status=success'
|
||||
})
|
||||
} catch (err) {
|
||||
this.error = {
|
||||
type: 'error',
|
||||
message: err
|
||||
}
|
||||
|
||||
send({
|
||||
category: 'query',
|
||||
action: 'run',
|
||||
value: 0,
|
||||
label: 'status=error'
|
||||
})
|
||||
}
|
||||
state.db.refreshSchema()
|
||||
this.isGettingResults = false
|
||||
|
||||
Reference in New Issue
Block a user