diff --git a/nezha-fronted/src/components/common/project/L5/CanvasProps.vue b/nezha-fronted/src/components/common/project/L5/CanvasProps.vue index fab81a487..4c4b2e3d6 100644 --- a/nezha-fronted/src/components/common/project/L5/CanvasProps.vue +++ b/nezha-fronted/src/components/common/project/L5/CanvasProps.vue @@ -2,9 +2,9 @@
- - - + + + @@ -41,7 +41,8 @@
- +
{{$t('dashboard.panel.chartForm.legendTip')}}
- + @@ -90,11 +92,12 @@
- + - {{item.name}} @@ -126,7 +129,8 @@ - {{item.name}} @@ -136,50 +140,106 @@
- {{'Thresholds'}} (0:Ok > … >2:Critical) + {{'Thresholds'}} (0:Ok > … >2:Critical) -
- - - - - - - - - - - - - - - - + + {{item.level}} + + +
+
+
+ + T + +
+
+
+ + +
+
+
Fill
+
Line
+
Text
+
+
+ > +
+ base +
+ + + base + + + + + + + + + + + + + + base + + + + + +
+
+ +
+
-
add
@@ -392,6 +452,67 @@
+
+
背景颜色
+
+
+
+ {{selection.pen.fillStyle}} + + + + +
+
+ + +
+
+
+ +
+
Gradient
+
+ + + + + + +
+
+ +
+
透明度(0 - 1)
+
+ +
+
+
线条样式
@@ -576,7 +697,8 @@
{{selection.pen.strokeStyle}} - +
@@ -612,126 +734,8 @@
-
-
背景颜色
-
-
-
- {{selection.pen.fillStyle}} - - - - -
-
- - -
-
-
- -
-
透明度(0 - 1)
-
- -
-
-
- - -
-
-
动画类型
-
- - - -
-
- -
-
圆点大小(px)
-
- -
-
- -
-
线条颜色
-
-
-
- {{selection.pen.animateColor}} - - - - -
-
- - -
-
-
- - - - - - - - - - - - - - - - - - - -
- -
Animation @@ -746,6 +750,7 @@
+
@@ -753,11 +758,48 @@ v-model="selection.pen.animateType" size="small" :popper-append-to-body="false" - @change="changeTopologyOpt(topologyData.data.fromArrow,'fromArrow')"> - + > +
+ +
+ +
+ + + +
+
+
+ +
+
+
+ {{selection.pen.animateColor}} + + + + +
+
+ + +
+
+
+ +
@@ -775,7 +817,8 @@
- +
@@ -975,7 +1018,8 @@
-
@@ -994,7 +1038,8 @@
- +
- +
@@ -1079,10 +1125,11 @@ // import ChartMetric from "./chartMetric"; import chartDataFormat from '../../../charts/chartDataFormat'; import promqlInput from "../../../page/dashboard/explore/promqlInput"; - import {getUUID, resetZIndex} from "../../../common/js/common"; - var rz = { - methods: { - rz(e) { + import {getUUID,resetZIndex} from "../../../common/js/common"; + + var rz={ + methods:{ + rz(e){ resetZIndex(e); } } @@ -1091,7 +1138,7 @@ //pen.type 0为node 1位line data(){ return { - expressions: [], + expressions:[], chartTypeList:[ { id:"line", @@ -1127,17 +1174,14 @@ id:"avg", name:'avg' },{ - id:"count", - name:'count' - },{ - id:"sum", - name:'sum' + id:"total", + name:'total' } ], - metricList: [], // metric列表 + metricList:[], // metric列表 metricCascaderList:[],//metric级联列表 metricAllData:new Map(),//存放所有的project-module-metric-labelValue,避免重复加载 - metricOptions: [], + metricOptions:[], unitOptions:chartDataFormat.unitOptions(), lineId:null, lineIsJson:false, @@ -1213,6 +1257,20 @@ looks:true, }, data:{}, + bkTypeOption:[ + { + id:0, + name:'X' + }, + { + id:1, + name:'→' + }, + { + id:2, + name:'↑' + } + ], penDash:[ {d:'M5 14 l85 0',"stroke-dasharray":""}, {d:'M5 14 l85 0',"stroke-dasharray":"5,5"}, @@ -1245,39 +1303,39 @@ {id:'dot',name:'圆点'}, {id:'comet',name:'彗星'}, ], - nodeAnimateOptions :[ - { - id: 'upDown', - name: '上下跳动' - }, - { - id: 'leftRight', - name: '左右跳动' - }, - { - id: 'heart', - name: '心跳' - }, - { - id: 'success', - name: '成功' - }, - { - id: 'warning', - name: '警告' - }, - { - id: 'error', - name: '错误' - }, - { - id: 'show', - name: '炫耀' - }, - ], + nodeAnimateOptions:[ + { + id:'upDown', + name:'上下跳动' + }, + { + id:'leftRight', + name:'左右跳动' + }, + { + id:'heart', + name:'心跳' + }, + { + id:'success', + name:'成功' + }, + { + id:'warning', + name:'警告' + }, + { + id:'error', + name:'错误' + }, + { + id:'show', + name:'炫耀' + }, + ], } }, - mixins: [rz], + mixins:[rz], components:{ promqlInput }, @@ -1351,10 +1409,10 @@ } }, methods:{ - queryMetrics() { - this.metricOptions = []; + queryMetrics(){ + this.metricOptions=[]; this.$get('prom/api/v1/label/__name__/values').then(response=>{ - if(response.status == 'success'){ + if(response.status=='success'){ let metrics=response.data.sort(); let metricMap=new Map(); metrics.forEach((item)=>{ @@ -1380,7 +1438,7 @@ label:key, value:key, }; - if(metricMap.get(key) && metricMap.get(key).length>1){ + if(metricMap.get(key)&&metricMap.get(key).length>1){ option.children=metricMap.get(key); } this.metricOptions.push(option); @@ -1455,6 +1513,30 @@ } this.onChange(); }, + bkTypeChange(val){ + + if(!this.selection.pen.gradientToColor&&val){ + this.selection.pen.gradientToColor='#bae7ff' + } + if(!this.selection.pen.gradientFromColor&&val){ + this.selection.pen.gradientFromColor='#c6ebb4' + this.selection.pen.fillStyle='#c6ebb4' + } + this.onChange() + }, + colorPickerClick(ref){ + this.$refs[ref].showPicker=true; + }, + colorPickerClickTable(ref,row){ + row.showColor=row.color.fill; + row.showType='fill'; + console.log(row); + console.log(this.$refs[ref]); + this.$nextTick(()=>{ + this.$refs[ref][0].showPicker=true; + }) + + }, colorChange(val,name){//改变颜色 if(name==='arrowColor'){ this.selection.pen.fromArrowColor=this.colorRGBtoHex(val); @@ -1464,18 +1546,43 @@ }else{ this.selection.pen[name]=this.colorRGBtoHex(val); } + if(name=='fillStyle'){ + this.selection.pen.gradientFromColor=this.selection.pen.fillStyle; + } this.selection.pen.data[name]=this.colorRGBtoHex(val); - - this.onChange(); }, + colorChangeTable(item,val){//改变颜色 + if(!item.showType){return}; + item.color[item.showType]=this.colorRGBtoHex(val); + }, + changeShowPicker(item,type){ + this.$refs['colorPickerBac' + item.level][0].showPicker=true; + item.showType=type; + item.showColor=item.color[type]; + }, + colorOut(obj,e){ + + let flag=false; + e.path.forEach((item)=>{ + if(item.className==='el-color-dropdown el-color-picker__panel' || item.className==='color-tab'){ + flag=true + } + }) + console.log(obj,flag); + if(flag){ + return + } + obj.showType=''; + obj.showColor=undefined; + }, changeTopologyOpt(val,key,isColor){ // // getTopology(this.index).data[key]=val; // getTopology(this.index).render(); if(isColor){ this.topologyData.data[key]=this.colorRGBtoHex(val); - } else{ + }else{ this.topologyData.data[key]=val; } Object.keys(this.topologyData.data).forEach((key1)=>{ @@ -1487,8 +1594,8 @@ colorRGBtoHex(color){//获取颜色16进制数 if(!color){ return "" - } - ; + }; + if(color.length<=7){return color} let rgb=color.split(','); let r=parseInt(rgb[0].split('(')[1]); let g=parseInt(rgb[1]); @@ -1516,7 +1623,7 @@ let delObj=this.selection.pen?this.selection.pen.id:this.selection.pens this.$emit('del',delObj); }, - getMetricOptions() { + getMetricOptions(){ return this.metricOptions; }, addExpression(){ @@ -1526,13 +1633,13 @@ expressionChange(item){ }, - removeExpression(index) { - if (this.selection.pen.data.expressArr.length > 1) { - this.selection.pen.data.expressArr.splice(index, 1); - this.selection.pen.data.legends.splice(index, 1); - this.$nextTick(() => { - this.expressions.forEach((ex, index) => { - if (ex) { + removeExpression(index){ + if(this.selection.pen.data.expressArr.length>1){ + this.selection.pen.data.expressArr.splice(index,1); + this.selection.pen.data.legends.splice(index,1); + this.$nextTick(()=>{ + this.expressions.forEach((ex,index)=>{ + if(ex){ this.$refs[`promql-${index}`][0].metricChange(ex); } }); @@ -1542,12 +1649,15 @@ valueMappingAdd(){ this.selection.pen.data.valueMapping.push({ color:{ - border:'#000', - bac:'#fff', - text:'#000', + line:'#000000', + fill:'#ffffff', + text:'#000000', }, - animation:'upDown', + showColor:undefined, + animateType:this.selection.pen.type?1:'upDown', value:'', + level:this.selection.pen.data.valueMapping.length, + showType:'fill',//bac text border }); }, valueMappingValueChange(index,row){ @@ -1557,15 +1667,11 @@ console.log(index,row) }, inputFocus(e){ - // console.log(e); - // console.log(e.path[2]); - // e.path[2].classList.add('el-input-number-show-button'); + console.log(e.path[2].children[0],e.path[2].children[1]); + e.path[2].children[0].setAttribute("tabindex","0"); + e.path[2].children[1].setAttribute("tabindex","1"); }, inputBlur(e){ - // console.log(e); - }, - colorPickerClick(ref){ - this.$refs[ref].showPicker=true; }, } } @@ -1584,11 +1690,13 @@ font-size: 14px; text-align: center; } - .props-box /deep/ .el-tabs--card>.el-tabs__header{ + + .props-box /deep/ .el-tabs--card > .el-tabs__header { background: #EEEEEE; border: none; } - .props-box /deep/ .el-tabs--card>.el-tabs__header .el-tabs__item.is-active{ + + .props-box /deep/ .el-tabs--card > .el-tabs__header .el-tabs__item.is-active { background: #FFFFFF; font-family: Roboto-Bold; font-size: 14px; @@ -1597,7 +1705,8 @@ border-bottom-color: #FFF; border-top: 3px solid #FA901C; } - .props-box /deep/ .el-tabs--card>.el-tabs__header .el-tabs__item{ + + .props-box /deep/ .el-tabs--card > .el-tabs__header .el-tabs__item { box-sizing: content-box; } @@ -1606,20 +1715,26 @@ display: inline-block !important; margin-right: 5px; } + .no-style-class.el-color-picker__panel{ + border-radius: 0 0 5px 5px; + border-top: none; + } diff --git a/nezha-fronted/src/components/common/project/L5/services/canvas.js b/nezha-fronted/src/components/common/project/L5/services/canvas.js index 9b5f50513..d243b6484 100644 --- a/nezha-fronted/src/components/common/project/L5/services/canvas.js +++ b/nezha-fronted/src/components/common/project/L5/services/canvas.js @@ -18,25 +18,25 @@ export const Tools=[ { group:'基本形状', children:[ - { - name:'rectangleImg', - icon:'icon-rect', - data:{ - text:'rect', - rect:{ - width:100, - height:100 - }, - paddingLeft:10, - paddingRight:10, - paddingTop:10, - paddingBottom:10, - name:'rectangleImg', - icon: '\ue680', - iconFamily: 'nz-icon', - iconColor: '' - } - }, + // { + // name:'rectangleImg', + // icon:'icon-rect', + // data:{ + // text:'rect', + // rect:{ + // width:100, + // height:100 + // }, + // paddingLeft:10, + // paddingRight:10, + // paddingTop:10, + // paddingBottom:10, + // name:'rectangleImg', + // icon: '\ue680', + // iconFamily: 'nz-icon', + // iconColor: '' + // } + // }, { name: 'rectangle', icon: 'icon-cube', @@ -165,45 +165,11 @@ export const Tools=[ name:'pentagram' } }, - { - name:'image', - icon:'icon-image', - data:{ - text:'Nezha', - rect:{ - width:100, - height:100 - }, - name:'image', - image:'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3488940205,2956353665&fm=26&gp=0.jpg' - } - }, ] }, { - group: '自定义图片', - children: [ - { - name: 'rectangle', - icon: 'icon-image', - data: { - text: 'Nezha', - rect: { - width: 100, - height: 100 - }, - name: 'rectangle', - image: 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3488940205,2956353665&fm=26&gp=0.jpg', - imageRatio:true, - "imageAlign":"center", - iconRect:{ - "width":80, - "height":80, - }, - "fullIconRect":{"width":80,"height":90,"center":{"x":972,"y":456},"ex":1012,"ey":496} - } - }, - ], + group: '自定义组件', + children: [], }, ]; diff --git a/nezha-fronted/src/components/common/project/L5/topoTooltip.vue b/nezha-fronted/src/components/common/project/L5/topoTooltip.vue index 053f4dc2b..152c9015a 100644 --- a/nezha-fronted/src/components/common/project/L5/topoTooltip.vue +++ b/nezha-fronted/src/components/common/project/L5/topoTooltip.vue @@ -1,10 +1,10 @@ @@ -88,10 +98,12 @@ valueMapping:{"mapping":[{"color":{"bac":"#fff","text":"#000"},"text":"","value":""}],"type":"text"}, }; chartData.span=12; + this.chartData=chartData; + console.log(chartData); setTimeout(()=>{ this.getChartData(chartData,0); }); - this.chartData=chartData + }, // 获取一个图表具体数据,图表信息,图表位置index getChartData(chartInfo, pos, filterType) { @@ -130,21 +142,9 @@ } let step = bus.getStep(startTime, endTime); - this.$nextTick(() => { - // const axiosArr = chartItem.elements.map((ele) => { - // const filterItem = ele; - // let query = encodeURIComponent(filterItem.expression); - // if((chartInfo.type==='line'||chartInfo.type==='bar'||chartInfo.type==='stackArea'||chartInfo.type==='table')&&chartInfo.param){//如果是这三个 默认给connected - // chartInfo.param.nullType=chartInfo.param.nullType||'connected'; - // query+='&nullType='+chartInfo.param.nullType; - // } - // if(chartInfo.type === 'table'&&chartInfo.param&&chartInfo.param.last == 1){ - // return this.$get('/prom/api/v1/query_range?query=' + query + "&start=" + this.$stringTimeParseToUnix(endTime) + "&end=" + this.$stringTimeParseToUnix(endTime) + '&step=' + step); - // } - // return this.$get('/prom/api/v1/query_range?query=' + query + "&start=" + this.$stringTimeParseToUnix(startTime) + "&end=" + this.$stringTimeParseToUnix(endTime) + '&step=' + step); - // }); - // 一个图表的所有element单独获取数据 - axios.all(chartInfo.res).then((res) => { + setTimeout(()=>{ + this.$nextTick(() => { + let res=chartItem.res; console.log(res); if (res.length > 0) { let series = []; @@ -174,6 +174,7 @@ } } else { response.data.result.forEach((queryItem, resIndex) => { + console.log(queryItem, resIndex); let seriesItem = { theData: { name: '', @@ -310,7 +311,7 @@ } } }); - + console.log(this.$refs['editChart' + chartItem.id],chartItem.id); if (this.$refs['editChart' + chartItem.id]) { let chartData = { chartItem: chartItem, @@ -339,6 +340,8 @@ this.$refs['editChart' + chartItem.id].setData(chartItem, series, this.filter.panelId, this.filter, legend, filterType, errorMsg); } else { + console.log(123123123123123123,chartItem, series, + this.filter.panelId, this.filter, legend, '', errorMsg); this.$refs['editChart' + chartItem.id].setData(chartItem, series, this.filter.panelId, this.filter, legend, '', errorMsg); } @@ -382,13 +385,8 @@ } } } - }).catch((error) => { - if (error) { - this.$message.error(error.toString()); - console.error(error) - } }); - }); + },100) } }, }, diff --git a/nezha-fronted/src/components/common/project/topologyL5.vue b/nezha-fronted/src/components/common/project/topologyL5.vue index 13d45ebbe..f30ce14b2 100644 --- a/nezha-fronted/src/components/common/project/topologyL5.vue +++ b/nezha-fronted/src/components/common/project/topologyL5.vue @@ -9,10 +9,12 @@ - +
- + @@ -35,15 +37,15 @@ + class="avatar-uploader" + action=" " + :show-file-list="false" + :on-success="handleAvatarSuccess" + :before-upload="beforeAvatarUpload" + :auto-upload="true" + list-type="picture-card" + style="width: 284px;height: 30px" + > Upload custom picture @@ -53,11 +55,12 @@ -
+
+ :popper-append-to-body="false" + @change="changeTopologyOpt(lineName,'lineName')">
@@ -175,13 +178,13 @@
- - - - - - - + + + + + + +
@@ -425,41 +428,44 @@ this.getTopologyData().then((data)=>{ this.openTopologyData(data).then(()=>{ //获取对应的值 给节点 连线添加对应动画 - console.log(data); this.lineName=data.lineName?data.lineName:this.lineName; this.chartGetData=[]; let axiosArr=[]; + let promiseArr=[]; + let self=this; + let pensPromise=(pen, arr,index)=>{ + return new Promise(function(resolve, reject) { + Promise.all(arr).then((res)=>{ + self.chartGetData[index].res=self.computeData(res,pen.data.aggregation,pen); + self.setAnimation(pen,self.chartGetData[index].res); + resolve() + }); + }); + }; let endTime=this.filterTime[1]; let startTime=this.filterTime[0]; let step=bus.getStep(startTime,endTime); - data.pens&&data.pens.forEach(item=>{ - console.log(item.id); + data.pens&&data.pens.forEach((item,index)=>{ this.chartGetData.push({id:item.id,res:[]}); let arr=item.data.expressArr.map((ele)=>{ let query=encodeURIComponent(ele); + if(!query){ + return new Promise(resolve=>{ + resolve({data:"",status:'no query'}); + }) + } query+='&nullType='+'connected'; return this.$get('/prom/api/v1/query_range?query='+query+"&start="+this.$stringTimeParseToUnix(startTime)+"&end="+this.$stringTimeParseToUnix(endTime)+'&step='+step); }); axiosArr.push({item,arr}); + promiseArr.push(pensPromise(item,arr,index)) }); - - axios.all(axiosArr).then(all=>{ - all.forEach((obj,index)=>{ - this.chartGetData[index].res=obj.arr; - if(obj.item.type===0){// 判断valueMapping 给相应的状态 - // obj.item.animateType='warning'; - if(obj.item.animateType){ - onChangeAnimate(obj.item,obj.item.animateType) - } - }else if(obj.item.type===1){// 判断valueMapping 给相应的状态 - // onChangeAnimateLine(obj.item,'beads') - } - }) - }).then(()=>{ + Promise.all(promiseArr).then((res)=>{ getTopology(this.topologyIndex).open(data); getTopology(this.topologyIndex).lock(1); }); + this.getNodesArr(); }) }); @@ -469,41 +475,44 @@ this.getTopologyData().then((data)=>{ this.openTopologyData(data).then(()=>{ //获取对应的值 给节点 连线添加对应动画 - console.log(data); this.lineName=data.lineName?data.lineName:this.lineName; this.chartGetData=[]; let axiosArr=[]; + let promiseArr=[]; + let self=this; + let pensPromise=(pen, arr,index)=>{ + return new Promise(function(resolve, reject) { + Promise.all(arr).then((res)=>{ + self.chartGetData[index].res=self.computeData(res,pen.data.aggregation,pen); + self.setAnimation(pen,self.chartGetData[index].res); + resolve() + }); + }); + }; let endTime=this.filterTime[1]; let startTime=this.filterTime[0]; let step=bus.getStep(startTime,endTime); - data.pens&&data.pens.forEach(item=>{ - console.log(item.id); + data.pens&&data.pens.forEach((item,index)=>{ this.chartGetData.push({id:item.id,res:[]}); let arr=item.data.expressArr.map((ele)=>{ let query=encodeURIComponent(ele); + if(!query){ + return new Promise(resolve=>{ + resolve({data:"",status:'no query'}); + }) + } query+='&nullType='+'connected'; return this.$get('/prom/api/v1/query_range?query='+query+"&start="+this.$stringTimeParseToUnix(startTime)+"&end="+this.$stringTimeParseToUnix(endTime)+'&step='+step); }); axiosArr.push({item,arr}); + promiseArr.push(pensPromise(item,arr,index)) }); - - axios.all(axiosArr).then(all=>{ - all.forEach((obj,index)=>{ - this.chartGetData[index].res=obj.arr; - if(obj.item.type===0){// 判断valueMapping 给相应的状态 - // obj.item.animateType='warning'; - if(obj.item.animateType){ - onChangeAnimate(obj.item,obj.item.animateType) - } - }else if(obj.item.type===1){// 判断valueMapping 给相应的状态 - // onChangeAnimateLine(obj.item,'beads') - } - }) - }).then(()=>{ + Promise.all(promiseArr).then((res)=>{ getTopology(this.topologyIndex).open(data); getTopology(this.topologyIndex).lock(1); }); + this.getNodesArr(); }) }); @@ -527,12 +536,165 @@ getTopologyData(){ return new Promise(resolve=>{ let data=localStorage.getItem('data'); - data=data?JSON.parse(data):{bkColor:'#FFFFFF',gridSize:10,gridColor:'#ededed',lineWidth:1,ruleColor:"#4e4e4e"}; + data=data?JSON.parse(data):{ + bkColor:'#FFFFFF', + gridSize:10, + gridColor:'#ededed', + lineWidth:1, + ruleColor:"#4e4e4e" + }; this.saveData={...data}; resolve(data); }); }, + //赋值动画 + setAnimation(pen,res){// 根据所有res的状态 赋值动画 + let maxLevel=0; + if(res.length>0){ + res.forEach((response,innerPos)=>{ + if(response.status!=='success'){ + return + } + if (response.data.result) { + response.data.result.forEach((queryItem, resIndex) => { + queryItem.showValue=9; + pen.data.valueMapping.forEach((item,index)=>{ + if(item.value==='base'){return} + if( queryItem.showValue >item.value){ + queryItem.level=item.level; + if(maxLevelitem.level===maxLevel); + onChangeAnimate(pen,selLevel.animateType,selLevel.color.fill,selLevel.color.line); + pen.font.color=selLevel.color.text; + }else if(pen.type===1){// 判断valueMapping 给相应的状态 + let selLevel=pen.data.valueMapping.find(item=>item.level===maxLevel); + pen.animateColor=selLevel.color.fill; + pen.strokeStyle=selLevel.color.line; + pen.animateType=selLevel.animateType; + onChangeAnimateLine(pen,pen.animateType); + pen.font.color=selLevel.color.text; + } + } else { + if(pen.type===0&&pen.animatePlay){// 判断valueMapping 给相应的状态 + onChangeAnimate(pen,pen.animateType); + }else if(pen.type===1&&pen.animatePlay){// 判断valueMapping 给相应的状态 + onChangeAnimateLine(pen,pen.animateType); + } + } + }, + computeData(res,type,pen){//处理别名 以及 根据type显示对应的值 + if(res.length>0){ + res.forEach((response,innerPos)=>{ + if(response.status!=='success'){ + return + } + + if (response.data.result) { + response.data.result.forEach((queryItem, resIndex) => { + // 图表中每条线的名字,后半部分 + let host = '';//up, + if (queryItem.metric.__name__) { + host = `${queryItem.metric.__name__}{`;//up, + } + const tagsArr = Object.keys(queryItem.metric);//["__name__","asset","idc","instance","job","module","project"] + // 设置时间-数据格式对 + let tempArr = []; + let dpsArr = []; + tempArr = queryItem.values; + dpsArr = Object.entries(queryItem.values);//[ ["0",[1577959830.781,"0"]], ["1",[1577959845.781,"0"]] ] + dpsArr = dpsArr.map(item => { + return [item[0], [item[1][0], Number(item[1][1])]] + }); + // 判断是否有数据, && tagsArr.length > 0 + if (dpsArr.length) { + tagsArr.forEach((tag, i) => { + if (tag !== '__name__') { + host += `${tag}="${queryItem.metric[tag]}",`; + } + }); + if (host.endsWith(',')) { + host = host.substr(0, host.length - 1); + } + if (queryItem.metric.__name__) { + host += "}"; + } + if (!host || host === '') { + host = pen.data.expressArr[innerPos]; + } + //处理legend别名 + let alias = this.dealLegendAlias(host, pen.data.legends[innerPos]); + if (!alias || alias === '') { + alias = host; + } + queryItem.legend={name: host+"-"+pen.data.legends[innerPos]+"-" + resIndex, alias: alias}; + queryItem.showValue=this.getMetricTypeValue(queryItem,type); + // 图表中每条线的名字,去掉最后的逗号与空格:metric名称, 标签1=a,标签2=c + } + }); + } + + }) + } + return res + }, + dealLegendAlias:function(legend,expression){ + if(/\{\{.+\}\}/.test(expression)){ + let labelValue=expression.replace(/(\{\{.+?\}\})/g,function(i){ + let label=i.substr(i.indexOf('{{')+2,i.indexOf('}}')-i.indexOf('{{')-2); + let reg=new RegExp(label+'=".+?"'); + let value=null; + if(reg.test(legend)){ + let find=legend.match(reg)[0]; + value=find.substr(find.indexOf('"')+1,find.lastIndexOf('"')-find.indexOf('"')-1); + } + return value?value:label; + }); + return labelValue + }else{ + return expression; + } + }, + getMetricTypeValue(queryItem,type){ + let copy=''; + copy=JSON.parse(JSON.stringify(queryItem.values)); + switch (type) { + case 'min': + let min =copy.sort((x,y)=>{return parseFloat(x[1]) - parseFloat(y[1])})[0][1]; + return min; + case 'max': + let max =copy.sort((x,y)=>{return parseFloat(y[1]) - parseFloat(x[1])})[0][1]; + return max; + case 'avg': + copy = copy.map(t=>parseFloat(t[1])); + let sum = eval(copy.join('+')); + let avg = sum / copy.length; + return avg; + case 'last': + let last =copy.sort((x,y)=>{return parseFloat(y[0]) - parseFloat(x[0])})[0][1]; + return last; + case 'first': + let first =copy.sort((x,y)=>{return parseFloat(y[0]) - parseFloat(x[0])})[copy.length][1]; + return first; + case 'total': + copy = copy.map(t=>parseFloat(t[1])); + let total = eval(copy.join('+')); + return total; + } + }, //获取module getModule(){ this.projectInfo.loading=true; @@ -658,13 +820,14 @@ }, onMessage(event,data){ - console.log('onMessage',event,data); - console.log(getTopology(this.topologyIndex)) + // console.log('onMessage',event,data); + // console.log(getTopology(this.topologyIndex)) if(getTopology(this.topologyIndex)){ this.cachesIndex=getTopology(this.topologyIndex).caches.index; if(this.$refs.topTool){ this.$refs.topTool.redoFlag=false - }; + } + ; } if(!Array.isArray(data)&&data){//判断不是数组 提前个data配置好节点属性 if(data.type===0&& !data.data){ @@ -679,7 +842,17 @@ lineWidth:this.nodeDefaultWidth(data.name), iconToolState:true, //chart 配置项 - valueMapping:[], + valueMapping:[{ + color:{ + line:'#000000', + fill:'#ffffff', + text:'#000000', + }, + value:'base', + animateType:'base', + level:0, + base:true, + }], expressArr:[], legends:[], tooltipShow:true, @@ -703,7 +876,17 @@ toArrowColor:data.toArrowColor, lineWidth:1, //chart 配置项 - valueMapping:[], + valueMapping:[{ + color:{ + border:'#000000', + bac:'#ffffff', + text:'#000000', + }, + value:'base', + animateType:'base', + level:0, + base:true, + }], expressArr:[], legends:[], tooltipShow:true, @@ -721,11 +904,6 @@ data.lineWidth=data.data.lineWidth; } } - - - // if(event==='addNode'&&data.name==='rectangleImg'){ - // data.lineWidth=0; - // } switch(event){ case 'moveInNode': case 'moveInLine': @@ -734,7 +912,6 @@ this.timer3=null } this.chartData={...data.data,...this.chartGetData.find(item=>item.id===data.id)}; - console.log(this.chartData); this.tooltipPosition.show=true; break; case 'moveOutNode': @@ -1102,6 +1279,7 @@ item.fillStyle=item.data.fillStyle; item.strokeStyle=item.data.strokeStyle; item.animatePlay=item.data.animatePlay; + item.font.color="#000000"; }else if(item.type===1){ item.animateColor=item.data.animateColor; item.strokeStyle=item.data.strokeStyle; @@ -1109,6 +1287,7 @@ item.fromArrowColor=item.data.fromArrowColor; item.toArrowColor=item.data.toArrowColor; item.animatePlay=item.data.animatePlay; + item.font.color="#000000"; } }) let domRect=document.getElementById('topology-canvas').getBoundingClientRect(); @@ -1229,23 +1408,26 @@ }