diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts index eb339117be..ceda44174a 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts @@ -181,7 +181,7 @@ export class TableInfo extends S2ChartView { // options const s2Options: S2Options = { - width: containerDom.offsetWidth, + width: containerDom.getBoundingClientRect().width, height: containerDom.offsetHeight, seriesNumber: { enable: tableHeader.showIndex, @@ -297,7 +297,7 @@ export class TableInfo extends S2ChartView { const totalWidthWithImg = ev.colLeafNodes.reduce((p, n) => { return p + (urlFields.includes(n.field) ? 120 : n.width) }, 0) - const containerWidth = containerDom.offsetWidth + const containerWidth = containerDom.getBoundingClientRect().width - 1 if (containerWidth <= totalWidthWithImg) { // 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,但是需要处理非整数宽度值,不然会出现透明细线 ev.colLeafNodes.reduce((p, n) => { @@ -325,11 +325,11 @@ export class TableInfo extends S2ChartView { n.x = getStartPosition(n) } }) + const lastNode = ev.colLeafNodes[ev.colLeafNodes.length - 1] if (totalWidth > containerWidth) { - const lastNode = ev.colLeafNodes[ev.colLeafNodes.length - 1] lastNode.width = Math.floor(lastNode.width - (totalWidth - containerWidth)) } - ev.colsHierarchy.width = containerWidth - 2 + ev.colsHierarchy.width = lastNode.x + lastNode.width }) } // 空数据时表格样式 diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts index 3ce5571741..ef8ada4de1 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts @@ -140,7 +140,7 @@ export class TableNormal extends S2ChartView { const { basicStyle, tableCell, tableHeader, tooltip } = parseJson(chart.customAttr) // options const s2Options: S2Options = { - width: containerDom.offsetWidth, + width: containerDom.getBoundingClientRect().width, height: containerDom.offsetHeight, seriesNumber: { enable: tableHeader.showIndex, @@ -216,7 +216,7 @@ export class TableNormal extends S2ChartView { newChart.store.set('lastLayoutResult', undefined) return } - const containerWidth = containerDom.offsetWidth + const containerWidth = containerDom.getBoundingClientRect().width - 1 const scale = containerWidth / ev.colsHierarchy.width if (scale <= 1) { // 图库计算的布局宽度已经大于等于容器宽度,不需要再扩大,但是需要处理非整数宽度值,不然会出现透明细线 @@ -232,12 +232,12 @@ export class TableNormal extends S2ChartView { n.x = p return p + n.width }, 0) + // 从最后一列减掉 + const lastNode = ev.colLeafNodes[ev.colLeafNodes.length - 1] if (totalWidth > containerWidth) { - // 从最后一列减掉 - const lastNode = ev.colLeafNodes[ev.colLeafNodes.length - 1] lastNode.width = Math.floor(lastNode.width - (totalWidth - containerWidth)) } - ev.colsHierarchy.width = containerWidth - 1 + ev.colsHierarchy.width = lastNode.x + lastNode.width }) } configEmptyDataStyle(newChart, basicStyle, newData, container)