diff --git a/core/frontend/src/components/canvas/utils/utils.js b/core/frontend/src/components/canvas/utils/utils.js index d5f8e38d5c..b095245901 100644 --- a/core/frontend/src/components/canvas/utils/utils.js +++ b/core/frontend/src/components/canvas/utils/utils.js @@ -508,18 +508,28 @@ export function exportExcelDownload(chart, snapshot, width, height, loadingWrapp }) }) } - if (chart.render === 'echarts' && chart.type === 'table-normal') { + if (chart.type === 'table-normal') { const initTotal = fields.map(i => [2, 3].includes(i.deType) ? 0 : undefined) initTotal[0] = '合计' - tableRow.reduce((p, n) => { - p.forEach((v, i) => { - if (!isNaN(v)) { - p[i] = v + n[excelHeaderKeys[i]] - } - }) - return p - }, initTotal) - excelData.push(initTotal) + let exportSum = true + if (chart.render === 'antv') { + const { size } = JSON.parse(chart.customAttr) + initTotal[0] = size.summaryLabel + if (size.showSummary === false) { + exportSum = false + } + } + if (exportSum) { + tableRow.reduce((p, n) => { + p.forEach((v, i) => { + if (!isNaN(v)) { + p[i] = v + n[excelHeaderKeys[i]] + } + }) + return p + }, initTotal) + excelData.push(initTotal) + } } const request = { proxy: null, diff --git a/core/frontend/src/lang/en.js b/core/frontend/src/lang/en.js index dc94d92875..4ee3d2d25c 100644 --- a/core/frontend/src/lang/en.js +++ b/core/frontend/src/lang/en.js @@ -1839,7 +1839,9 @@ export default { forecast_model: 'Forecast model', forecast_degree: 'Degree', linear_regression: 'Linear regression', - polynomial_regression: 'Polynomial regression' + polynomial_regression: 'Polynomial regression', + show_summary: 'Show summary', + summary_label: 'Summary label' }, dataset: { scope_edit: 'Effective only when editing', diff --git a/core/frontend/src/lang/tw.js b/core/frontend/src/lang/tw.js index d3cf2b9264..485141a1db 100644 --- a/core/frontend/src/lang/tw.js +++ b/core/frontend/src/lang/tw.js @@ -1832,7 +1832,9 @@ export default { forecast_model: '預測模型', forecast_degree: '階數', linear_regression: '線性回歸', - polynomial_regression: '多項式擬合' + polynomial_regression: '多項式擬合', + show_summary: '顯示總計', + summary_label: '總計標籤' }, dataset: { scope_edit: '僅編輯時生效', diff --git a/core/frontend/src/lang/zh.js b/core/frontend/src/lang/zh.js index 326b5d7f1c..c69cd4b868 100644 --- a/core/frontend/src/lang/zh.js +++ b/core/frontend/src/lang/zh.js @@ -1829,7 +1829,9 @@ export default { forecast_model: '预测模型', forecast_degree: '阶数', linear_regression: '线性回归', - polynomial_regression: '多项式拟合' + polynomial_regression: '多项式拟合', + show_summary: '显示总计', + summary_label: '总计标签' }, dataset: { goto: ', 前往 ', diff --git a/core/frontend/src/views/chart/chart/chart.js b/core/frontend/src/views/chart/chart/chart.js index 14a37c8766..1d5cd5e9e0 100644 --- a/core/frontend/src/views/chart/chart/chart.js +++ b/core/frontend/src/views/chart/chart/chart.js @@ -185,7 +185,9 @@ export const DEFAULT_SIZE = { tableColumnFreezeHead: 0, tableColumnFreezeTail: 0, tableRowFreezeHead: 0, - tableHeaderSort: false + tableHeaderSort: false, + showSummary: false, + summaryLabel: '总计' } export const DEFAULT_SUSPENSION = { show: true diff --git a/core/frontend/src/views/chart/chart/table/table-info.js b/core/frontend/src/views/chart/chart/table/table-info.js index a2741f2e79..d25229c4ef 100644 --- a/core/frontend/src/views/chart/chart/table/table-info.js +++ b/core/frontend/src/views/chart/chart/table/table-info.js @@ -9,7 +9,8 @@ import { getAutoAdjustPosition, getTooltipDefaultOptions, setTooltipContainerStyle, - SERIES_NUMBER_FIELD + SERIES_NUMBER_FIELD, + TableDataCell } from '@antv/s2' import { getCustomTheme, getSize } from '@/views/chart/chart/common/common_table' import { DEFAULT_COLOR_CASE, DEFAULT_TOTAL } from '@/views/chart/chart/chart' @@ -77,6 +78,15 @@ class SortTooltip extends BaseTooltip { }) } } +class SummaryCell extends TableDataCell { + getTextStyle() { + return this.theme.colCell.bolderText + } + getBackgroundColor() { + const { backgroundColor, backgroundColorOpacity } = this.theme.colCell.cell + return { backgroundColor, backgroundColorOpacity } + } +} export function baseTableInfo(container, chart, action, tableData, pageInfo, vueCom, resizeFunc) { const containerDom = document.getElementById(container) @@ -418,6 +428,34 @@ export function baseTableNormal(container, chart, action, tableData, vueCom, res node.label = ' ' } } + // 总计 + if (customAttr.size.showSummary) { + // 设置汇总行高度和表头一致 + const heightByField = {} + heightByField[newData.length] = customAttr.size.tableTitleHeight + s2Options.style.rowCfg = { heightByField } + // 计算汇总加入到数据里,冻结最后一行 + const xAxis = JSON.parse(chart.xaxis) + const yAxis = JSON.parse(chart.yaxis) + s2Options.frozenTrailingRowCount = 1 + const summaryObj = yAxis.length > 0 ? newData.reduce((p, n) => { + yAxis.forEach(axis => { + p[axis.dataeaseName] = (n[axis.dataeaseName] || 0) + (p[axis.dataeaseName] || 0) + }) + return p + }, { SUMMARY: true }) : {} + newData.push(summaryObj) + s2Options.dataCell = viewMeta => { + if (viewMeta.rowIndex === newData.length - 1) { + if (viewMeta.colIndex === 0 && xAxis.length !== 0) { + viewMeta.fieldValue = customAttr.size.summaryLabel ?? '总计' + viewMeta.summaryLabel = viewMeta.fieldValue + } + return new SummaryCell(viewMeta, viewMeta.spreadsheet) + } + return new TableDataCell(viewMeta, viewMeta.spreadsheet) + } + } // 开始渲染 const s2 = new TableSheet(containerDom, s2DataConfig, s2Options) @@ -1006,7 +1044,13 @@ function showTooltipValue(s2Instance, event, meta) { if (!cellMeta.data) { return } - const value = cellMeta.data[valueField] + let value = cellMeta.data[valueField] + if (cellMeta.summaryLabel) { + value = cellMeta.fieldValue + } + if (!value) { + return + } const metaObj = find(meta, m => m.field === valueField ) diff --git a/core/frontend/src/views/chart/chart/util.js b/core/frontend/src/views/chart/chart/util.js index 5a3fecfd66..61b94354c4 100644 --- a/core/frontend/src/views/chart/chart/util.js +++ b/core/frontend/src/views/chart/chart/util.js @@ -69,7 +69,9 @@ export const TYPE_CONFIGS = [ 'tableColTooltip', 'tableCellTooltip', 'showTableHeader', - 'tableHeaderSort' + 'tableHeaderSort', + 'showSummary', + 'summaryLabel' ], 'title-selector-ant-v': [ 'show', diff --git a/core/frontend/src/views/chart/components/ChartComponentS2.vue b/core/frontend/src/views/chart/components/ChartComponentS2.vue index 99459d4c49..f872da4437 100644 --- a/core/frontend/src/views/chart/components/ChartComponentS2.vue +++ b/core/frontend/src/views/chart/components/ChartComponentS2.vue @@ -336,6 +336,10 @@ export default { } else { rowData = this.myChart.dataSet.getRowData(meta) } + // 忽略汇总表总计行 + if (rowData.SUMMARY) { + return + } const dimensionList = [] for (const key in rowData) { if (nameIdMap[key]) { diff --git a/core/frontend/src/views/chart/components/shapeAttr/SizeSelectorAntV.vue b/core/frontend/src/views/chart/components/shapeAttr/SizeSelectorAntV.vue index f92b2ba04c..1970d124da 100644 --- a/core/frontend/src/views/chart/components/shapeAttr/SizeSelectorAntV.vue +++ b/core/frontend/src/views/chart/components/shapeAttr/SizeSelectorAntV.vue @@ -16,7 +16,8 @@ {{ $t('chart.adapt') }} + >{{ $t('chart.adapt') }} + @@ -44,11 +45,11 @@ > @@ -77,11 +78,11 @@ > @@ -106,11 +107,11 @@ > @@ -121,11 +122,11 @@ > @@ -152,11 +153,11 @@ > @@ -205,11 +206,11 @@ > @@ -290,32 +291,28 @@ @@ -328,14 +325,14 @@ @@ -351,8 +348,8 @@ {{ $t('dynamic_time.before') }} @@ -361,8 +358,8 @@ {{ $t('dynamic_time.before') }} @@ -475,11 +472,11 @@ > @@ -503,13 +500,35 @@ @change="changeBarSizeCase('tableColTooltip')" /> + + + + + + {{ $t('chart.chart_bar') }} {{ $t('chart.chart_line') }} @@ -577,11 +596,11 @@ > @@ -596,8 +615,8 @@ {{ $t('chart.chart_scatter') }} @@ -685,23 +704,23 @@ {{ item.name }} @@ -715,49 +734,49 @@ @@ -804,23 +823,23 @@ {{ item.name }} @@ -834,49 +853,49 @@ @@ -889,11 +908,11 @@ > @@ -904,11 +923,11 @@ > @@ -989,11 +1008,13 @@ {{ $t('chart.italic') }} + >{{ $t('chart.italic') }} + {{ $t('chart.bolder') }} + >{{ $t('chart.bolder') }} + {{ $t('chart.font_shadow') }} + >{{ $t('chart.font_shadow') }} + {{ $t('chart.p_left') }} + value="start" + >{{ $t('chart.p_left') }} + {{ $t('chart.p_center') }} + value="center" + >{{ $t('chart.p_center') }} + {{ $t('chart.p_right') }} + value="end" + >{{ $t('chart.p_right') }} + {{ $t('chart.p_top') }} + value="start" + >{{ $t('chart.p_top') }} + {{ $t('chart.p_center') }} + value="center" + >{{ $t('chart.p_center') }} + {{ $t('chart.p_bottom') }} + value="end" + >{{ $t('chart.p_bottom') }} + @@ -1126,11 +1154,13 @@ {{ $t('chart.italic') }} + >{{ $t('chart.italic') }} + {{ $t('chart.bolder') }} + >{{ $t('chart.bolder') }} + {{ $t('chart.font_shadow') }} + >{{ $t('chart.font_shadow') }} + {{ $t('chart.show') }} + >{{ $t('chart.show') }} +
{{ $t('chart.italic') }} + >{{ $t('chart.italic') }} + {{ $t('chart.bolder') }} + >{{ $t('chart.bolder') }} + {{ $t('chart.font_shadow') }} + >{{ $t('chart.font_shadow') }} + @@ -1361,23 +1396,23 @@ {{ item.name }} @@ -1391,49 +1426,49 @@ @@ -1445,11 +1480,11 @@ > @@ -1461,11 +1496,11 @@ > @@ -1477,11 +1512,11 @@ > @@ -1500,8 +1535,8 @@ > @@ -1517,9 +1552,9 @@ @@ -1530,8 +1565,8 @@ > @@ -1554,8 +1589,8 @@ > @@ -1566,8 +1601,8 @@ > @@ -1579,8 +1614,8 @@ > @@ -1593,8 +1628,8 @@ > @@ -1606,11 +1641,11 @@ > @@ -1797,6 +1832,7 @@ export default { this.sizeForm.tableColumnFreezeHead = this.sizeForm.tableColumnFreezeHead ?? DEFAULT_SIZE.tableColumnFreezeHead this.sizeForm.tableColumnFreezeTail = this.sizeForm.tableColumnFreezeTail ?? DEFAULT_SIZE.tableColumnFreezeTail this.sizeForm.tableRowFreezeHead = this.sizeForm.tableRowFreezeHead ?? DEFAULT_SIZE.tableRowFreezeHead + this.sizeForm.summaryLabel = this.sizeForm.summaryLabel ?? DEFAULT_SIZE.summaryLabel this.sizeForm.showIndex = this.sizeForm.showIndex ? this.sizeForm.showIndex : DEFAULT_SIZE.showIndex this.sizeForm.showTableHeader = this.sizeForm.showTableHeader !== false @@ -2069,71 +2105,75 @@ export default { diff --git a/core/frontend/src/views/chart/components/table/TableTooltip.vue b/core/frontend/src/views/chart/components/table/TableTooltip.vue index f07028dfa0..9b847b72c6 100644 --- a/core/frontend/src/views/chart/components/table/TableTooltip.vue +++ b/core/frontend/src/views/chart/components/table/TableTooltip.vue @@ -25,6 +25,8 @@