NEZ-2068 feat: chart legend, value mapping 表达式统一
This commit is contained in:
@@ -150,7 +150,10 @@ export default {
|
||||
showValue: showValue,
|
||||
name: legend.name,
|
||||
alias: legend.alias,
|
||||
labels: data.metric,
|
||||
labels: {
|
||||
...data.metric,
|
||||
legend: legend.alias
|
||||
},
|
||||
seriesIndex: expressionIndex,
|
||||
dataIndex: dataIndex,
|
||||
mapping: mapping,
|
||||
|
||||
@@ -93,7 +93,10 @@ export default {
|
||||
showValue: showValue,
|
||||
name: legend.name,
|
||||
alias: legend.alias,
|
||||
labels: data.metric,
|
||||
labels: {
|
||||
...data.metric,
|
||||
legend: legend.alias
|
||||
},
|
||||
seriesIndex: expressionIndex,
|
||||
dataIndex: dataIndex,
|
||||
mapping: mapping,
|
||||
|
||||
@@ -89,6 +89,7 @@ export default {
|
||||
}
|
||||
gauge.label = data.metric
|
||||
gauge.legend = legend.alias
|
||||
gauge.label.legend = gauge.legend
|
||||
gauge.name = legend.name
|
||||
gauge.alias = legend.alias
|
||||
gauge.showValue = chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(gauge.value, null, -1, decimals)
|
||||
|
||||
@@ -100,6 +100,7 @@ export default {
|
||||
}
|
||||
Hexagon.label = data.metric
|
||||
Hexagon.legend = legend.alias
|
||||
Hexagon.label.legend = Hexagon.legend
|
||||
Hexagon.name = legend.name
|
||||
Hexagon.alias = legend.alias
|
||||
Hexagon.showValue = chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(Hexagon.value, null, -1, decimals)
|
||||
@@ -251,10 +252,10 @@ export default {
|
||||
const textColor = point.mapping ? point.mapping.color.text : this.invertColor(color)
|
||||
if (this.chartInfo.param.text === 'all') {
|
||||
str += point.alias
|
||||
valueStr = point.mapping && point.mapping.display ? self.handleDisplay(point.mapping.display, { ...point.metrics, value: point.showValue }) : point.showValue
|
||||
valueStr = point.mapping && point.mapping.display ? self.handleDisplay(point.mapping.display, { ...point.metrics, legend: point.alias, value: point.showValue }) : point.showValue
|
||||
}
|
||||
if (this.chartInfo.param.text === 'value' || !this.chartInfo.param.text) {
|
||||
valueStr = point.mapping && point.mapping.display ? self.handleDisplay(point.mapping.display, { ...point.metrics, value: point.showValue }) : point.showValue
|
||||
valueStr = point.mapping && point.mapping.display ? self.handleDisplay(point.mapping.display, { ...point.metrics, legend: point.alias, value: point.showValue }) : point.showValue
|
||||
}
|
||||
if (this.chartInfo.param.text === 'legend') {
|
||||
str += point.alias
|
||||
|
||||
@@ -134,6 +134,7 @@ export default {
|
||||
stat.value = getMetricTypeValue(data.values, chartInfo.param.statistics)
|
||||
stat.label = data.metric
|
||||
stat.legend = this.handleLegend(chartInfo, data, expressionIndex, dataIndex, colorIndex).alias
|
||||
stat.label.legend = stat.legend
|
||||
stat.name = this.handleLegend(chartInfo, data, expressionIndex, dataIndex, colorIndex).name
|
||||
stat.showValue = chartDataFormat.getUnit(chartInfo.unit ? chartInfo.unit : 2).compute(stat.value, null, -1, decimals)
|
||||
stat.mapping = this.selectMapping(stat.value, chartInfo.param.valueMapping, chartInfo.param.enable && this.chartInfo.param.enable.valueMapping)
|
||||
|
||||
@@ -30,14 +30,20 @@ export default {
|
||||
return str
|
||||
},
|
||||
handleDisplay (display, params) {
|
||||
const self = this
|
||||
const myParams = JSON.parse(JSON.stringify(params))
|
||||
myParams.$labels = JSON.parse(JSON.stringify(params))
|
||||
myParams.$value = myParams.value
|
||||
myParams.$legend = myParams.legend
|
||||
if (/\{\{.+\}\}/.test(display)) {
|
||||
const labelValue = display.replace(/(\{\{.+?\}\})/g, function (i) {
|
||||
const label = i.substr(i.indexOf('{{') + 2, i.indexOf('}}') - i.indexOf('{{') - 2)
|
||||
let value = null
|
||||
if (params[label]) {
|
||||
value = params[label]
|
||||
if (self.$loadsh.get(myParams, label)) {
|
||||
value = self.$loadsh.get(myParams, label)
|
||||
}
|
||||
return value || label
|
||||
// return value || label
|
||||
return value || ''
|
||||
})
|
||||
return labelValue
|
||||
} else {
|
||||
|
||||
@@ -150,7 +150,7 @@ export default {
|
||||
// 处理legend别名
|
||||
if (chartInfo.elements) {
|
||||
if (chartInfo.elements[expressionIndex]) {
|
||||
alias = alias + this.handleLegendAlias(legend, chartInfo.elements[expressionIndex].legend)
|
||||
alias = alias + this.handleLegendAlias(legend, chartInfo.elements[expressionIndex].legend, tagKeysArr)
|
||||
}
|
||||
if (!alias) {
|
||||
alias = chartInfo.elements[expressionIndex].expression || ''
|
||||
@@ -181,18 +181,27 @@ export default {
|
||||
alias
|
||||
}
|
||||
},
|
||||
handleLegendAlias (legend, aliasExpression) {
|
||||
handleLegendAlias (legend, aliasExpression, params) {
|
||||
const self = this
|
||||
const myParams = JSON.parse(JSON.stringify(params))
|
||||
myParams.$labels = JSON.parse(JSON.stringify(params))
|
||||
myParams.$value = myParams.value
|
||||
if (/\{\{.+\}\}/.test(aliasExpression)) {
|
||||
const labelValue = aliasExpression.replace(/(\{\{.+?\}\})/g, function (i) {
|
||||
const label = i.substr(i.indexOf('{{') + 2, i.indexOf('}}') - i.indexOf('{{') - 2)
|
||||
if (!legend) {
|
||||
return label
|
||||
}
|
||||
const reg = new RegExp(label + '=".+?"')
|
||||
let value = null
|
||||
if (reg.test(legend)) {
|
||||
const find = legend.match(reg)[0]
|
||||
value = find.substr(find.indexOf('"') + 1, find.lastIndexOf('"') - find.indexOf('"') - 1)
|
||||
if (params && self.$loadsh.get(myParams, label)) {
|
||||
value = self.$loadsh.get(myParams, label)
|
||||
}
|
||||
if (label) {
|
||||
const reg = new RegExp(label + '=".+?"')
|
||||
if (reg.test(legend)) {
|
||||
const find = legend.match(reg)[0]
|
||||
value = find.substr(find.indexOf('"') + 1, find.lastIndexOf('"') - find.indexOf('"') - 1)
|
||||
}
|
||||
}
|
||||
return value || ''
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user