Explorar o código

优化调整上下限逻辑,兼容季节图、堆积柱状图

cxmo hai 10 meses
pai
achega
984069de14

+ 3 - 3
src/views/dataEntry_manage/addChart.vue

@@ -820,12 +820,12 @@ export default {
 						})
 					)
 					let hasLimitChange = false
-					//如果是 曲线图 堆积柱状图 组合图 需检测上下限是否修改
-					if([1,4,6].includes(this.chartInfo.ChartType)){
+					//需检测上下限是否修改
+					if(![7,10,11].includes(this.chartInfo.ChartType)){
 						const limitSame= this.getLimitInfo()
 						hasLimitChange = !limitSame
 					}
-
+					
 					const { ChartType,ChartName,ChartThemeId,SourcesFrom,Instructions,MarkersLines,MarkersAreas,ChartThemeStyle } = this.chartInfo;
 					let public_param = {
 						ChartClassifyId: this.chartInfo.classify.length ? this.chartInfo.classify[this.chartInfo.classify.length - 1] : 0,

+ 3 - 2
src/views/dataEntry_manage/editChart.vue

@@ -823,6 +823,7 @@ export default {
 					this.chartInfo.ChartType === 11 && this.initRadarData(res.Data);
 					
 					this.getThemeList();
+					//初始化上下限
 					this.setLimitData(this.tableData)
 
         });
@@ -920,8 +921,8 @@ export default {
 					)
 					
 					let hasLimitChange = Boolean(this.chartInfo.MinMaxSave)
-					//如果是 曲线图 堆积柱状图 组合图 需检测上下限是否修改
-					if([1,4,6].includes(this.chartInfo.ChartType)&&!this.chartInfo.MinMaxSave){
+					//需检测上下限是否修改
+					if(![7,10,11].includes(this.chartInfo.ChartType)&&!this.chartInfo.MinMaxSave){
 						const limitSame= this.getLimitInfo()
 						hasLimitChange = !limitSame
 					}

+ 27 - 21
src/views/dataEntry_manage/mixins/addOreditMixin.js

@@ -227,6 +227,7 @@ export default {
 									text: sourceStr
 								});
 							}
+							//新增指标后,检测上下限变化,修改上下限
 							this.EdbAxisChange()
 
 							this.$nextTick(()=>{
@@ -560,6 +561,7 @@ export default {
 			let index = this.tableData.findIndex(obj => obj.EdbInfoId === item.EdbInfoId);
 			this.tableData.splice(index, 1);
 			this.$message.success('删除成功')
+			//删除指标时,检测上下限,修改上下限
 			this.EdbAxisChange()
 			//添加图表时重置默认样式
 			this.$route.path==='/addchart' && this.resetChartEdbDefault();
@@ -937,6 +939,9 @@ export default {
 			//若用户没有修改过,则计算y轴的上下限
 			if(!this.chartInfo.MinMaxSave){
 				this.calcYAxislimit(this.tableData)
+			}else{
+				//若用户修改过,则检测轴的上下限是否为空,若为空,则需要计算对应轴的上下限
+				this.checkLimit(this.tableData)
 			}
 		},
 		//新增/编辑保存图表时-判断用户有没有手动更改过上下限
@@ -949,37 +954,38 @@ export default {
 			if(leftData.length){
 				const {Max,Min} = this.calcLimit(leftData.flat())
 				leftLimitSame = Max===Number(this.leftLimitData[0])&&Min===Number(this.leftLimitData[1])
-                console.table([{
-                    'y轴': '左轴',
-                    '设置最大值': this.leftLimitData[0],
-                    '设置最小值': this.leftLimitData[1],
-                    '指标最大值':Max,
-                    '指标最小值':Min
-                }])
+				console.table([{
+					'y轴': '左轴',
+					'设置最大值': this.leftLimitData[0],
+					'设置最小值': this.leftLimitData[1],
+					'指标最大值':Max,
+					'指标最小值':Min
+				}])
 			}
 			if(rightData.length){
 				const {Max,Min} = this.calcLimit(rightData.flat())
 				rightLimitSame = Max===Number(this.rightLimitData[0])&&Min===Number(this.rightLimitData[1])
-                console.table([{
-                    'y轴': '右轴',
-                    '设置最大值': this.rightLimitData[0],
-                    '设置最小值': this.rightLimitData[1],
-                    '指标最大值':Max,
-                    '指标最小值':Min
-                }])
+				console.table([{
+					'y轴': '右轴',
+					'设置最大值': this.rightLimitData[0],
+					'设置最小值': this.rightLimitData[1],
+					'指标最大值':Max,
+					'指标最小值':Min
+				}])
 			}
 			if(rightTwoData.length){
 				const {Max,Min} = this.calcLimit(rightTwoData.flat())
 				rightTwoLimitSame = Max===Number(this.rightTwoLimitData[0])&&Min===Number(this.rightTwoLimitData[1])
-                console.table([{
-                    'y轴': '右二轴',
-                    '设置最大值': this.rightTwoLimitData[0],
-                    '设置最小值': this.rightTwoLimitData[1],
-                    '指标最大值':Max,
-                    '指标最小值':Min
-                }])
+				console.table([{
+					'y轴': '右二轴',
+					'设置最大值': this.rightTwoLimitData[0],
+					'设置最小值': this.rightTwoLimitData[1],
+					'指标最大值':Max,
+					'指标最小值':Min
+				}])
 			}
 			let limitSame = leftLimitSame&&rightLimitSame&&rightTwoLimitSame
+			console.log('是否修改过上下限?',!limitSame)
 			return limitSame
 		},
 	}

+ 72 - 43
src/views/dataEntry_manage/mixins/chartPublic.js

@@ -597,8 +597,8 @@ export const chartSetMixin = {
         const useTableLimit = ['/predictEdb','/chartThemeSet'].includes(this.$route.path)
         let minLimit = 0,maxLimit = 0
         if(useTableLimit){
-            minLimit = this.tableData[sameSideIndex].MinData
-            maxLimit = this.tableData[sameSideIndex].MaxData
+            minLimit = newval[sameSideIndex].MinData
+            maxLimit = newval[sameSideIndex].MaxData
         }else{
             const limitMap = {
                 0:this.rightLimitData||[],
@@ -787,21 +787,22 @@ export const chartSetMixin = {
         ? -1
         : newval.findIndex((item) => item.IsAxis===2);
 
-        //在添加编辑页,min max为重新计算过的min max 其他页面不管
-        const isCalcLimit = ['/addchart','/editchart'].includes(this.$route.path)
+
+        //获取对应轴的上下限
+        //预测指标-走势图;图表配置-主题设置;不使用自定义上下限,剔除
+        const useTableLimit = ['/predictEdb','/chartThemeSet'].includes(this.$route.path)
         let minLimit = 0,maxLimit = 0
-        //如果该图表没标记过
-        if(isCalcLimit&&!this.chartInfo.hasLimitEdit){
+        if(useTableLimit){
+            minLimit = chartData[sameSideIndex].MinData
+            maxLimit = chartData[sameSideIndex].MaxData
+        }else{
             const limitMap = {
                 0:this.rightLimitData||[],
                 1:this.leftLimitData||[],
                 2:this.rightTwoLimitData||[]
             }
-            if(limitMap[chartData[sameSideIndex].IsAxis]){
-                const arr = limitMap[chartData[sameSideIndex].IsAxis]
-                minLimit = arr[1]||0
-                maxLimit = arr[0]||0
-            }
+            minLimit = limitMap[item.IsAxis][1]||0
+            maxLimit = limitMap[item.IsAxis][0]||0
         }
         
         //y轴
@@ -834,8 +835,8 @@ export const chartSetMixin = {
           },
           opposite: [0,2].includes(item.IsAxis),
           reversed: item.IsOrder,
-          min: (isCalcLimit&&!this.chartInfo.hasLimitEdit)?Number(minLimit):Number(chartData[sameSideIndex].MinData),
-          max: (isCalcLimit&&!this.chartInfo.hasLimitEdit)?Number(maxLimit):Number(chartData[sameSideIndex].MaxData),
+          min: Number(minLimit),
+          max: Number(maxLimit),
           tickWidth: 1,
           visible: serie_yIndex === index && sameSideIndex ===index,
           plotBands: this.setAxisPlotAreas(item.IsAxis),
@@ -932,6 +933,18 @@ export const chartSetMixin = {
       let seasonYdata = [],
         seasonData = [];
 
+        //获取对应轴的上下限
+        //预测指标-走势图;图表配置-主题设置;不使用自定义上下限,剔除
+        const useTableLimit = ['/predictEdb','/chartThemeSet'].includes(this.$route.path)
+        let minLimit = 0,maxLimit = 0
+        if(useTableLimit){
+            minLimit = chartData.MinData
+            maxLimit = chartData.MaxData
+        }else{
+            minLimit = this.leftLimitData[1]||0
+            maxLimit = this.leftLimitData[0]||0
+        }
+
       //数据列
       for (let j of chartDataHandle) {
         //预测指标配置
@@ -982,8 +995,8 @@ export const chartSetMixin = {
           textAlign: 'left',
           reserveSpace: false
         },
-        max: Number(chartData.MaxData),
-        min: Number(chartData.MinData),
+        max: Number(maxLimit),
+        min: Number(minLimit),
         plotBands: this.setAxisPlotAreas(1),
         plotLines: this.setAxisPlotLines(1)
       }];
@@ -1104,6 +1117,18 @@ export const chartSetMixin = {
         this.isSetExtremeValue = false;
       }
 
+      //获取对应轴的上下限
+        //预测指标-走势图;图表配置-主题设置;不使用自定义上下限,剔除
+        const useTableLimit = ['/predictEdb','/chartThemeSet'].includes(this.$route.path)
+        let minLimit = 0,maxLimit = 0
+        if(useTableLimit){
+            minLimit = Math.max(...real_data.map(_ => _.y));
+            maxLimit = Math.min(...real_data.map(_ => _.y));
+        }else{
+            minLimit = this.leftLimitData[1]||0
+            maxLimit = this.leftLimitData[0]||0
+        }
+
       const { IsOrder,ChartColor } = newval[0];
       //y轴
       let yAxis = {
@@ -2699,37 +2724,41 @@ export const chartSetMixin = {
                 this.leftLimitData = [Number(LeftMax),Number(LeftMin)]
                 this.rightLimitData = [Number(RightMax),Number(RightMin)]
                 this.rightTwoLimitData = [Number(Right2Max),Number(Right2Min)]
-                //若轴的上下限均为0,则不管用户有没有修改过,都重新赋值
-                if(this.leftLimitData[0]===0&&this.leftLimitData[1]===0){
-                    const leftData = tableData.filter(i=>i.IsAxis===1).map(i=>[Number(i.MinData),Number(i.MaxData)])
-                    if(leftData.length){
-                        const {Max,Min} = this.calcLimit(leftData.flat())
-                        this.leftLimitData = [Max,Min]
-                    }else{
-                        this.leftLimitData = [0,0]
-                    }
+                //若用户修改过,则检测轴的上下限是否为空,若为空,则需要计算对应轴的上下限
+                this.checkLimit(tableData)
+            }else{
+                this.calcYAxislimit(tableData)
+            }
+        },
+        checkLimit(tableData=[]){
+            //若轴的上下限均为0,则不管用户有没有修改过,都重新赋值
+            if(Number(this.leftLimitData[0])===0&&Number(this.leftLimitData[1])===0){
+                const leftData = tableData.filter(i=>i.IsAxis===1).map(i=>[Number(i.MinData),Number(i.MaxData)])
+                if(leftData.length){
+                    const {Max,Min} = this.calcLimit(leftData.flat())
+                    this.leftLimitData = [Max,Min]
+                }else{
+                    this.leftLimitData = [0,0]
                 }
-                if(this.rightLimitData[0]===0&&this.rightLimitData[1]===0){
-                    const rightData = tableData.filter(i => !i.IsAxis).map(i=>[Number(i.MinData),Number(i.MaxData)])
-                    if(rightData.length){
-                        const {Max,Min} = this.calcLimit(rightData.flat())
-                        this.rightLimitData = [Max,Min]
-                    }else{
-                        this.rightLimitData = [0,0]
-                    }
+            }
+            if(Number(this.rightLimitData[0])===0&&Number(this.rightLimitData[1])===0){
+                const rightData = tableData.filter(i => !i.IsAxis).map(i=>[Number(i.MinData),Number(i.MaxData)])
+                if(rightData.length){
+                    const {Max,Min} = this.calcLimit(rightData.flat())
+                    this.rightLimitData = [Max,Min]
+                }else{
+                    this.rightLimitData = [0,0]
                 }
-                if(this.rightTwoLimitData[0]===0&&this.rightTwoLimitData[1]===0){
-                    const rightTwoData = tableData.filter(i=>i.IsAxis===2).map(i=>[Number(i.MinData),Number(i.MaxData)])
-                    if(rightTwoData.length){
-                        const {Max,Min} = this.calcLimit(rightTwoData.flat())
-                        this.rightTwoLimitData = [Max,Min]
-                    }else{
-                        this.rightTwoLimitData = [0,0]
-                    }
+            }
+            if(Number(this.rightTwoLimitData[0])===0&&Number(this.rightTwoLimitData[1])===0){
+                const rightTwoData = tableData.filter(i=>i.IsAxis===2).map(i=>[Number(i.MinData),Number(i.MaxData)])
+                if(rightTwoData.length){
+                    const {Max,Min} = this.calcLimit(rightTwoData.flat())
+                    this.rightTwoLimitData = [Max,Min]
+                }else{
+                    this.rightTwoLimitData = [0,0]
                 }
-            }else{
-                this.calcYAxislimit(tableData)
             }
-        }
+        },
 	}
 }