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