From 038c5f7fdbadb80432fcd53b6f685e69546d6747 Mon Sep 17 00:00:00 2001 From: wisonic Date: Mon, 16 Dec 2024 16:56:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=80=8F=E8=A7=86=E8=A1=A8=E6=A0=91=E5=BD=A2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=9C=A8=E5=88=97=E7=BB=B4=E5=BA=A6=E4=B8=BA=E7=A9=BA=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A1=8C?= =?UTF-8?q?=E6=80=BB=E8=AE=A1=E5=B0=8F=E8=AE=A1=E6=97=A0=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/table/table-pivot.ts | 161 +++++++++++++++--- 1 file changed, 140 insertions(+), 21 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts index d60c3e467a..c4b095c5cc 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts @@ -560,7 +560,7 @@ function customCalcFunc(query, data, status, chart, totalCfgMap, axisMap, custom } } -function getCustomCalcResult(query, axisMap, chart: ChartObj, status: TotalStatus, customCalc) { +function getTreeCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { const quotaField = query[EXTRA_FIELD] const { row, col } = axisMap // 行列交叉总计 @@ -570,26 +570,18 @@ function getCustomCalcResult(query, axisMap, chart: ChartObj, status: TotalStatu // 列总计 if (status.isColTotal && !status.isRowSubTotal) { const { colTotal, rowSubInColTotal } = customCalc - const { tableLayoutMode } = chart.customAttr.basicStyle const path = getTreePath(query, row) let val if (path.length) { - if (tableLayoutMode === 'grid' && colTotal) { + const subLevel = getSubLevel(query, row) + if (subLevel + 1 === row.length && colTotal) { path.push(quotaField) val = get(colTotal.data, path) } - // 树形模式的行小计放在列总计里面 - if (tableLayoutMode === 'tree') { - const subLevel = getSubLevel(query, row) - if (subLevel + 1 === row.length && colTotal) { - path.push(quotaField) - val = get(colTotal.data, path) - } - if (subLevel + 1 < row.length && rowSubInColTotal) { - const data = rowSubInColTotal?.[subLevel]?.data - path.push(quotaField) - val = get(data, path) - } + if (subLevel + 1 < row.length && rowSubInColTotal) { + const data = rowSubInColTotal?.[subLevel]?.data + path.push(quotaField) + val = get(data, path) } } return val @@ -614,13 +606,133 @@ function getCustomCalcResult(query, axisMap, chart: ChartObj, status: TotalStatu const { rowTotal } = customCalc const path = getTreePath(query, col) let val - if (path.length && rowTotal) { - path.push(quotaField) - val = get(rowTotal.data, path) + if (rowTotal) { + if (path.length) { + path.push(quotaField) + val = get(rowTotal.data, path) + } + // 列维度为空,行维度不为空 + if (!col.length && row.length) { + val = get(rowTotal.data, quotaField) + } } - // 列维度为空,行维度不为空 - if (!col.length && row.length) { - val = get(rowTotal.data, quotaField) + return val + } + // 行小计 + if (status.isRowSubTotal) { + // 列维度为空,行小计直接当成列总计 + if ( + (!status.isColTotal && !status.isColSubTotal) || + (!col.length && status.isColTotal && status.isRowSubTotal) + ) { + const { rowSubTotal } = customCalc + const rowLevel = getSubLevel(query, row) + const colPath = getTreePath(query, col) + const rowPath = getTreePath(query, row) + const path = [...colPath, ...rowPath] + const data = rowSubTotal?.[rowLevel]?.data + let val + if (path.length && rowSubTotal) { + path.push(quotaField) + val = get(data, path) + } + return val + } + } + // 行总计里面的列小计 + if (status.isRowTotal && status.isColSubTotal) { + const { colSubInRowTotal } = customCalc + const colLevel = getSubLevel(query, col) + const { data } = colSubInRowTotal?.[colLevel] + const colPath = getTreePath(query, col) + let val + if (colPath.length && colSubInRowTotal) { + colPath.push(quotaField) + val = get(data, colPath) + } + return val + } + // 列总计里面的行小计 + if (status.isColTotal && status.isRowSubTotal) { + const { rowSubInColTotal } = customCalc + const rowSubLevel = getSubLevel(query, row) + const data = rowSubInColTotal?.[rowSubLevel]?.data + const path = getTreePath(query, row) + let val + if (path.length && rowSubInColTotal) { + path.push(quotaField) + val = get(data, path) + } + return val + } + // 列小计里面的行小计 + if (status.isColSubTotal && status.isRowSubTotal) { + const { rowSubInColSub } = customCalc + const rowSubLevel = getSubLevel(query, row) + const colSubLevel = getSubLevel(query, col) + const data = rowSubInColSub?.[rowSubLevel]?.[colSubLevel]?.data + const rowPath = getTreePath(query, row) + const colPath = getTreePath(query, col) + const path = [...rowPath, ...colPath] + let val + if (path.length && rowSubInColSub) { + path.push(quotaField) + val = get(data, path) + } + return val + } + return NaN +} + +function getGridCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { + const quotaField = query[EXTRA_FIELD] + const { row, col } = axisMap + // 行列交叉总计 + if (status.isRowTotal && status.isColTotal) { + return customCalc.rowColTotal?.data?.[quotaField] + } + // 列总计 + if (status.isColTotal && !status.isRowSubTotal) { + const { colTotal } = customCalc + const path = getTreePath(query, row) + let val + if (path.length) { + if (colTotal) { + path.push(quotaField) + val = get(colTotal.data, path) + } + } + return val + } + // 列小计 + if (status.isColSubTotal && !status.isRowTotal && !status.isRowSubTotal) { + const { colSubTotal } = customCalc + const subLevel = getSubLevel(query, col) + const rowPath = getTreePath(query, row) + const colPath = getTreePath(query, col) + const path = [...rowPath, ...colPath] + const data = colSubTotal?.[subLevel]?.data + let val + if (path.length && data) { + path.push(quotaField) + val = get(data, path) + } + return val + } + // 行总计 + if (status.isRowTotal && !status.isColSubTotal) { + const { rowTotal } = customCalc + const path = getTreePath(query, col) + let val + if (rowTotal) { + if (path.length) { + path.push(quotaField) + val = get(rowTotal.data, path) + } + // 列维度为空,行维度不为空 + if (!col.length && row.length) { + val = get(rowTotal.data, quotaField) + } } return val } @@ -682,6 +794,13 @@ function getCustomCalcResult(query, axisMap, chart: ChartObj, status: TotalStatu return val } } +function getCustomCalcResult(query, axisMap, chart: ChartObj, status: TotalStatus, customCalc) { + const { tableLayoutMode } = chart.customAttr.basicStyle + if (tableLayoutMode === 'tree') { + return getTreeCustomCalcResult(query, axisMap, status, customCalc) + } + return getGridCustomCalcResult(query, axisMap, status, customCalc) +} function getSubLevel(query, axis) { const fields: [] = axis.map(a => a.dataeaseName)