forked from github/dataease
Merge pull request #12595 from dataease/pr@dev-v2@fix_pivot_tree_custom_col_calc
fix(图表): 透视表树形模式自定义汇总列总计显示错误 #12291
This commit is contained in:
commit
8bdf364c57
@ -232,7 +232,7 @@ export class TablePivot extends S2ChartView<PivotSheet> {
|
|||||||
return p
|
return p
|
||||||
}, {})
|
}, {})
|
||||||
total.calcFunc = (query, data, _, status) => {
|
total.calcFunc = (query, data, _, status) => {
|
||||||
return customCalcFunc(query, data, status, totalCfgMap, axisMap, customCalc)
|
return customCalcFunc(query, data, status, chart, totalCfgMap, axisMap, customCalc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -440,7 +440,7 @@ export class TablePivot extends S2ChartView<PivotSheet> {
|
|||||||
super('table-pivot', [])
|
super('table-pivot', [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function customCalcFunc(query, data, status, totalCfgMap, axisMap, customCalc) {
|
function customCalcFunc(query, data, status, chart, totalCfgMap, axisMap, customCalc) {
|
||||||
if (!data?.length || !query[EXTRA_FIELD]) {
|
if (!data?.length || !query[EXTRA_FIELD]) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -470,7 +470,7 @@ function customCalcFunc(query, data, status, totalCfgMap, axisMap, customCalc) {
|
|||||||
return result?.[query[EXTRA_FIELD]]
|
return result?.[query[EXTRA_FIELD]]
|
||||||
}
|
}
|
||||||
case 'CUSTOM': {
|
case 'CUSTOM': {
|
||||||
const val = getCustomCalcResult(query, axisMap, status, customCalc || {})
|
const val = getCustomCalcResult(query, axisMap, chart, status, customCalc || {})
|
||||||
if (val === '') {
|
if (val === '') {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
@ -484,7 +484,7 @@ function customCalcFunc(query, data, status, totalCfgMap, axisMap, customCalc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) {
|
function getCustomCalcResult(query, axisMap, chart: ChartObj, status: TotalStatus, customCalc) {
|
||||||
const quotaField = query[EXTRA_FIELD]
|
const quotaField = query[EXTRA_FIELD]
|
||||||
const { row, col } = axisMap
|
const { row, col } = axisMap
|
||||||
// 行列交叉总计
|
// 行列交叉总计
|
||||||
@ -493,12 +493,28 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) {
|
|||||||
}
|
}
|
||||||
// 列总计
|
// 列总计
|
||||||
if (status.isColTotal && !status.isRowSubTotal) {
|
if (status.isColTotal && !status.isRowSubTotal) {
|
||||||
const { colTotal } = customCalc
|
const { colTotal, rowSubInColTotal } = customCalc
|
||||||
|
const { tableLayoutMode } = chart.customAttr.basicStyle
|
||||||
const path = getTreePath(query, row)
|
const path = getTreePath(query, row)
|
||||||
let val
|
let val
|
||||||
if (path.length && colTotal) {
|
if (path.length) {
|
||||||
path.push(quotaField)
|
if (tableLayoutMode === 'grid' && colTotal) {
|
||||||
val = get(colTotal.data, path)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
@ -528,8 +544,7 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) {
|
|||||||
}
|
}
|
||||||
// 列维度为空,行维度不为空
|
// 列维度为空,行维度不为空
|
||||||
if (!col.length && row.length) {
|
if (!col.length && row.length) {
|
||||||
const path = [query[EXTRA_FIELD]]
|
val = get(rowTotal.data, quotaField)
|
||||||
val = get(rowTotal.data, path)
|
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user