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

fix standart chart resize in pivot, improve performance

This commit is contained in:
lana-k
2025-04-03 22:36:50 +02:00
parent 77df3a8446
commit 3ee825defe
6 changed files with 115 additions and 22 deletions

View File

@@ -123,10 +123,8 @@ describe('Chart.vue', () => {
const newContainerWidth = initialContainerWidth * 2 || 1000
const newContainerHeight = initialContainerHeight * 2 || 2000
wrapper.find('.chart-container').wrapperElement.parentElement.style.width =
`${newContainerWidth}px`
wrapper.find('.chart-container').wrapperElement.parentElement.style.height =
`${newContainerHeight}px`
container.style.width = `${newContainerWidth}px`
container.style.height = `${newContainerHeight}px`
await flushPromises()
@@ -179,4 +177,34 @@ describe('Chart.vue', () => {
expect(fIo.downloadFromUrl.calledOnceWith(url, 'chart'))
wrapper.unmount()
})
it('dataSources are passed correctly', async () => {
const dataSources = {
name: ['Gryffindor'],
points: [80]
}
const wrapper = mount(Chart, {
attachTo: document.body,
props: {
dataSources
},
global: {
mocks: { $store }
}
})
await flushPromises()
await wrapper.find('button.js-add-button').wrapperElement.click()
await flushPromises()
await wrapper
.find('.field .dropdown-container .Select__indicator')
.wrapperElement.dispatchEvent(
new MouseEvent('mousedown', { bubbles: true })
)
expect(wrapper.find('.Select__menu').text()).to.contain('name' + 'points')
wrapper.unmount()
})
})

View File

@@ -1,5 +1,5 @@
import { expect } from 'chai'
import { mount } from '@vue/test-utils'
import { mount, flushPromises } from '@vue/test-utils'
import Pivot from '@/views/MainView/Workspace/Tabs/Tab/DataView/Pivot'
import chartHelper from '@/lib/chartHelper'
import fIo from '@/lib/utils/fileIo'
@@ -533,4 +533,57 @@ describe('Pivot.vue', () => {
fIo.downloadFromUrl.calledOnceWith('canvas data url', 'pivot')
).to.equal(true)
})
it('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
})
await flushPromises()
const plotContainer = wrapper.find('.pivot-output').wrapperElement
const plot = wrapper.find('.svg-container').wrapperElement
const initialContainerWidth = plotContainer.scrollWidth
const initialContainerHeight = plotContainer.scrollHeight
const initialPlotWidth = plot.scrollWidth
const initialPlotHeight = plot.scrollHeight
const newContainerWidth = initialContainerWidth * 2 || 1000
const newContainerHeight = initialContainerHeight * 2 || 2000
plotContainer.style.width = `${newContainerWidth}px`
plotContainer.style.height = `${newContainerHeight}px`
await flushPromises()
const plotAfterResize = wrapper.find('.svg-container').wrapperElement
expect(plotAfterResize.scrollWidth).not.to.equal(initialPlotWidth)
expect(plotAfterResize.scrollWidth.scrollHeight).not.to.equal(
initialPlotHeight
)
wrapper.unmount()
})
})