NEZ-3211 feat:legedn 以及 统计重构
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { initColor, Incrs } from '@/components/chart/chart/tools'
|
||||
import { randomcolor } from '@/components/common/js/radomcolor/randomcolor'
|
||||
import chartDataFormat from '@/components/chart/chartDataFormat'
|
||||
import lodash from "lodash";
|
||||
import {getMetricTypeValue} from "@/components/common/js/tools";
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
@@ -28,9 +30,18 @@ export default {
|
||||
time.forEach(item => {
|
||||
ObjTime[item] = undefined
|
||||
})
|
||||
chartData.forEach(series => { // 首先处理时间 对应点没有值(不包括null 则添加undefind)
|
||||
series.forEach(item => {
|
||||
chartData.forEach((series, expressionIndex) => { // 首先处理时间 对应点没有值(不包括null 则添加undefind)
|
||||
series.forEach((item, seriesIndex) => {
|
||||
let seriesObjTime = {}
|
||||
// 若需要统计,处理统计数据
|
||||
const statisticsTypes = this.chartInfo.param.legend ? this.chartInfo.param.legend.values : ''
|
||||
let statistics = []
|
||||
if (!lodash.isEmpty(statisticsTypes)) {
|
||||
statistics = statisticsTypes.map(type => {
|
||||
return { type, value: getMetricTypeValue(item.values, type) }
|
||||
})
|
||||
}
|
||||
item.statistics = statistics
|
||||
item.values.forEach(value => {
|
||||
seriesObjTime[value[0]] = value[1]
|
||||
})
|
||||
@@ -39,9 +50,8 @@ export default {
|
||||
...ObjTime,
|
||||
...seriesObjTime
|
||||
}
|
||||
console.log(seriesObjTime, seriesObjTime)
|
||||
seriesData.push(Object.keys(seriesObjTime).map(time => seriesObjTime[time]))
|
||||
seriesAll.push(this.renderSeries(item, chartIndex))
|
||||
seriesAll.push(this.renderSeries(item, expressionIndex, seriesIndex, chartIndex))
|
||||
chartIndex++
|
||||
})
|
||||
})
|
||||
@@ -51,25 +61,26 @@ export default {
|
||||
seriesAll
|
||||
}
|
||||
},
|
||||
renderSeries (series, chartIndex) {
|
||||
renderSeries (series, expressionIndex, dataIndex, chartIndex) {
|
||||
const leftUnit = this.chartInfo.unit
|
||||
const leftUnitCompute = chartDataFormat.getUnit(leftUnit)
|
||||
const decimals = this.chartInfo.param.decimals || 2
|
||||
if (chartIndex > 19) {
|
||||
this.seriesColor.push(randomcolor())
|
||||
}
|
||||
const legend = this.handleLegend(this.chartInfo, series, expressionIndex, dataIndex, chartIndex)
|
||||
console.log(legend)
|
||||
const obj = {
|
||||
name: series.elements.name + JSON.stringify(series.metric),
|
||||
label: series.elements.name + JSON.stringify(series.metric),
|
||||
class: series.elements.name + JSON.stringify(series.metric),
|
||||
scale: 'left', // right
|
||||
// value: (u, v) => v == null ? null : (!v ? v : leftUnitCompute.compute(v, null, -1, decimals)),
|
||||
values: (u, v) => series.elements.name + JSON.stringify(series.metric),
|
||||
stroke: this.seriesColor[chartIndex],
|
||||
width: 1 / devicePixelRatio
|
||||
}
|
||||
const name = series.elements.name + JSON.stringify(series.metric)
|
||||
const alias = series.elements.name + JSON.stringify(series.metric)
|
||||
const name = legend.name
|
||||
const alias = legend.alias
|
||||
const statistics = series.statistics
|
||||
this.legends.push({ name, alias, statistics, color: this.seriesColor[chartIndex] })
|
||||
return obj
|
||||
|
||||
@@ -189,6 +189,7 @@ export default {
|
||||
},
|
||||
// 单个legend
|
||||
handleLegend (chartInfo, data, expressionIndexs, dataIndex, colorIndex) {
|
||||
console.log(chartInfo, data, expressionIndexs, dataIndex, colorIndex)
|
||||
let expressionIndex = expressionIndexs
|
||||
let legend = '' // up
|
||||
let alias = ''
|
||||
@@ -250,7 +251,7 @@ export default {
|
||||
const colorRandom = randomcolor()
|
||||
this.colorList.push(colorRandom)
|
||||
}
|
||||
this.legends.push({ name, alias, statistics, color: this.colorList[colorIndex] })
|
||||
// this.legends.push({ name, alias, statistics, color: this.colorList[colorIndex] })
|
||||
return {
|
||||
name,
|
||||
alias
|
||||
|
||||
Reference in New Issue
Block a user