Merge pull request #8476 from dataease/pr@dev-v2@feat_table_smooth_scroll

feat(图表): 表格支持平滑滚动 #7277
This commit is contained in:
wisonic-s 2024-03-13 15:45:44 +08:00 committed by GitHub
commit 902d21842c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -136,6 +136,7 @@ const renderChart = (viewInfo: Chart, resetPageInfo: boolean) => {
recursionTransObj(customStyleTrans, chart.customStyle, scale.value, terminal.value) recursionTransObj(customStyleTrans, chart.customStyle, scale.value, terminal.value)
setupPage(chart, resetPageInfo) setupPage(chart, resetPageInfo)
myChart?.facet.timer?.stop()
myChart?.destroy() myChart?.destroy()
const chartView = chartViewManager.getChartView( const chartView = chartViewManager.getChartView(
viewInfo.render, viewInfo.render,
@ -172,38 +173,44 @@ const setupPage = (chart: ChartObj, resetPageInfo?: boolean) => {
} }
} }
let scrollTimer: number
let scrollTop = 0
const initScroll = () => { const initScroll = () => {
clearInterval(scrollTimer)
// *toptop<* // *toptop<*
const customAttr = view.value.customAttr const customAttr = view.value.customAttr
const senior = view.value.senior const senior = view.value.senior
scrollTop = 0
if ( if (
senior?.scrollCfg?.open && senior?.scrollCfg?.open &&
(view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage)) (view.value.type === 'table-normal' || (view.value.type === 'table-info' && !state.showPage))
) { ) {
const rowHeight = customAttr.tableCell.tableItemHeight //
const headerHeight = customAttr.tableHeader.tableTitleHeight myChart.facet.timer?.stop()
const dom = document.getElementById(containerId) if (myChart.store.get('scrollY') !== 0) {
if (dom.offsetHeight > rowHeight * chartData.value.tableRow.length + headerHeight) { myChart.store.set('scrollY', 0)
myChart.render()
}
//
// 2 2 : = / 2 * 2
const offsetHeight = document.getElementById(containerId).offsetHeight
//
if (!offsetHeight) {
return return
} }
scrollTimer = setInterval(() => { const rowHeight = customAttr.tableCell.tableItemHeight
const offsetHeight = dom.offsetHeight const headerHeight = customAttr.tableHeader.tableTitleHeight
const top = rowHeight * senior.scrollCfg.row const scrollBarSize = myChart.theme.scrollBar.size
if (offsetHeight - headerHeight + scrollTop < rowHeight * chartData.value.tableRow.length) { const scrollHeight =
scrollTop += top rowHeight * chartData.value.tableRow.length + headerHeight - offsetHeight + scrollBarSize
} else { //
scrollTop = 0 if (scrollHeight < scrollBarSize) {
} return
myChart.store.set('scrollY', scrollTop) }
if (!offsetHeight) { const viewHeight = offsetHeight - headerHeight - scrollBarSize
return const scrollViewCount = chartData.value.tableRow.length - viewHeight / rowHeight
} const duration = (scrollViewCount / senior.scrollCfg.row) * senior.scrollCfg.interval
myChart.render() myChart.facet.scrollWithAnimation(
}, senior.scrollCfg.interval) { offsetY: { value: scrollHeight, animate: false } },
duration,
initScroll
)
} }
} }
@ -335,6 +342,7 @@ const resize = (width, height) => {
} }
timer = setTimeout(() => { timer = setTimeout(() => {
myChart?.changeSheetSize(width, height) myChart?.changeSheetSize(width, height)
myChart?.facet.timer?.stop()
myChart?.render() myChart?.render()
initScroll() initScroll()
}, 500) }, 500)
@ -363,9 +371,9 @@ onMounted(() => {
resizeObserver.observe(document.getElementById(containerId)) resizeObserver.observe(document.getElementById(containerId))
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
myChart?.facet.timer?.stop()
myChart?.destroy() myChart?.destroy()
resizeObserver?.disconnect() resizeObserver?.disconnect()
clearInterval(scrollTimer)
}) })
const autoStyle = computed(() => { const autoStyle = computed(() => {