feat: 优化 tooltip的显示 以及 事件的处理
This commit is contained in:
@@ -166,6 +166,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
initChart (chartOptions = this.chartOption) {
|
initChart (chartOptions = this.chartOption) {
|
||||||
this.setDataLink()
|
this.setDataLink()
|
||||||
|
console.log(JSON.stringify(this.chartData))
|
||||||
try {
|
try {
|
||||||
this.isStack = this.chartInfo.param.stack
|
this.isStack = this.chartInfo.param.stack
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|||||||
@@ -319,9 +319,40 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
showAllSeries () {
|
showAllSeries () {
|
||||||
|
const echarts = getChart(this.chartId)
|
||||||
|
const arr = []
|
||||||
|
if (echarts) {
|
||||||
|
echarts.series.forEach((seriesItem, sindex) => {
|
||||||
|
if (sindex > 0) {
|
||||||
|
seriesItem.show = true
|
||||||
|
arr.push(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
echarts.redraw()
|
||||||
|
if (this.$refs.legend) {
|
||||||
|
this.$refs.legend.isGrey = this.isGrey = arr
|
||||||
|
}
|
||||||
|
}
|
||||||
this.clickout()
|
this.clickout()
|
||||||
},
|
},
|
||||||
showSelectedSeries () {
|
showSelectedSeries () {
|
||||||
|
const index = this.toolbox.clickIndex
|
||||||
|
const echarts = getChart(this.chartId)
|
||||||
|
const arr = []
|
||||||
|
if (echarts) {
|
||||||
|
echarts.series.forEach((seriesItem, sindex) => {
|
||||||
|
if (sindex > 0) {
|
||||||
|
seriesItem.show = false
|
||||||
|
arr.push(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
echarts.series[index + 1].show = !echarts.series[index + 1].show
|
||||||
|
arr[index] = false
|
||||||
|
echarts.redraw()
|
||||||
|
if (this.$refs.legend) {
|
||||||
|
this.$refs.legend.isGrey = this.isGrey = arr
|
||||||
|
}
|
||||||
|
}
|
||||||
this.clickout()
|
this.clickout()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export default {
|
|||||||
...ObjTime,
|
...ObjTime,
|
||||||
...seriesObjTime
|
...seriesObjTime
|
||||||
}
|
}
|
||||||
|
item.expressionIndex = expressionIndex
|
||||||
seriesData.push(Object.keys(seriesObjTime).map(time => seriesObjTime[time]))
|
seriesData.push(Object.keys(seriesObjTime).map(time => seriesObjTime[time]))
|
||||||
seriesAll.push(this.renderSeries(item, expressionIndex, seriesIndex, chartIndex))
|
seriesAll.push(this.renderSeries(item, expressionIndex, seriesIndex, chartIndex))
|
||||||
chartIndex++
|
chartIndex++
|
||||||
@@ -107,7 +108,8 @@ export default {
|
|||||||
yAxisIndex: isRight ? 1 : 0, // right
|
yAxisIndex: isRight ? 1 : 0, // right
|
||||||
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,
|
||||||
|
expressionIndex: series.expressionIndex
|
||||||
}
|
}
|
||||||
if (chartType === 'area') {
|
if (chartType === 'area') {
|
||||||
obj.fill = this.seriesColor[chartIndex] + '20' // 面积图使用
|
obj.fill = this.seriesColor[chartIndex] + '20' // 面积图使用
|
||||||
@@ -127,7 +129,8 @@ export default {
|
|||||||
let tooltipTopOffset = 0
|
let tooltipTopOffset = 0
|
||||||
const self = this
|
const self = this
|
||||||
const tooltip = document.createElement('div')
|
const tooltip = document.createElement('div')
|
||||||
tooltip.className = 'nz-uplot-tooltip'
|
tooltip.className = 'nz-uplot-tooltip chart-time-series-tooltip'
|
||||||
|
tooltip.style.display = 'none'
|
||||||
let over
|
let over
|
||||||
let isRender = false
|
let isRender = false
|
||||||
function setTooltip (u, e) { // 生成tooltip内容
|
function setTooltip (u, e) { // 生成tooltip内容
|
||||||
@@ -138,8 +141,6 @@ export default {
|
|||||||
const lft = u.valToPos(u.data[0][self.dataIdx], 'x')
|
const lft = u.valToPos(u.data[0][self.dataIdx], 'x')
|
||||||
const windowWidth = window.innerWidth// 窗口宽度
|
const windowWidth = window.innerWidth// 窗口宽度
|
||||||
const windowHeight = window.innerHeight// 窗口高度
|
const windowHeight = window.innerHeight// 窗口高度
|
||||||
const boxWidth = tooltip.offsetWidth
|
|
||||||
const boxHeight = tooltip.offsetHeight
|
|
||||||
let x = 0
|
let x = 0
|
||||||
let y = 0
|
let y = 0
|
||||||
if (self.mousePosition.left < (windowWidth / 2)) { // 说明鼠标在左边放不下提示框
|
if (self.mousePosition.left < (windowWidth / 2)) { // 说明鼠标在左边放不下提示框
|
||||||
@@ -162,6 +163,7 @@ export default {
|
|||||||
const tooltipModel = self.$lodash.get(self.chartInfo, 'param.tooltip.mode', 'single')
|
const tooltipModel = self.$lodash.get(self.chartInfo, 'param.tooltip.mode', 'single')
|
||||||
if (self.chartInfo.param && !(tooltipModel == 'single')) {
|
if (self.chartInfo.param && !(tooltipModel == 'single')) {
|
||||||
params = u.series.map((s, i) => {
|
params = u.series.map((s, i) => {
|
||||||
|
if (i == 0) return ''
|
||||||
return {
|
return {
|
||||||
seriesIndex: i - 1,
|
seriesIndex: i - 1,
|
||||||
yAxisIndex: s.yAxisIndex,
|
yAxisIndex: s.yAxisIndex,
|
||||||
@@ -171,11 +173,7 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
params = params.filter(item => {
|
params = params.filter(item => {
|
||||||
if (!item || !item.seriesIndex || !item.show) {
|
return item && item.show
|
||||||
return false
|
|
||||||
}
|
|
||||||
const flag = typeof (item.value[1]) == 'undefined'
|
|
||||||
return !flag
|
|
||||||
})
|
})
|
||||||
} else if (self.seriesIdx) {
|
} else if (self.seriesIdx) {
|
||||||
const obj = self.series[self.seriesIdx - 1]
|
const obj = self.series[self.seriesIdx - 1]
|
||||||
@@ -193,13 +191,13 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
tooltip.style.display = 'block'
|
tooltip.style.display = 'block'
|
||||||
}
|
}
|
||||||
if (self.isConnect == 'crosshair' && self.chartId !== self.currentMousemove) {
|
if (self.isConnect == 'crosshair' && self.chartId != self.currentMousemove) {
|
||||||
|
tooltip.style.display = 'none'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (self.seriesIdx) {
|
if (self.seriesIdx) {
|
||||||
over.style.cursor = 'pointer'
|
over.style.cursor = 'pointer'
|
||||||
}
|
}
|
||||||
tooltip.className += ' chart-time-series-tooltip'
|
|
||||||
let str = '<div class="nz-tooltip nz-chart__tooltip">'
|
let str = '<div class="nz-tooltip nz-chart__tooltip">'
|
||||||
const hasTotal = self.isStack
|
const hasTotal = self.isStack
|
||||||
const decimals = self.chartInfo.param.decimals || 2
|
const decimals = self.chartInfo.param.decimals || 2
|
||||||
@@ -305,11 +303,12 @@ export default {
|
|||||||
} else if (paramsDot > 6) {
|
} else if (paramsDot > 6) {
|
||||||
paramsDot = 6
|
paramsDot = 6
|
||||||
}
|
}
|
||||||
const val = formatScientificNotation(item.value[1], paramsDot)
|
const val = typeof (item.value[1]) == 'undefined' ? 0 : formatScientificNotation(item.value[1], paramsDot)
|
||||||
|
const showVal = typeof (item.value[1]) == 'undefined' ? '' : chartDataFormat.getUnit(unit).compute(val, null, -1, decimals)
|
||||||
sum += isNaN(self.numberWithEConvent(val)) ? 0 : parseFloat(self.numberWithEConvent(val))
|
sum += isNaN(self.numberWithEConvent(val)) ? 0 : parseFloat(self.numberWithEConvent(val))
|
||||||
let previousDom = ''
|
let previousDom = ''
|
||||||
if (previousItem) {
|
if (previousItem) {
|
||||||
const previousVal = formatScientificNotation(previousItem.value[1], paramsDot)
|
const previousVal = typeof (previousItem.value[1]) == 'undefined' ? 0 : formatScientificNotation(previousItem.value[1], paramsDot)
|
||||||
let minusVal = 0
|
let minusVal = 0
|
||||||
let operator
|
let operator
|
||||||
if (previousVal <= val) {
|
if (previousVal <= val) {
|
||||||
@@ -340,7 +339,7 @@ export default {
|
|||||||
<span>${seriesName}</span>
|
<span>${seriesName}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row__value">
|
<div class="row__value">
|
||||||
<span>${chartDataFormat.getUnit(unit).compute(val, null, -1, decimals)}</span>
|
<span>${showVal}</span>
|
||||||
${previousDom}
|
${previousDom}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -466,6 +465,12 @@ export default {
|
|||||||
uplotMouseenter () {
|
uplotMouseenter () {
|
||||||
const chart = getChart(this.chartId)
|
const chart = getChart(this.chartId)
|
||||||
const over = chart.over
|
const over = chart.over
|
||||||
|
const root = chart.root.querySelector('.u-wrap')
|
||||||
|
let tooltip = root.getElementsByClassName('nz-uplot-tooltip')
|
||||||
|
if (tooltip.length) {
|
||||||
|
tooltip = tooltip[0]
|
||||||
|
tooltip.style.display = 'block'
|
||||||
|
}
|
||||||
over.addEventListener('mouseleave', this.uplotMouseleave)
|
over.addEventListener('mouseleave', this.uplotMouseleave)
|
||||||
over.addEventListener('mousemove', this.uplotMousemove)
|
over.addEventListener('mousemove', this.uplotMousemove)
|
||||||
over.addEventListener('mousedown', this.uplotMousedown)
|
over.addEventListener('mousedown', this.uplotMousedown)
|
||||||
@@ -475,6 +480,13 @@ export default {
|
|||||||
uplotMouseleave () {
|
uplotMouseleave () {
|
||||||
const chart = getChart(this.chartId)
|
const chart = getChart(this.chartId)
|
||||||
const over = chart.over
|
const over = chart.over
|
||||||
|
const root = chart.root.querySelector('.u-wrap')
|
||||||
|
let tooltip = root.getElementsByClassName('nz-uplot-tooltip')
|
||||||
|
console.log(tooltip, over)
|
||||||
|
if (tooltip.length) {
|
||||||
|
tooltip = tooltip[0]
|
||||||
|
tooltip.style.display = 'none'
|
||||||
|
}
|
||||||
over.removeEventListener('mouseleave', this.uplotMouseleave)
|
over.removeEventListener('mouseleave', this.uplotMouseleave)
|
||||||
over.removeEventListener('mousemove', this.uplotMousemove)
|
over.removeEventListener('mousemove', this.uplotMousemove)
|
||||||
over.removeEventListener('mousedown', this.uplotMousedown)
|
over.removeEventListener('mousedown', this.uplotMousedown)
|
||||||
@@ -532,7 +544,7 @@ export default {
|
|||||||
}
|
}
|
||||||
console.log(params)
|
console.log(params)
|
||||||
if (!params.seriesName) {
|
if (!params.seriesName) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const nameArr = params.seriesName.split('-')
|
const nameArr = params.seriesName.split('-')
|
||||||
if (nameArr.length > 1) {
|
if (nameArr.length > 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user