From 74af760db72e406c77d197af33bb5c5d2e2812a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=8A=B2=E6=9D=BE?= Date: Wed, 23 Dec 2020 19:05:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20legend=E9=AB=98=E4=BA=AE=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/charts/chartPreview.vue | 44 +++- .../components/charts/line-chart-block.vue | 249 +++++++++++------- .../page/dashboard/overview/chart.vue | 54 +++- 3 files changed, 243 insertions(+), 104 deletions(-) diff --git a/nezha-fronted/src/components/charts/chartPreview.vue b/nezha-fronted/src/components/charts/chartPreview.vue index ada280624..31cbecd0a 100644 --- a/nezha-fronted/src/components/charts/chartPreview.vue +++ b/nezha-fronted/src/components/charts/chartPreview.vue @@ -606,8 +606,48 @@ } }, clickScreenLegend(legendName,index){ + /*点击legend + * 1.当前如果是全高亮状态,则全部置灰,只留被点击的legend高亮 + * 2.如果点击的是唯一高亮的legend,则变为全高亮状态 + * 3.否则只改变被点击的legend状态 + * */ + let highlightNum = 0; //高亮数量 + this.isGreyScreen.forEach(g => { + if (!g) { + highlightNum++; + } + }); + let hasGrey = highlightNum < this.isGreyScreen.length; //是否有置灰的 + let curIsGrey = this.isGreyScreen[index]; //当前legend的状态 + let currentIsTheOnlyOneHighlight = !curIsGrey && highlightNum === 1; //当前legend是否是目前唯一高亮的 + + let echart = this.echartModalStore; + if (echart) { + if (!hasGrey) { //1.除当前legend外全置灰 + echart.dispatchAction({ + type: 'legendInverseSelect' + }); + echart.dispatchAction({ + type: 'legendSelect', + name: legendName + }); + this.isGreyScreen = this.isGreyScreen.map((g, i) => i !== index); + } else if (currentIsTheOnlyOneHighlight) { //2.全高亮 + echart.dispatchAction({ + type: 'legendAllSelect' + }); + this.isGreyScreen = this.isGreyScreen.map(() => false); + } else { + let type = curIsGrey ? "legendSelect" : "legendUnSelect"; + echart.dispatchAction({ + type: type, + name: legendName + }); + this.$set(this.isGreyScreen, index, !this.isGreyScreen[index]); + } + } //点击图表某一个legend,图表只显示当前点击的曲线或柱状图,其它隐藏,再次点击已选中的legend ,显示全部 - let curIsGrey=this.isGreyScreen[index]; + /*let curIsGrey=this.isGreyScreen[index]; if(this.echartModalStore){ this.screenLegendList.forEach((item,i)=>{ let isGrey = this.isGreyScreen[i]; @@ -650,7 +690,7 @@ } } }) - } + }*/ }, formatLegend(chartWidth,name){ if(!name){ diff --git a/nezha-fronted/src/components/charts/line-chart-block.vue b/nezha-fronted/src/components/charts/line-chart-block.vue index a5286dc55..4777e87b4 100644 --- a/nezha-fronted/src/components/charts/line-chart-block.vue +++ b/nezha-fronted/src/components/charts/line-chart-block.vue @@ -178,6 +178,7 @@ +