1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2026-08-05 07:19:17 +08:00

#139 view details of selected points

This commit is contained in:
lana-k
2026-07-20 21:37:24 +02:00
parent 686a09a8ce
commit 9838421d65
7 changed files with 58 additions and 13 deletions

View File

@@ -33,9 +33,9 @@
</template> </template>
<template v-if="showValueViewer" #right-pane> <template v-if="showValueViewer" #right-pane>
<value-viewer <value-viewer
:empty="!selectedItem" :empty="!selectedItems || selectedItems.length === 0"
emptyMessage="No points selected to view" emptyMessage="No points selected to view"
:value="JSON.stringify(selectedItem)" :value="JSON.stringify(selectedItems)"
defaultFormat="json" defaultFormat="json"
/> />
</template> </template>
@@ -95,7 +95,7 @@ export default {
}, },
resizeObserver: null, resizeObserver: null,
useResizeHandler: this.$store.state.isWorkspaceVisible, useResizeHandler: this.$store.state.isWorkspaceVisible,
selectedItem: null selectedItems: null
} }
}, },
computed: { computed: {
@@ -105,6 +105,7 @@ export default {
}, },
watch: { watch: {
dataSources() { dataSources() {
chartHelper.clearSelection(this.state.data, this.state.layout)
// we need to update state.data in order to update the graph // we need to update state.data in order to update the graph
// https://github.com/plotly/react-chart-editor/issues/948 // https://github.com/plotly/react-chart-editor/issues/948
if (this.dataSources) { if (this.dataSources) {
@@ -151,11 +152,14 @@ export default {
this.$refs.plotlyEditor?.$el?.querySelector('.js-plotly-plot') this.$refs.plotlyEditor?.$el?.querySelector('.js-plotly-plot')
plotlyDiv?.on('plotly_selected', selectionEvent => { plotlyDiv?.on('plotly_selected', selectionEvent => {
if (selectionEvent) { if (selectionEvent) {
this.selectedItem = 1 this.selectedItems = chartHelper.getRowsByIndexFromDataSources(
this.dataSources,
selectionEvent.points.map(point => point.pointIndex)
)
} }
}) })
plotlyDiv?.on('plotly_deselect', () => { plotlyDiv?.on('plotly_deselect', () => {
this.selectedItem = null this.selectedItems = null
}) })
}, },
activated() { activated() {
@@ -179,10 +183,8 @@ export default {
// TODO: check changes and enable Save button if needed // TODO: check changes and enable Save button if needed
}, },
update(data, layout, frames) { update(data, layout, frames) {
if (layout?.selections?.length > 0) { chartHelper.clearSelection(data, layout)
layout.selections = []
data.forEach(dataItem => delete dataItem.selectedpoints)
}
this.state = { data, layout, frames } this.state = { data, layout, frames }
this.$emit('update') this.$emit('update')
}, },

View File

@@ -58,7 +58,7 @@
</icon-button> </icon-button>
<icon-button <icon-button
v-if="mode === 'graph'" v-if="mode !== 'pivot'"
ref="viewNodeOrEdgeBtn" ref="viewNodeOrEdgeBtn"
tooltip="View details" tooltip="View details"
tooltipPosition="top-left" tooltipPosition="top-left"

View File

@@ -125,6 +125,13 @@ export default {
}, },
async checkFile(file) { async checkFile(file) {
if (!file) {
alert(
'You should drop a file. ' +
'It can be an SQLite database, CSV file, JSON or NDJSON file.'
)
return
}
this.state = 'dropping' this.state = 'dropping'
this.newDb = database.getNewDatabase() this.newDb = database.getNewDatabase()

View File

@@ -227,7 +227,7 @@ export default {
events.send(eventName) events.send(eventName)
}, },
_keyListener(e) { _keyListener(e) {
if (this.$route.path === '/workspace') { if (this.$route.path === '/workspace' && this.currentInquiryTab) {
// Run query Ctrl+R or Ctrl+Enter // Run query Ctrl+R or Ctrl+Enter
if ((e.key === 'r' || e.key === 'Enter') && (e.ctrlKey || e.metaKey)) { if ((e.key === 'r' || e.key === 'Enter') && (e.ctrlKey || e.metaKey)) {
e.preventDefault() e.preventDefault()

View File

@@ -13,6 +13,27 @@ export function getOptionsFromDataSources(dataSources) {
})) }))
} }
export function getRowsByIndexFromDataSources(dataSources, rowIndexes) {
if (!dataSources) {
return []
}
const dataSourceColumns = Object.keys(dataSources)
return rowIndexes.map(rowIndex =>
dataSourceColumns.reduce((result, columnName) => {
result[columnName] = dataSources[columnName][rowIndex]
return result
}, {})
)
}
export function clearSelection(data, layout) {
if (layout?.selections?.length > 0) {
layout.selections = []
data.forEach(dataItem => delete dataItem.selectedpoints)
}
}
export function getOptionsForSave(state, dataSources) { export function getOptionsForSave(state, dataSources) {
// we don't need to save the data, only settings // we don't need to save the data, only settings
// so we modify state.data using dereference // so we modify state.data using dereference
@@ -22,6 +43,9 @@ export function getOptionsForSave(state, dataSources) {
emptySources[key] = [] emptySources[key] = []
} }
dereference.default(stateCopy.data, emptySources) dereference.default(stateCopy.data, emptySources)
// Also, we don't need to save selections
clearSelection(stateCopy.data, stateCopy.layout)
return stateCopy return stateCopy
} }
@@ -72,5 +96,7 @@ export default {
getOptionsForSave, getOptionsForSave,
getImageDataUrl, getImageDataUrl,
getHtml, getHtml,
getChartData getChartData,
getRowsByIndexFromDataSources,
clearSelection
} }

View File

@@ -1,3 +1,5 @@
import { clearSelection } from '@/lib/chartHelper'
export default { export default {
_migrate(installedVersion, inquiries) { _migrate(installedVersion, inquiries) {
if (installedVersion < 2) { if (installedVersion < 2) {
@@ -28,6 +30,14 @@ export default {
}) })
} }
if (installedVersion < 5) {
inquiries.forEach(inquiry => {
if (inquiry.viewType === 'chart') {
clearSelection(inquiry.viewOptions.data, inquiry.viewOptions.layout)
}
})
}
return inquiries return inquiries
} }
} }

View File

@@ -5,7 +5,7 @@ import migration from './_migrations'
const migrate = migration._migrate const migrate = migration._migrate
const myInquiriesKey = 'myInquiries' const myInquiriesKey = 'myInquiries'
const latestVersion = 4 const latestVersion = 5
export default { export default {
version: latestVersion, version: latestVersion,