MCPcopy Create free account
hub / github.com/dataease/SQLBot / checkIsPercent

Function checkIsPercent

g2-ssr/charts/utils.js:98–149  ·  view source on GitHub ↗
(valueAxes, data)

Source from the content-addressed store, hash-verified

96}
97
98function checkIsPercent(valueAxes, data) {
99 const result = {
100 isPercent: false,
101 data: [],
102 }
103
104 // 深拷贝原始数据
105 for (let i = 0; i < data.length; i++) {
106 result.data.push({ ...data[i] })
107 }
108
109 // 检查是否有任何一个轴包含百分比数据
110 for (const valueAxis of valueAxes) {
111 const notEmptyData = filter(
112 data,
113 (d) =>
114 d &&
115 d[valueAxis.value] !== null &&
116 d[valueAxis.value] !== undefined &&
117 d[valueAxis.value] !== '' &&
118 d[valueAxis.value] !== 0 &&
119 d[valueAxis.value] !== '0',
120 )
121
122 if (notEmptyData.length > 0) {
123 const v = notEmptyData[0][valueAxis.value] + ''
124 if (endsWith(v.trim(), '%')) {
125 result.isPercent = true
126 break // 找到一个百分比轴就结束检查
127 }
128 }
129 }
130
131 // 如果发现任何百分比轴,处理所有轴的所有百分比数据
132 if (result.isPercent) {
133 for (let i = 0; i < data.length; i++) {
134 for (const valueAxis of valueAxes) {
135 const value = data[i][valueAxis.value]
136 if (value !== null && value !== undefined && value !== '') {
137 const strValue = String(value).trim()
138 if (endsWith(strValue, '%')) {
139 const formatValue = replace(strValue, '%', '')
140 const numValue = Number(formatValue)
141 result.data[i][valueAxis.value] = isNaN(numValue) ? 0 : numValue
142 }
143 }
144 }
145 }
146 }
147
148 return result
149}
150
151module.exports = { checkIsPercent, formatNumber, getAxesWithFilter, processMultiQuotaData }

Callers 4

getLineOptionsFunction · 0.70
getPieOptionsFunction · 0.70
getBarOptionsFunction · 0.70
getColumnOptionsFunction · 0.70

Calls 3

filterFunction · 0.85
replaceFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected