diff --git a/frontend/src/views/chart/chart/common/common_table.js b/frontend/src/views/chart/chart/common/common_table.js index e38cbcf94a..81214b36a2 100644 --- a/frontend/src/views/chart/chart/common/common_table.js +++ b/frontend/src/views/chart/chart/common/common_table.js @@ -8,3 +8,30 @@ export function getCustomTheme(chart) { theme.background = background return theme } + +export function getSize(chart) { + const size = {} + let customAttr = {} + if (chart.customAttr) { + customAttr = JSON.parse(chart.customAttr) + // size + if (customAttr.size) { + const s = JSON.parse(JSON.stringify(customAttr.size)) + size.colCfg = { + height: s.tableTitleHeight + } + size.cellCfg = { + height: s.tableItemHeight + } + if (!s.tableColumnMode || s.tableColumnMode === 'adapt') { + delete size.cellCfg.width + size.layoutWidthType = 'compact' + } else { + delete size.layoutWidthType + size.cellCfg.width = s.tableColumnWidth + } + } + } + + return size +} diff --git a/frontend/src/views/chart/chart/table/table-info.js b/frontend/src/views/chart/chart/table/table-info.js index 15fce23ebf..080a4aaf33 100644 --- a/frontend/src/views/chart/chart/table/table-info.js +++ b/frontend/src/views/chart/chart/table/table-info.js @@ -1,5 +1,5 @@ import { TableSheet } from '@antv/s2' -import { getCustomTheme } from '@/views/chart/chart/common/common_table' +import { getCustomTheme, getSize } from '@/views/chart/chart/common/common_table' export function baseTableInfo(s2, container, chart, action, tableData) { const containerDom = document.getElementById(container) @@ -38,11 +38,60 @@ export function baseTableInfo(s2, container, chart, action, tableData) { width: containerDom.offsetWidth, height: containerDom.offsetHeight, // showSeriesNumber: true - style: { - cellCfg: { - width: 500 - } - } + style: getSize(chart) + } + + // 开始渲染 + if (s2) { + s2.destroy() + } + s2 = new TableSheet(containerDom, s2DataConfig, s2Options) + + // theme + const customTheme = getCustomTheme(chart) + s2.setThemeCfg({ theme: customTheme }) + + return s2 +} + +export function baseTableNormal(s2, container, chart, action, tableData) { + const containerDom = document.getElementById(container) + + // data + const fields = chart.data.fields + if (!fields || fields.length === 0) { + if (s2) { + s2.destroy() + } + return + } + + const columns = [] + const meta = [] + fields.forEach(ele => { + columns.push(ele.dataeaseName) + + meta.push({ + field: ele.dataeaseName, + name: ele.name + }) + }) + + // data config + const s2DataConfig = { + fields: { + columns: columns + }, + meta: meta, + data: tableData + } + + // options + const s2Options = { + width: containerDom.offsetWidth, + height: containerDom.offsetHeight, + // showSeriesNumber: true + style: getSize(chart) } // 开始渲染 diff --git a/frontend/src/views/chart/components/ChartComponentS2.vue b/frontend/src/views/chart/components/ChartComponentS2.vue index 4421891aaf..25e68cee82 100644 --- a/frontend/src/views/chart/components/ChartComponentS2.vue +++ b/frontend/src/views/chart/components/ChartComponentS2.vue @@ -5,7 +5,8 @@