diff --git a/nezha-fronted/src/components/charts/chart-alert-list.vue b/nezha-fronted/src/components/charts/chart-alert-list.vue index 8a80f8ea5..a44acad28 100644 --- a/nezha-fronted/src/components/charts/chart-alert-list.vue +++ b/nezha-fronted/src/components/charts/chart-alert-list.vue @@ -2,7 +2,7 @@ @import './chart.scss'; - + @@ -242,6 +242,7 @@ chartContainerId = 'chartAlertListPreview'; } + console.log('previewChart',this.chart,chartContainerId) //设置高度 chart-table this.$nextTick(() => { //const chartBox = document.getElementById('chartPreviewDailog'); @@ -263,6 +264,7 @@ tableBox.style.height = `${height-this.titleHeight-this.pageHeight-25}px`;//-75-32+25 }else{ const chartDiv = document.getElementById(chartContainerId); + console.log('container div',chartDiv) chartDiv.style.height = `${height-this.chartSpaceHeight-this.titleHeight-15}px`; } }); diff --git a/nezha-fronted/src/components/charts/d3-line-chart2.vue b/nezha-fronted/src/components/charts/d3-line-chart2.vue deleted file mode 100644 index d70cb36de..000000000 --- a/nezha-fronted/src/components/charts/d3-line-chart2.vue +++ /dev/null @@ -1,130 +0,0 @@ - - - - - diff --git a/nezha-fronted/src/components/charts/d3-line.js b/nezha-fronted/src/components/charts/d3-line.js deleted file mode 100644 index ebc02a5a0..000000000 --- a/nezha-fronted/src/components/charts/d3-line.js +++ /dev/null @@ -1,638 +0,0 @@ -import * as d3 from "d3"; -import './d3-line.scss' -import {randomcolor} from "../common/js/radomcolor/randomcolor"; - -export function D3LineChart(selector,option){ - return { - selector:selector, //选择器 - width:option.width, - height:option.height, - timeFormat:option.timeFormat?option.timeFormat:'%Y-%m-%d', - _timeFormat:null, - datas:option.datas, - legends:option.legends, - title:option.title?option.title:'', - subTitle:option.subTitle?option.subTitle:'', - colors:option.colors, - padding:option.padding?option.padding:{top:40,left:40,bottom:40,right:20}, - duration:option.duration?option.duration:800, - _head_height:0, - _foot_height:0, - currentLineNum:0, - showXAxisTick:option.showXAxisTick?option.showXAxisTick:false, - showYAxisTick:option.showYAxisTick?option.showYAxisTick:false, - tooltipFormatter:option.tooltipFormatter, - - init:function(){ - let $self=this; - //定义画布 - this.svg=d3.select(this.selector) - .append('svg') - .attr('width',this.width) - .attr('height',this.height) - .on('mouseover',function(){ - if ($self.tooltip) $self.tooltip.style('display', null); - if ($self.tooltipLine) $self.tooltipLine.attr('stroke', 'orange'); - $self.svg.style('cursor','crosshair') - }) - .on('mousemove', drawTooltip) - .on('mouseout', removeTooltip); - - this.initOption(); - this.constomAction(); - - this.drawTitle(); - this.creatScale(); - this.createDefs(); - this.createXInnerBar(); - this.createYInnderBar(); - this.createXAxis(); - this.createYAxis(); - - // this.createLegends(); - this.drawLines(); - - this.createZoom() - - let oldToolVal=null; - function removeTooltip() { - if ($self.tooltip) $self.tooltip.style('display', 'none'); - if ($self.tooltipLine) $self.tooltipLine.attr('stroke', 'none'); - } - function drawTipLine(time){ - if ($self.currentTransform) - $self.tooltipLine - .style('stroke-width','1') - .attr("clip-path", "url(#clip)") - .attr('x1', $self.currentTransform.applyX($self.xScale(time))) - .attr('x2', $self.currentTransform.applyX($self.xScale(time))) - .attr('y1', $self._head_height) - .attr('y2', $self.height - $self._foot_height); - else - $self.tooltipLine - .style('stroke-width','1') - .attr("clip-path", "url(#clip)") - .attr('x1', $self.xScale(time)) - .attr('x2', $self.xScale(time)) - .attr('y1', $self._head_height) - .attr('y2', $self.height - $self._foot_height); - } - function drawLineDot(){ - - } - function drawTooltip(){ - var x=d3.mouse($self.svg.node())[0]; - if(x<$self.padding.left||x>$self.width-$self.padding.right){ - return false; - } - if ($self.currentTransform) - var time = $self.currentTransform.rescaleX($self.xScale).invert(d3.mouse($self.svg.node())[0]); - else - var time = $self.xScale.invert(d3.mouse($self.svg.node())[0]); - - drawTipLine(time) - - $self.tooltip.html(d3.timeFormat('%Y-%m-%d %H:%M:%S')(time)) - .style('left', d3.event.pageX + 20 + 'px') - .style('top', d3.event.pageY - 20 + 'px') - .selectAll() - .data($self.datas).enter() - .append('div') - .html(function(d, i,g) { - let toolVal=d[0]; - let min=Math.abs(+toolVal[0] - +time ) - d.forEach(item=>{ - let temp=Math.abs(+item[0] - +time) - if(temp - min < 0){ - min=temp; - toolVal=item; - } - }) - if(toolVal){ - oldToolVal=toolVal; - let legend=$self.legends[i]; - if(!legend.isGray){ - return `
-
${legend.alias?legend.alias:legend.name}:
-
${toolVal[1]}
-
` - } - } - }); - } - }, - initOption:function(){ - this._timeFormat=d3.timeFormat(this.timeFormat) - this._head_height=this.padding.top - this._foot_height=this.padding.bottom - this.currentLineNum=this.datas.length; - this.tooltip = d3.select('body') - .append('div') - .attr('style',"position: absolute; background-color: rgba(221,228,237,1);border-color:rgba(221,228,237,1); padding: 5px; display: none; left: 983px; top: 89px;") - this.tooltipLine = this.svg.append('line'); - - this.dotBox = this.svg.append('g') - - this.minMax=getMinMax(this.datas); - - if(this.padding.left < computeDistance(this.minMax.max+'')){ - this.padding.left = computeDistance(this.minMax.max+'') - } - - if(!this.colors || this.colors.length{return d[1]})]) - min=d3.min([min,d3.min(arr[i],d=>{return d[1]})]) - } - return{min:min,max:max} -} -function computeDistance(str){ - var width = 0; - var html = document.createElement('span'); - html.innerText = str; - html.className = 'getTextWidth'; - document.querySelector('body').appendChild(html); - width = document.querySelector('.getTextWidth').offsetWidth; - document.querySelector('.getTextWidth').remove(); - return Number((width+5)); -} - -function CrystalLineObject(chart) { - this.group = null; - this.path = null; - this.oldData = []; - let dataset=chart.datas; - let svg=chart.svg; - let xScale=chart.xScale; - let yScale=chart.yScale; - let lineColor=chart.colors; - const dispatch=chart.dispatch; - - this.init = function(id) { - var arr = dataset[id]; - let legend=chart.legends[id]; - this.group = svg.append("g"); - let $self=this; - var line = d3.line() - .x(function(d, i) { - return xScale(d[0]); - }) - .y(function(d) { - return yScale(d[1]); - }) - .curve(d3.curveCatmullRom.alpha(0.3)); //折线曲度 - - //添加折线 - this.path = this.group.append("path") - .attr("d", line(arr)) - .attr('class','chart-line') - .style("fill", "none") - .style("stroke-width", 1) - .attr("clip-path", "url(#clip)") - .style("stroke", lineColor[id]) - .style("stroke-opacity", 0.9) - .on('line-single-show',function(d,i,group){ - let event=d3.event; - let name=event.detail?event.detail.name:"" - if(legend.name != name){ - $self.group - .transition() - .duration(chart.duration) - .style('opacity','0') - legend.isGray=true; - }else{ - $self.group.transition() - .duration(chart.duration).style('opacity','1') - legend.isGray=false; - } - }) - .on('line-all-show',function(){ - $self.group.transition() - .duration(chart.duration).style('opacity','1') - chart.legends.forEach(item=>{ - item.isGray=false; - }) - }) - - //添加系列的小圆点 - /*this.group.selectAll("circle") - .data(arr) - .enter() - .append("circle") - .attr("clip-path", "url(#clip)") - .attr("cx", function(d, i) { - return xScale(d[0]); - }) - .attr("cy", function(d) { - return yScale(d[1]); - }) - .attr("r", 2) - .attr("fill", lineColor[id]);*/ - this.oldData = arr; - }; - - this.scale = function(id, _duration, transform) { - var arr = dataset[id]; - - var line = d3.line() - .x(function(d, i) { - - return transform.applyX(xScale(d[0])) - }) - .y(function(d) { - return yScale(d[1]); - }) - - //添加折线 - this.group.select("path") - .attr("d", line(arr)) - .style("fill", "none") - .style("stroke-width", 1) - .style("stroke", lineColor[id]) - .style("stroke-opacity", 0.9); - - this.group.selectAll("circle") - .attr("cx", function(d, i) { - return transform.applyX(xScale(d[0])); - }) - .attr("cy", function(d) { - return yScale(d[1]); - }) - - } - - //动画初始化方法 - this.movieBegin = function(id) { - var arr = dataset[id]; - //补足/删除路径 - var olddata = this.oldData; - var line = d3.line() - .x(function(d, i) { - if (i >= olddata.length) return chart.width - chart.padding.left; - else return xScale(d[0]); - }) - .y(function(d, i) { - if (i >= olddata.length) return chart.height - chart._foot_height; - else return yScale(olddata[i].value); - }); - - //路径初始化 - this.path.attr("d", line(arr)); - - //截断旧数据 - var tempData = olddata.slice(0, arr.length); - /*var circle = this.group.selectAll("circle").data(tempData); - - //删除多余的圆点 - circle.exit().remove();*/ - - //圆点初始化,添加圆点,多出来的到右侧底部 - /*this.group.selectAll("circle") - .data(arr) - .enter() - .append("circle") - .attr("cx", function(d, i) { - if (i >= olddata.length) return chart.width - chart.padding; - else return xScale(d[0]); - }) - .attr("cy", function(d, i) { - if (i >= olddata.length) return chart.height - chart._foot_height; - else return yScale(d[1]); - }) - .attr("r", 5) - .attr("fill", lineColor[id]);*/ - - this.oldData = arr; - }; - - //重绘加动画效果 - this.reDraw = function(id, _duration) { - var arr = dataset[id]; - var line = d3.line() - .x(function(d, i) { - return xScale(d[0]); - }) - .y(function(d) { - return yScale(d[1]); - }); - - //路径动画 - this.path.transition().duration(_duration).attr("d", line(arr)); - - //圆点动画 - /* this.group.selectAll("circle") - .transition() - .duration(_duration) - .attr("cx", function(d, i) { - return xScale(d[0]); - }) - .attr("cy", function(d) { - return yScale(d[1]); - })*/ - }; - - //从画布删除折线 - this.remove = function() { - this.group.remove(); - }; - -} diff --git a/nezha-fronted/src/components/charts/d3-line.scss b/nezha-fronted/src/components/charts/d3-line.scss deleted file mode 100644 index c2b5c5283..000000000 --- a/nezha-fronted/src/components/charts/d3-line.scss +++ /dev/null @@ -1,72 +0,0 @@ -.chart{ - position: relative; -} -.title { - font-family: Arial, 微软雅黑; - font-size: 18px; - text-anchor: middle; -} - -.subTitle { - font-family: Arial, 宋体; - font-size: 12px; - text-anchor: middle; - fill: #666 -} - -.axis path, -.axis line { - fill: none; - stroke: black; - shape-rendering: crispEdges; -} - -.axis text { - font-family: sans-serif; - font-size: 11px; - fill: #999; -} - -.inner_line path, -.inner_line line { - fill: none; - stroke: #ccc; - shape-rendering: crispEdges; - opacity: .5; -} - -.legend { - font-size: 12px; - font-family: Arial, Helvetica, sans-serif; - text-align:left; - max-height:80px; - min-height:25px; - left: 10px; - line-height: 18px; - position: absolute; - padding-bottom:3px; -} - -.legend-shape{ - display:inline-block; - margin-right:5px; - border-radius:10px; - width:15px; - height:5px; - vertical-align: middle; -} -.ft-gr{ - color:lightgray; -} - -.legend-item{ - text-overflow:ellipsis; - white-space:nowrap; - /*width:100%;*/ - margin-right:10px; - overflow-x:hidden; - cursor:pointer; - display:inline-block; - float:left; - line-height: 20px; -} diff --git a/nezha-fronted/src/components/common/leftMenu.vue b/nezha-fronted/src/components/common/leftMenu.vue index e8d395b18..7bac5c227 100644 --- a/nezha-fronted/src/components/common/leftMenu.vue +++ b/nezha-fronted/src/components/common/leftMenu.vue @@ -431,7 +431,6 @@ bus.$emit("asset-filter-change", "typeIds", assetTypeIds); }else{ bus.$emit("asset-filter-change", "typeIds", ""); - this.pageObj.typeIds=''; } }, changeVendorCheckBox() { diff --git a/nezha-fronted/src/components/page/dashboard/chartBox.vue b/nezha-fronted/src/components/page/dashboard/chartBox.vue index 3ce4e1502..53dcd181e 100644 --- a/nezha-fronted/src/components/page/dashboard/chartBox.vue +++ b/nezha-fronted/src/components/page/dashboard/chartBox.vue @@ -117,7 +117,7 @@ - + span-{{item}} @@ -141,7 +141,7 @@ - + @@ -193,8 +193,8 @@ - - {{item.name}} + + {{item.label}} @@ -577,7 +577,7 @@ }); } } - + console.log('save chart',params) let intervalTime = 1; //设置3秒超时 let interval = setInterval(() => { @@ -695,6 +695,7 @@ }, getAlertParam:function(param,opType){ this.$refs.chartForm.validate((valid) => { + console.log('valid',valid,param,opType) const params = { title: this.editChart.title,//this.editChart span: this.editChart.span, @@ -702,7 +703,7 @@ type: this.editChart.type, unit:this.editChart.unit, param:param, - sync: this.editChart.sync + sync: this.editChart.sync, }; if (valid) { if(opType==='preview') { @@ -732,6 +733,10 @@ item.saveTarget(index); }); }*/ + if(this.editChart.type == 'alertList'){ + this.$refs.alertParamBox.saveParam(); + return ; + } if(this.editChart.type == 'singleStat'){ this.$set(this.editChart.param, "statistics", this.statistics); } else { @@ -1112,6 +1117,7 @@ }, //preview--end initElements() { + console.log('statisticsList',this.statisticsList) if (!this.editChart.elements || this.editChart.elements.length == 0) { this.editChart.elements = [{expression: "", legend: "", type: "expert", id: ""}]; }