1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2026-02-04 15:38:55 +08:00
This commit is contained in:
lana-k
2025-11-08 22:23:38 +01:00
parent d7db6a0f5d
commit 65c1c18fcb
6 changed files with 1305 additions and 31 deletions

View File

@@ -35,7 +35,12 @@
/> />
</Field> </Field>
<Field v-if="modelValue.sourceUsage === 'map_to'"> <Field
v-if="
modelValue.sourceUsage === 'map_to' ||
modelValue.type === 'calculated'
"
>
<ColorscalePicker <ColorscalePicker
:selected="modelValue.colorscale" :selected="modelValue.colorscale"
className="colorscale-picker" className="colorscale-picker"
@@ -46,7 +51,9 @@
</Field> </Field>
<Field <Field
v-if="modelValue.type !== 'constant' && modelValue.sourceUsage === 'map_to'" v-if="
modelValue.sourceUsage === 'map_to' || modelValue.type === 'calculated'
"
label="Color as" label="Color as"
> >
<RadioBlocks <RadioBlocks
@@ -57,7 +64,9 @@
</Field> </Field>
<Field <Field
v-if="modelValue.type !== 'constant' && modelValue.sourceUsage === 'map_to'" v-if="
modelValue.sourceUsage === 'map_to' || modelValue.type === 'calculated'
"
label="Colorscale direction" label="Colorscale direction"
> >
<RadioBlocks <RadioBlocks
@@ -126,7 +135,6 @@ export default {
}, },
calculated: { calculated: {
method: 'degree', method: 'degree',
sourceUsage: 'map_to',
colorscale: null, colorscale: null,
mode: 'continious', mode: 'continious',
colorscaleDirection: 'normal' colorscaleDirection: 'normal'

View File

@@ -47,8 +47,7 @@ export function buildNodes(graph, dataSources, options) {
nodes.forEach(node => { nodes.forEach(node => {
if (node[nodeId]) { if (node[nodeId]) {
graph.addNode(node[nodeId], { graph.addNode(node[nodeId], {
data: node, data: node
labelColor: options.style.nodes.label.color
}) })
} }
}) })
@@ -56,7 +55,7 @@ export function buildNodes(graph, dataSources, options) {
} }
export function buildEdges(graph, dataSources, options) { export function buildEdges(graph, dataSources, options) {
const docColumn = Object.keys(dataSources)[0] || 'doc' const docColumn = Object.keys(dataSources)[0]
const { objectType, edgeSource, edgeTarget } = options.structure const { objectType, edgeSource, edgeTarget } = options.structure
if (objectType && edgeSource && edgeTarget) { if (objectType && edgeSource && edgeTarget) {
@@ -69,8 +68,7 @@ export function buildEdges(graph, dataSources, options) {
const target = edge[edgeTarget] const target = edge[edgeTarget]
if (graph.hasNode(source) && graph.hasNode(target)) { if (graph.hasNode(source) && graph.hasNode(target)) {
graph.addEdge(source, target, { graph.addEdge(source, target, {
data: edge, data: edge
labelColor: options.style.edges.label.color
}) })
} }
}) })
@@ -261,7 +259,6 @@ function getColorMethod(
colorscale[index % colorscale.length] colorscale[index % colorscale.length]
]) ])
) )
return (attributes, nodeId) => { return (attributes, nodeId) => {
const category = sourceGetter(nodeId, attributes) const category = sourceGetter(nodeId, attributes)
attributes.color = colorMap[category] attributes.color = colorMap[category]
@@ -277,6 +274,7 @@ function getColorMethod(
const value = sourceGetter(nodeId, attributes) const value = sourceGetter(nodeId, attributes)
const normalizedValue = (value - min) / (max - min) const normalizedValue = (value - min) / (max - min)
if (isNaN(normalizedValue)) { if (isNaN(normalizedValue)) {
attributes.color = '#000000'
return return
} }
const exactMatch = normalizedColorscale.find( const exactMatch = normalizedColorscale.find(
@@ -288,9 +286,9 @@ function getColorMethod(
} }
const rightColorIndex = normalizedColorscale.findIndex( const rightColorIndex = normalizedColorscale.findIndex(
([value]) => value >= normalizedValue ([value]) => value > normalizedValue
) )
const leftColorIndex = (rightColorIndex || 1) - 1 const leftColorIndex = rightColorIndex - 1
const right = normalizedColorscale[rightColorIndex] const right = normalizedColorscale[rightColorIndex]
const left = normalizedColorscale[leftColorIndex] const left = normalizedColorscale[leftColorIndex]
const interpolationFactor = const interpolationFactor =
@@ -327,18 +325,3 @@ function getEdgeValueScale(graph, sourceGetter) {
}, new Set()) }, new Set())
return Array.from(scaleSet).sort((a, b) => a - b) return Array.from(scaleSet).sort((a, b) => a - b)
} }
export function getOptionsFromDataSources(dataSources) {
if (!dataSources) {
return []
}
return Object.keys(dataSources).map(name => ({
value: name,
label: name
}))
}
export default {
getOptionsFromDataSources
}

View File

@@ -31,7 +31,7 @@ import fIo from '@/lib/utils/fileIo'
import $ from 'jquery' import $ from 'jquery'
import 'pivottable' import 'pivottable'
import 'pivottable/dist/pivot.css' import 'pivottable/dist/pivot.css'
import PivotUi from './PivotUi' import PivotUi from './PivotUi/index.vue'
import pivotHelper from './pivotHelper' import pivotHelper from './pivotHelper'
import Chart from '@/views/MainView/Workspace/Tabs/Tab/DataView/Chart' import Chart from '@/views/MainView/Workspace/Tabs/Tab/DataView/Chart'
import chartHelper from '@/lib/chartHelper' import chartHelper from '@/lib/chartHelper'

File diff suppressed because it is too large Load Diff

View File

@@ -15,7 +15,6 @@ describe('Chart.vue', () => {
}) })
it('getOptionsForSave called with proper arguments', () => { it('getOptionsForSave called with proper arguments', () => {
// mount the component
const wrapper = mount(Chart, { const wrapper = mount(Chart, {
global: { global: {
mocks: { $store } mocks: { $store }
@@ -30,7 +29,6 @@ describe('Chart.vue', () => {
}) })
it('emits update when plotly updates', async () => { it('emits update when plotly updates', async () => {
// mount the component
const wrapper = mount(Chart, { const wrapper = mount(Chart, {
global: { global: {
mocks: { $store } mocks: { $store }
@@ -48,7 +46,6 @@ describe('Chart.vue', () => {
points: [80] points: [80]
} }
// mount the component
const wrapper = mount(Chart, { const wrapper = mount(Chart, {
props: { props: {
dataSources, dataSources,
@@ -208,4 +205,40 @@ describe('Chart.vue', () => {
expect(wrapper.find('.Select__menu').text()).to.contain('name' + 'points') expect(wrapper.find('.Select__menu').text()).to.contain('name' + 'points')
wrapper.unmount() wrapper.unmount()
}) })
it('hides and shows controls depending on showViewSettings and resizes the plot', async () => {
const wrapper = mount(Chart, {
attachTo: document.body,
props: {
dataSources: null
},
global: {
mocks: { $store }
}
})
// don't call flushPromises here, otherwize resize observer will be call to often
// which causes ResizeObserver loop completed with undelivered notifications.
await nextTick()
const plot = wrapper.find('.svg-container').wrapperElement
const initialPlotWidth = plot.scrollWidth
const initialPlotHeight = plot.scrollHeight
expect(wrapper.find('.plotly_editor .editor_controls').exists()).to.equal(
false
)
await wrapper.setProps({ showViewSettings: true })
await flushPromises()
expect(plot.scrollWidth).not.to.equal(initialPlotWidth)
expect(plot.scrollHeight).not.to.equal(initialPlotHeight)
expect(wrapper.find('.plotly_editor .editor_controls').exists()).to.equal(
true
)
wrapper.unmount()
})
}) })

View File

@@ -586,4 +586,48 @@ describe('Pivot.vue', () => {
wrapper.unmount() wrapper.unmount()
}) })
it('hides or shows controlls depending on showViewSettings and resizes standart chart', async () => {
const wrapper = mount(Pivot, {
global: {
mocks: { $store: { state: { isWorkspaceVisible: true } } }
},
props: {
dataSources: {
item: ['foo', 'bar', 'bar', 'bar'],
year: [2021, 2021, 2020, 2020]
},
initOptions: {
rows: ['item'],
cols: ['year'],
colOrder: 'key_a_to_z',
rowOrder: 'key_a_to_z',
aggregatorName: 'Count',
vals: [],
renderer: $.pivotUtilities.renderers['Bar Chart'],
rendererName: 'Bar Chart'
}
},
attachTo: container
})
expect(wrapper.find('.pivot-ui').isVisible()).to.equal(false)
await flushPromises()
const plot = wrapper.find('.svg-container').wrapperElement
const initialPlotHeight = plot.scrollHeight
await wrapper.setProps({ showViewSettings: true })
expect(wrapper.find('.pivot-ui').isVisible()).to.equal(true)
await flushPromises()
const plotAfterResize = wrapper.find('.svg-container').wrapperElement
expect(plotAfterResize.scrollWidth.scrollHeight).not.to.equal(
initialPlotHeight
)
wrapper.unmount()
})
}) })