NEZ-2293 fix:chart-line datazoom后 未重新计算分段
This commit is contained in:
@@ -167,7 +167,69 @@ export default {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const self = this
|
||||
getChart(this.chartId).off('dataZoom')
|
||||
getChart(this.chartId).on('dataZoom', function (params) {
|
||||
if (params.batch[0].startValue) {
|
||||
const chartInfo = self.chartInfo
|
||||
const dataArg = self.$loadsh.cloneDeep(self.series)
|
||||
dataArg.forEach(item => {
|
||||
item.data = item.data.filter(value => value[0] > params.batch[0].startValue && value[0] < params.batch[0].endValue)
|
||||
})
|
||||
const maxValueCopies = self.getMaxValue(dataArg, chartInfo)
|
||||
const maxValue = maxValueCopies.maxValue
|
||||
const copies = maxValueCopies.copies
|
||||
const unit = maxValueCopies.unit
|
||||
const option = {
|
||||
yAxis: {
|
||||
minInterval: chartDataFormat.Interval(maxValue, copies, unit.type, 'min'),
|
||||
maxInterval: chartDataFormat.Interval(maxValue, copies, unit.type, 'max') * Math.ceil(dataArg.length / 5)
|
||||
}
|
||||
}
|
||||
if (!maxValueCopies.copies) {
|
||||
option.yAxis.min = 0
|
||||
option.yAxis.max = 1
|
||||
} else {
|
||||
option.yAxis.max = undefined
|
||||
}
|
||||
if (unit.type == 'Time' || option.yAxis.maxInterval === 1) {
|
||||
delete option.yAxis.maxInterval
|
||||
}
|
||||
getChart(self.chartId) && getChart(self.chartId).setOption({
|
||||
yAxis: {
|
||||
...option.yAxis
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// 处理点击后的 Y轴
|
||||
const chartInfo = self.chartInfo
|
||||
const dataArg = self.series
|
||||
const maxValueCopies = self.getMaxValue(dataArg, chartInfo)
|
||||
const maxValue = maxValueCopies.maxValue
|
||||
const copies = maxValueCopies.copies
|
||||
const unit = maxValueCopies.unit
|
||||
const option = {
|
||||
yAxis: {
|
||||
minInterval: chartDataFormat.Interval(maxValue, copies, unit.type, 'min'),
|
||||
maxInterval: chartDataFormat.Interval(maxValue, copies, unit.type, 'max') * Math.ceil(dataArg.length / 5)
|
||||
}
|
||||
}
|
||||
if (!maxValueCopies.copies) {
|
||||
option.yAxis.min = 0
|
||||
option.yAxis.max = 1
|
||||
} else {
|
||||
option.yAxis.max = undefined
|
||||
}
|
||||
if (unit.type == 'Time' || option.yAxis.maxInterval === 1) {
|
||||
delete option.yAxis.maxInterval
|
||||
}
|
||||
getChart(self.chartId) && getChart(self.chartId).setOption({
|
||||
yAxis: {
|
||||
...option.yAxis
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
this.isInit = false
|
||||
}, 200)
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as echarts from 'echarts'
|
||||
import { getMetricTypeValue } from '@/components/common/js/tools'
|
||||
import { getChart, getMousePoint, setChart } from '@/components/common/js/common'
|
||||
import { randomcolor } from '@/components/common/js/radomcolor/randomcolor'
|
||||
import chartDataFormat from "@/components/chart/chartDataFormat";
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
@@ -318,6 +319,69 @@ export default {
|
||||
}, 300)
|
||||
}
|
||||
},
|
||||
getMaxValue (dataArg, chartInfo) {
|
||||
let maxValue = 0
|
||||
let minValue = 0
|
||||
if (dataArg.length > 0) {
|
||||
maxValue = 0
|
||||
minValue = 0
|
||||
for (let j = 0; j < dataArg.length; j++) {
|
||||
for (let i = 0; i < dataArg[j].data.length; i++) {
|
||||
if (!isNaN(dataArg[j].data[i][1])) {
|
||||
maxValue = (maxValue < Number(dataArg[j].data[i][1]) ? Number(dataArg[j].data[i][1]) : maxValue)
|
||||
minValue = (minValue > Number(dataArg[j].data[i][1]) ? Number(dataArg[j].data[i][1]) : minValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const chartUnit = chartInfo.unit ? chartInfo.unit : 2
|
||||
const unit = chartDataFormat.getUnit(chartUnit)
|
||||
minValue = minValue > 0 ? 0 : minValue
|
||||
if (maxValue < 0) {
|
||||
maxValue = Math.abs(maxValue)
|
||||
}
|
||||
if (Math.abs(minValue) > Math.abs(maxValue)) {
|
||||
maxValue = Math.abs(minValue)
|
||||
}
|
||||
maxValue = maxValue - minValue
|
||||
maxValue = chartDataFormat.formatDatas(maxValue, unit.type, 'ceil', unit.ascii)
|
||||
let oldValue = maxValue
|
||||
if (maxValue < 0) {
|
||||
oldValue = Math.abs(maxValue)
|
||||
}
|
||||
if (minValue < 0) {
|
||||
oldValue = Math.abs(maxValue - minValue)
|
||||
}
|
||||
let dot = 0
|
||||
if (maxValue == 1) {
|
||||
dot++
|
||||
}
|
||||
if (oldValue > 10) {
|
||||
while (oldValue > 10) {
|
||||
oldValue = oldValue / 10
|
||||
}
|
||||
} else if (oldValue < 1 && maxValue !== 0) {
|
||||
while (oldValue < 1 && oldValue > 0) {
|
||||
oldValue = oldValue * 10
|
||||
dot++
|
||||
}
|
||||
maxValue = Math.floor(oldValue) / Math.pow(10, dot)
|
||||
dot++
|
||||
}
|
||||
const copies = chartDataFormat.copies(oldValue, unit.type)
|
||||
let oldDot = 2
|
||||
if (maxValue <= 1) {
|
||||
oldDot = dot > 6 ? 6 : dot
|
||||
}
|
||||
return {
|
||||
maxValue,
|
||||
dot,
|
||||
copies,
|
||||
minValue,
|
||||
unit,
|
||||
oldDot
|
||||
}
|
||||
},
|
||||
resize () {
|
||||
setTimeout(() => {
|
||||
getChart(this.chartId) && getChart(this.chartId).resize()
|
||||
|
||||
Reference in New Issue
Block a user