NEZ-3051 feat:dashboard 时序图表增加 tooltip配置
This commit is contained in:
@@ -133,6 +133,11 @@ export default {
|
|||||||
this.isStack = this.chartInfo.param.stack
|
this.isStack = this.chartInfo.param.stack
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
const chartOption = lodash.cloneDeep(chartOptions)
|
const chartOption = lodash.cloneDeep(chartOptions)
|
||||||
|
|
||||||
|
if (this.$lodash.get(this.chartInfo, 'param.enable.tooltip', false) && this.$lodash.get(this.chartInfo, 'param.tooltip.mode', 'all') === 'single') {
|
||||||
|
chartOption.tooltip.trigger = 'item'
|
||||||
|
}
|
||||||
|
|
||||||
// 防止tootip超出内容区域
|
// 防止tootip超出内容区域
|
||||||
if (this.from === 'integration' || this.from === 'dashboardTemp') {
|
if (this.from === 'integration' || this.from === 'dashboardTemp') {
|
||||||
chartOption.tooltip.appendToBody = false
|
chartOption.tooltip.appendToBody = false
|
||||||
@@ -367,6 +372,9 @@ export default {
|
|||||||
tooltipFormatter (hasTotal) { // 堆叠图需要total数据
|
tooltipFormatter (hasTotal) { // 堆叠图需要total数据
|
||||||
const self = this
|
const self = this
|
||||||
return function (params) {
|
return function (params) {
|
||||||
|
if (!params.length) { // tooltip mode为single
|
||||||
|
params = [params]
|
||||||
|
}
|
||||||
const decimals = self.chartInfo.param.decimals || 2
|
const decimals = self.chartInfo.param.decimals || 2
|
||||||
let str = '<div class="nz-chart__tooltip">'
|
let str = '<div class="nz-chart__tooltip">'
|
||||||
// 区分左y轴右y轴
|
// 区分左y轴右y轴
|
||||||
@@ -393,6 +401,32 @@ export default {
|
|||||||
if (!arr.length) {
|
if (!arr.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tooltip排序
|
||||||
|
let sortBy
|
||||||
|
if (self.$lodash.get(self.chartInfo, 'param.enable.tooltip') && self.$lodash.get(self.chartInfo, 'param.tooltip.mode') !== 'single' && self.$lodash.get(self.chartInfo, 'param.tooltip.sort') !== 'none') {
|
||||||
|
sortBy = self.$lodash.get(self.chartInfo, 'param.tooltip.sort')
|
||||||
|
}
|
||||||
|
const previousIndex = arr.findIndex(item => item.seriesName.indexOf('Previous') !== -1)
|
||||||
|
if (previousIndex != -1) { // 对比状态
|
||||||
|
const arrNow = arr.slice(0, previousIndex)
|
||||||
|
const arrPrevious = arr.slice(previousIndex)
|
||||||
|
if (sortBy === 'asc') {
|
||||||
|
arrNow.sort((a, b) => a.data[1] - b.data[1])
|
||||||
|
arrPrevious.sort((a, b) => a.data[1] - b.data[1])
|
||||||
|
} else if (sortBy === 'desc') {
|
||||||
|
arrNow.sort((a, b) => b.data[1] - a.data[1])
|
||||||
|
arrPrevious.sort((a, b) => b.data[1] - a.data[1])
|
||||||
|
}
|
||||||
|
arr = [...arrNow, ...arrPrevious]
|
||||||
|
} else {
|
||||||
|
if (sortBy === 'asc') {
|
||||||
|
arr.sort((a, b) => a.data[1] - b.data[1])
|
||||||
|
} else if (sortBy === 'desc') {
|
||||||
|
arr.sort((a, b) => b.data[1] - a.data[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let sum = 0
|
let sum = 0
|
||||||
let flag = true
|
let flag = true
|
||||||
arr.forEach((item, i) => {
|
arr.forEach((item, i) => {
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ export const chartTimeSeriesLineOption = {
|
|||||||
},
|
},
|
||||||
axisTick: {
|
axisTick: {
|
||||||
show: false
|
show: false
|
||||||
|
},
|
||||||
|
axisPointer: {
|
||||||
|
snap: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
yAxis: [
|
yAxis: [
|
||||||
|
|||||||
@@ -230,7 +230,8 @@ export default {
|
|||||||
valueMapping: false,
|
valueMapping: false,
|
||||||
thresholds: false,
|
thresholds: false,
|
||||||
visibility: false,
|
visibility: false,
|
||||||
rightYAxis: false
|
rightYAxis: false,
|
||||||
|
tooltip: true
|
||||||
},
|
},
|
||||||
thresholdShow: true,
|
thresholdShow: true,
|
||||||
thresholds: [{ value: undefined, color: randomcolor() }],
|
thresholds: [{ value: undefined, color: randomcolor() }],
|
||||||
@@ -249,7 +250,11 @@ export default {
|
|||||||
min: undefined,
|
min: undefined,
|
||||||
max: undefined
|
max: undefined
|
||||||
},
|
},
|
||||||
dataLink: []
|
dataLink: [],
|
||||||
|
tooltip: {
|
||||||
|
mode: 'all',
|
||||||
|
sort: 'none'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, orderNum: 0 }],
|
elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, orderNum: 0 }],
|
||||||
panel: '',
|
panel: '',
|
||||||
@@ -432,14 +437,23 @@ export default {
|
|||||||
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
|
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
|
||||||
this.chart.param.collapse = false
|
this.chart.param.collapse = false
|
||||||
}
|
}
|
||||||
if ((this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') && !this.chart.param.rightYAxis) {
|
if (this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') {
|
||||||
this.chart.param.rightYAxis = {
|
if (!this.chart.param.rightYAxis) {
|
||||||
elementNames: [],
|
this.chart.param.rightYAxis = {
|
||||||
style: 'line',
|
elementNames: [],
|
||||||
unit: 2,
|
style: 'line',
|
||||||
label: '',
|
unit: 2,
|
||||||
min: undefined,
|
label: '',
|
||||||
max: undefined
|
min: undefined,
|
||||||
|
max: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.chart.param.tooltip) {
|
||||||
|
this.chart.param.tooltip = {
|
||||||
|
mode: 'all',
|
||||||
|
sort: 'none'
|
||||||
|
}
|
||||||
|
this.chart.param.enable.tooltip = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.chart.type === 'stat') {
|
if (this.chart.type === 'stat') {
|
||||||
@@ -479,14 +493,23 @@ export default {
|
|||||||
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
|
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
|
||||||
this.chart.param.collapse = false
|
this.chart.param.collapse = false
|
||||||
}
|
}
|
||||||
if ((this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') && !this.chart.param.rightYAxis) {
|
if (this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') {
|
||||||
this.chart.param.rightYAxis = {
|
if (!this.chart.param.rightYAxis) {
|
||||||
elementNames: [],
|
this.chart.param.rightYAxis = {
|
||||||
style: 'line',
|
elementNames: [],
|
||||||
unit: 2,
|
style: 'line',
|
||||||
label: '',
|
unit: 2,
|
||||||
min: undefined,
|
label: '',
|
||||||
max: undefined
|
min: undefined,
|
||||||
|
max: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.chart.param.tooltip) {
|
||||||
|
this.chart.param.tooltip = {
|
||||||
|
mode: 'all',
|
||||||
|
sort: 'none'
|
||||||
|
}
|
||||||
|
this.chart.param.enable.tooltip = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.chart.type === 'stat') {
|
if (this.chart.type === 'stat') {
|
||||||
|
|||||||
@@ -448,7 +448,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Right Y Axis -->
|
<!-- Right Y Axis -->
|
||||||
<div v-if="isShowRightYAxis(chartConfig.type)">
|
<div v-if="isTimeSeries(chartConfig.type)">
|
||||||
<div class="form__sub-title">
|
<div class="form__sub-title">
|
||||||
<span>{{$t('dashboard.dashboard.chartForm.rightYAxis')}}</span>
|
<span>{{$t('dashboard.dashboard.chartForm.rightYAxis')}}</span>
|
||||||
<el-switch
|
<el-switch
|
||||||
@@ -574,6 +574,62 @@
|
|||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Tooltip -->
|
||||||
|
<div v-if="isTimeSeries(chartConfig.type)">
|
||||||
|
<div class="form__sub-title">
|
||||||
|
<span>{{$t('dashboard.dashboard.chartForm.tooltip')}}</span>
|
||||||
|
<el-switch
|
||||||
|
v-model="chartConfig.param.enable.tooltip"
|
||||||
|
size="small"
|
||||||
|
@change="change"
|
||||||
|
></el-switch>
|
||||||
|
</div>
|
||||||
|
<transition name="el-zoom-in-top">
|
||||||
|
<div
|
||||||
|
v-if="chartConfig.param.enable.tooltip"
|
||||||
|
class="form-items--half-width-group"
|
||||||
|
>
|
||||||
|
<!-- Mode -->
|
||||||
|
<el-form-item
|
||||||
|
:label="$t('dashboard.mode')"
|
||||||
|
class="form-item--half-width"
|
||||||
|
prop="param.tooltip.mode"
|
||||||
|
:rules="{ required: true, message: $t('validate.required'), trigger: 'change'}"
|
||||||
|
>
|
||||||
|
<el-select
|
||||||
|
v-model="chartConfig.param.tooltip.mode"
|
||||||
|
placeholder=""
|
||||||
|
popper-class="right-box-select-top prevent-clickoutside"
|
||||||
|
size="small"
|
||||||
|
@change="change"
|
||||||
|
>
|
||||||
|
<el-option :label="$t('dashboard.dashboard.chartForm.single')" value="single"></el-option>
|
||||||
|
<el-option :label="$t('overall.exportAll')" value="all"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<!-- Sort -->
|
||||||
|
<el-form-item
|
||||||
|
v-if="chartConfig.param.tooltip.mode!=='single'"
|
||||||
|
:label="$t('dashboard.dashboard.chartForm.sort')"
|
||||||
|
class="form-item--half-width"
|
||||||
|
prop="param.tooltip.sort"
|
||||||
|
>
|
||||||
|
<el-select
|
||||||
|
v-model="chartConfig.param.tooltip.sort"
|
||||||
|
placeholder=""
|
||||||
|
popper-class="right-box-select-top prevent-clickoutside"
|
||||||
|
size="small"
|
||||||
|
@change="change"
|
||||||
|
>
|
||||||
|
<el-option :label="$t('project.topology.none')" value="none"></el-option>
|
||||||
|
<el-option :label="$t('dashboard.explore.ascending')" value="asc"></el-option>
|
||||||
|
<el-option :label="$t('dashboard.explore.descending')" value="desc"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="isShowLegend(chartConfig.type)">
|
<div v-if="isShowLegend(chartConfig.type)">
|
||||||
<!--legendConfig-->
|
<!--legendConfig-->
|
||||||
<div class="form__sub-title">
|
<div class="form__sub-title">
|
||||||
@@ -1380,7 +1436,8 @@ export default {
|
|||||||
valueMapping: false,
|
valueMapping: false,
|
||||||
thresholds: false,
|
thresholds: false,
|
||||||
visibility: false,
|
visibility: false,
|
||||||
rightYAxis: false
|
rightYAxis: false,
|
||||||
|
tooltip: true
|
||||||
},
|
},
|
||||||
showHeader: this.chartConfig.param.showHeader,
|
showHeader: this.chartConfig.param.showHeader,
|
||||||
visibility: {
|
visibility: {
|
||||||
@@ -1397,7 +1454,11 @@ export default {
|
|||||||
min: undefined,
|
min: undefined,
|
||||||
max: undefined
|
max: undefined
|
||||||
},
|
},
|
||||||
dataLink: this.chartConfig.param.dataLink
|
dataLink: this.chartConfig.param.dataLink,
|
||||||
|
tooltip: {
|
||||||
|
mode: 'all',
|
||||||
|
sort: 'none'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.chartConfig.param.thresholds.push({ value: undefined, color: randomcolor() })
|
this.chartConfig.param.thresholds.push({ value: undefined, color: randomcolor() })
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ export default {
|
|||||||
default: return false
|
default: return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isShowRightYAxis (type) {
|
isTimeSeries (type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'line':
|
case 'line':
|
||||||
case 'area':
|
case 'area':
|
||||||
|
|||||||
@@ -247,7 +247,8 @@ export default {
|
|||||||
valueMapping: false,
|
valueMapping: false,
|
||||||
thresholds: false,
|
thresholds: false,
|
||||||
visibility: false,
|
visibility: false,
|
||||||
rightYAxis: false
|
rightYAxis: false,
|
||||||
|
tooltip: true
|
||||||
},
|
},
|
||||||
thresholdShow: true,
|
thresholdShow: true,
|
||||||
thresholds: [{ value: undefined, color: randomcolor() }],
|
thresholds: [{ value: undefined, color: randomcolor() }],
|
||||||
@@ -266,7 +267,11 @@ export default {
|
|||||||
min: undefined,
|
min: undefined,
|
||||||
max: undefined
|
max: undefined
|
||||||
},
|
},
|
||||||
dataLink: []
|
dataLink: [],
|
||||||
|
tooltip: {
|
||||||
|
mode: 'all',
|
||||||
|
sort: 'none'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, orderNum: 0 }],
|
elements: [{ expression: '', legend: '', type: 'expert', id: '', name: 'A', state: 1, orderNum: 0 }],
|
||||||
panel: '',
|
panel: '',
|
||||||
@@ -607,14 +612,23 @@ export default {
|
|||||||
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
|
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
|
||||||
this.chart.param.collapse = false
|
this.chart.param.collapse = false
|
||||||
}
|
}
|
||||||
if ((this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') && !this.chart.param.rightYAxis) {
|
if (this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') {
|
||||||
this.chart.param.rightYAxis = {
|
if (!this.chart.param.rightYAxis) {
|
||||||
elementNames: [],
|
this.chart.param.rightYAxis = {
|
||||||
style: 'line',
|
elementNames: [],
|
||||||
unit: 2,
|
style: 'line',
|
||||||
label: '',
|
unit: 2,
|
||||||
min: undefined,
|
label: '',
|
||||||
max: undefined
|
min: undefined,
|
||||||
|
max: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.chart.param.tooltip) {
|
||||||
|
this.chart.param.tooltip = {
|
||||||
|
mode: 'all',
|
||||||
|
sort: 'none'
|
||||||
|
}
|
||||||
|
this.chart.param.enable.tooltip = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.chart.type === 'stat') {
|
if (this.chart.type === 'stat') {
|
||||||
@@ -654,14 +668,23 @@ export default {
|
|||||||
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
|
if (this.chart.type === 'group' && !this.chart.param.collapse == undefined) {
|
||||||
this.chart.param.collapse = false
|
this.chart.param.collapse = false
|
||||||
}
|
}
|
||||||
if ((this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') && !this.chart.param.rightYAxis) {
|
if (this.chart.type === 'line' || this.chart.type === 'area' || this.chart.type === 'point') {
|
||||||
this.chart.param.rightYAxis = {
|
if (!this.chart.param.rightYAxis) {
|
||||||
elementNames: [],
|
this.chart.param.rightYAxis = {
|
||||||
style: 'line',
|
elementNames: [],
|
||||||
unit: 2,
|
style: 'line',
|
||||||
label: '',
|
unit: 2,
|
||||||
min: undefined,
|
label: '',
|
||||||
max: undefined
|
min: undefined,
|
||||||
|
max: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.chart.param.tooltip) {
|
||||||
|
this.chart.param.tooltip = {
|
||||||
|
mode: 'all',
|
||||||
|
sort: 'none'
|
||||||
|
}
|
||||||
|
this.chart.param.enable.tooltip = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.chart.type === 'stat') {
|
if (this.chart.type === 'stat') {
|
||||||
|
|||||||
Reference in New Issue
Block a user