diff --git a/nezha-fronted/src/assets/css/common.scss b/nezha-fronted/src/assets/css/common.scss index 7856ea690..8e60399da 100644 --- a/nezha-fronted/src/assets/css/common.scss +++ b/nezha-fronted/src/assets/css/common.scss @@ -440,7 +440,7 @@ td .nz-icon-gear:before { .chart-bar, .chart-gauge, .chart-sankey, -.chart-time-series, +.chart-time-series-tooltip, .chart-treemap, .chart-pie, .chart-bubble, @@ -456,7 +456,7 @@ td .nz-icon-gear:before { color: $--color-text-regular !important; box-shadow: none !important; } -.chart-time-series, +.chart-time-series-tooltip, .chart-pie, .chart-bar, .chart-treemap, @@ -464,7 +464,26 @@ td .nz-icon-gear:before { visibility: hidden; position: absolute; } - +.chart-time-series-tooltip { + position: absolute; + display: block; + border-style: solid; + white-space: nowrap; + box-shadow: rgba(0, 0, 0, 0.2) 1px 2px 10px; + transition: opacity 0.2s cubic-bezier(0.23, 1, 0.32, 1) 0s, visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1) 0s, transform 0.4s cubic-bezier(0.23, 1, 0.32, 1) 0s; + background-color: rgb(255, 255, 255); + border-width: 1px; + border-radius: 4px; + color: rgb(102, 102, 102); + font: 14px / 21px "Microsoft YaHei"; + padding: 10px; + top: 0px; + left: 0px; + border-color: rgb(255, 255, 255); + z-index: 99999999; + visibility: visible; + pointer-events: none; +} .yAxis-icon{ margin-right: 4px; background: transparent !important; @@ -543,7 +562,7 @@ i.nz-icon-override{ outline: none; } } -.chart-time-series.hide{ +.chart-time-series-tooltip.hide{ display: none !important; } .alert-rule-info-two{ diff --git a/nezha-fronted/src/components/chart/chart/legend.vue b/nezha-fronted/src/components/chart/chart/legend.vue index 719ab46d7..2540f1176 100644 --- a/nezha-fronted/src/components/chart/chart/legend.vue +++ b/nezha-fronted/src/components/chart/chart/legend.vue @@ -247,26 +247,15 @@ export default { if (this.isGrey[index]) { return false } - return if (this.chartInfo.type === 'pie' || this.chartInfo.type === 'doughnut' || this.chartInfo.type === 'rose') { this.$emit('hoverLegendD3', legendName, index, type) } else if (this.isTimeSeries) { - if (type == 'highlight' && getChart(this.chartId)) { - const option = getChart(this.chartId).getOption() - const series = this.$lodash.cloneDeep(option.series) - series[index].emphasis.focus = 'series' - getChart(this.chartId).setOption({ series }) - } else if (getChart(this.chartId)) { - const option = getChart(this.chartId).getOption() - const series = this.$lodash.cloneDeep(option.series) - series[index].emphasis.focus = 'none' - getChart(this.chartId).setOption({ series }) + const echarts = getChart(this.chartId) + if (type == 'highlight') { + echarts.setSeries(index + 1, {focus:true}) + } else { + echarts.setSeries(null, {focus: true}) } - getChart(this.chartId) && getChart(this.chartId).dispatchAction({ - type: type, - seriesIndex: index, - name: legendName - }) } else { getChart(this.chartId) && getChart(this.chartId).dispatchAction({ type: type, diff --git a/nezha-fronted/src/components/chart/chart/uplot/chartTimeSeries.vue b/nezha-fronted/src/components/chart/chart/uplot/chartTimeSeries.vue index 744993a55..940ad3763 100644 --- a/nezha-fronted/src/components/chart/chart/uplot/chartTimeSeries.vue +++ b/nezha-fronted/src/components/chart/chart/uplot/chartTimeSeries.vue @@ -200,7 +200,7 @@ export default { } }) ], - padding: [15, 15, 15, 15], + padding: [15, this.autoPadRight, 15, 15], legend: { show: false }, @@ -214,11 +214,11 @@ export default { { scale: 'left', values: (u, vals, space) => vals.map(v => leftUnitCompute.compute(v, null, -1, decimals)), - formatValue: (v, d) => { - console.log(v, d, 'vd') - return v - }, incrs: incrs, + // space: (self) => { + // console.log(self) + // return 50 + // }, size (self, values, axisIdx, cycleNum) { const axis = self.axes[axisIdx] @@ -243,34 +243,14 @@ export default { { show: true, side: 1, - grid: { show: false, width: 0 }, + grid: { show: false }, scale: 'right', + // space: (self) => { + // console.log(self) + // return 50 + // }, values: (u, vals, space) => vals.map(v => rightUnitCompute.compute(v, null, -1, decimals)), - formatValue: (v, d) => { - console.log(v, d, 'vd') - return v - }, incrs: rightIncrs - // size (self, values, axisIdx, cycleNum) { - // const axis = self.axes[axisIdx] - // - // // bail out, force convergence - // if (cycleNum > 1) { return axis._size } - // - // let axisSize = axis.ticks.size + axis.gap - // - // // find longest value - // const longestVal = (values ?? []).reduce((acc, val) => ( - // val.length > acc.length ? val : acc - // ), '') - // - // if (longestVal != '') { - // self.ctx.font = axis.font[0] - // axisSize += self.ctx.measureText(longestVal).width / devicePixelRatio - // } - // - // return Math.ceil(axisSize) - // } } ] } diff --git a/nezha-fronted/src/components/chart/chart/uplot/chartTimeSeriesMixin.js b/nezha-fronted/src/components/chart/chart/uplot/chartTimeSeriesMixin.js index bb58b0658..86a460957 100644 --- a/nezha-fronted/src/components/chart/chart/uplot/chartTimeSeriesMixin.js +++ b/nezha-fronted/src/components/chart/chart/uplot/chartTimeSeriesMixin.js @@ -2,8 +2,9 @@ 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' +import { formatScientificNotation, getMetricTypeValue } from '@/components/common/js/tools' import uPlot from 'uplot' +import bus from '@/libs/bus' export default { data () { return { @@ -75,9 +76,12 @@ export default { const elementNames = this.$lodash.get(this.chartInfo, 'param.rightYAxis.elementNames', []) isRight = elementNames.indexOf(series.elements.name) !== -1 } + const name = legend.name + const alias = legend.alias + const statistics = series.statistics const obj = { - name: series.elements.name + JSON.stringify(series.metric), - label: series.elements.name + JSON.stringify(series.metric), + name: name, + label: alias, class: series.elements.name + JSON.stringify(series.metric), scale: isRight ? 'right' : 'left', // right yAxisIndex: isRight ? 1 : 0, // right @@ -85,9 +89,6 @@ export default { stroke: this.seriesColor[chartIndex], width: 1 / devicePixelRatio } - const name = legend.name - const alias = legend.alias - const statistics = series.statistics this.legends.push({ name, alias, statistics, color: this.seriesColor[chartIndex] }) return obj }, @@ -96,17 +97,11 @@ export default { let tooltipTopOffset = 0 const self = this const tooltip = document.createElement('div') - tooltip.className = 'u-tooltip' - let seriesIdx = null let dataIdx = null - - const fmtDate = uPlot.fmtDate('{M}/{D}/{YY} {h}:{mm}:{ss} {AA}') - let over - let tooltipVisible = false - + let isRender = false function showTooltip () { if (!tooltipVisible) { tooltip.style.display = 'block' @@ -123,23 +118,240 @@ export default { } } - function setTooltip (u) { + function setTooltip (u) { // 生成tooltip内容 showTooltip() - - const top = u.valToPos(u.data[seriesIdx][dataIdx], 'y') + if (!self.$lodash.get(self.chartInfo, 'param.enable.tooltip', false)) { + return + } + isRender = false + console.log(self.chartInfo, seriesIdx, dataIdx, u) + const { left, top } = u.cursor const lft = u.valToPos(u.data[0][dataIdx], 'x') - tooltip.style.top = (tooltipTopOffset + top + shiftX) + 'px' tooltip.style.left = (tooltipLeftOffset + lft + shiftY) + 'px' + let params = [] + const tooltipModel = self.$lodash.get(self.chartInfo, 'param.tooltip.mode', 'single') + console.log(tooltipModel) + if (self.chartInfo.param && !(tooltipModel == 'single')) { + params = self.series.map((s, i) => { + return { + seriesIndex: i, + yAxisIndex: s.yAxisIndex, + value: [u.data[0][dataIdx], u.data[i + 1][dataIdx]], + seriesName: s.label + } + }) + params = params.filter(item => { + console.log(item.value[1], typeof (item.value[1]) == 'undefined') + const flag = typeof (item.value[1]) == 'undefined' + return !flag + }) + } else if (seriesIdx) { + const obj = self.series[seriesIdx - 1] + params = [{ + seriesIndex: seriesIdx - 1, + yAxisIndex: obj.yAxisIndex, + value: [u.data[0][dataIdx], u.data[seriesIdx][dataIdx]], + seriesName: obj.label + }] + } + isRender = !!params.length + console.log(isRender, 'isRender') + if (!isRender) { + tooltip.style.display = 'none' + over.style.cursor = null + return + } else { + tooltip.style.display = 'block' + over.style.cursor = 'pointer' + } + tooltip.className = 'chart-time-series-tooltip' + let str = '