feat: s2表格支持指标数值格式
This commit is contained in:
parent
c15dbf5f14
commit
715d1230c7
@ -1,6 +1,7 @@
|
||||
import { TableSheet, S2Event, PivotSheet } from '@antv/s2'
|
||||
import { getCustomTheme, getSize } from '@/views/chart/chart/common/common_table'
|
||||
import { DEFAULT_TOTAL } from '@/views/chart/chart/chart'
|
||||
import { formatterItem, valueFormatter } from '@/views/chart/chart/formatter'
|
||||
|
||||
export function baseTableInfo(s2, container, chart, action, tableData) {
|
||||
const containerDom = document.getElementById(container)
|
||||
@ -49,20 +50,50 @@ export function baseTableInfo(s2, container, chart, action, tableData) {
|
||||
name: drillField.name
|
||||
})
|
||||
} else {
|
||||
const f = getCurrentField(chart.xaxis, ele)
|
||||
columns.push(ele.dataeaseName)
|
||||
meta.push({
|
||||
field: ele.dataeaseName,
|
||||
name: ele.name
|
||||
name: ele.name,
|
||||
formatter: function(value) {
|
||||
if (!f) {
|
||||
return value
|
||||
}
|
||||
if (f.groupType === 'd') {
|
||||
return value
|
||||
} else {
|
||||
if (f.formatterCfg) {
|
||||
return valueFormatter(value, f.formatterCfg)
|
||||
} else {
|
||||
return valueFormatter(value, formatterItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
fields.forEach(ele => {
|
||||
const f = getCurrentField(chart.xaxis, ele)
|
||||
columns.push(ele.dataeaseName)
|
||||
meta.push({
|
||||
field: ele.dataeaseName,
|
||||
name: ele.name
|
||||
name: ele.name,
|
||||
formatter: function(value) {
|
||||
if (!f) {
|
||||
return value
|
||||
}
|
||||
if (f.groupType === 'd') {
|
||||
return value
|
||||
} else {
|
||||
if (f.formatterCfg) {
|
||||
return valueFormatter(value, f.formatterCfg)
|
||||
} else {
|
||||
return valueFormatter(value, formatterItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -146,20 +177,42 @@ export function baseTableNormal(s2, container, chart, action, tableData) {
|
||||
name: drillField.name
|
||||
})
|
||||
} else {
|
||||
const f = getCurrentField(chart.yaxis, ele)
|
||||
columns.push(ele.dataeaseName)
|
||||
meta.push({
|
||||
field: ele.dataeaseName,
|
||||
name: ele.name
|
||||
name: ele.name,
|
||||
formatter: function(value) {
|
||||
if (!f) {
|
||||
return value
|
||||
}
|
||||
if (f.formatterCfg) {
|
||||
return valueFormatter(value, f.formatterCfg)
|
||||
} else {
|
||||
return valueFormatter(value, formatterItem)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
fields.forEach(ele => {
|
||||
const f = getCurrentField(chart.yaxis, ele)
|
||||
columns.push(ele.dataeaseName)
|
||||
meta.push({
|
||||
field: ele.dataeaseName,
|
||||
name: ele.name
|
||||
name: ele.name,
|
||||
formatter: function(value) {
|
||||
if (!f) {
|
||||
return value
|
||||
}
|
||||
if (f.formatterCfg) {
|
||||
return valueFormatter(value, f.formatterCfg)
|
||||
} else {
|
||||
return valueFormatter(value, formatterItem)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -253,20 +306,42 @@ export function baseTablePivot(s2, container, chart, action, tableData) {
|
||||
name: drillField.name
|
||||
})
|
||||
} else {
|
||||
const f = getCurrentField(chart.yaxis, ele)
|
||||
columns.push(ele.dataeaseName)
|
||||
meta.push({
|
||||
field: ele.dataeaseName,
|
||||
name: ele.name
|
||||
name: ele.name,
|
||||
formatter: function(value) {
|
||||
if (!f) {
|
||||
return value
|
||||
}
|
||||
if (f.formatterCfg) {
|
||||
return valueFormatter(value, f.formatterCfg)
|
||||
} else {
|
||||
return valueFormatter(value, formatterItem)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
fields.forEach(ele => {
|
||||
const f = getCurrentField(chart.yaxis, ele)
|
||||
columns.push(ele.dataeaseName)
|
||||
meta.push({
|
||||
field: ele.dataeaseName,
|
||||
name: ele.name
|
||||
name: ele.name,
|
||||
formatter: function(value) {
|
||||
if (!f) {
|
||||
return value
|
||||
}
|
||||
if (f.formatterCfg) {
|
||||
return valueFormatter(value, f.formatterCfg)
|
||||
} else {
|
||||
return valueFormatter(value, formatterItem)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -324,3 +399,21 @@ export function baseTablePivot(s2, container, chart, action, tableData) {
|
||||
|
||||
return s2
|
||||
}
|
||||
|
||||
function getCurrentField(valueFieldList, field) {
|
||||
let list = []
|
||||
let res = null
|
||||
try {
|
||||
list = JSON.parse(valueFieldList)
|
||||
} catch (err) {
|
||||
list = JSON.parse(JSON.stringify(valueFieldList))
|
||||
}
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const f = list[i]
|
||||
if (field.dataeaseName === f.dataeaseName) {
|
||||
res = f
|
||||
break
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ export default {
|
||||
|
||||
valueFormatter() {
|
||||
this.item.index = this.index
|
||||
this.item.formatterType = 'quota'
|
||||
this.item.formatterType = 'dimension'
|
||||
this.$emit('valueFormatter', this.item)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2628,6 +2628,8 @@ export default {
|
||||
this.view.yaxis[this.valueFormatterItem.index].formatterCfg = this.valueFormatterItem.formatterCfg
|
||||
} else if (this.valueFormatterItem.formatterType === 'quotaExt') {
|
||||
this.view.yaxisExt[this.valueFormatterItem.index].formatterCfg = this.valueFormatterItem.formatterCfg
|
||||
} else if (this.valueFormatterItem.formatterType === 'dimension') {
|
||||
this.view.xaxis[this.valueFormatterItem.index].formatterCfg = this.valueFormatterItem.formatterCfg
|
||||
}
|
||||
this.calcData(true)
|
||||
this.closeValueFormatter()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user