Karsa 1 year ago
parent
commit
43720d202f
1 changed files with 46 additions and 38 deletions
  1. 46 38
      src/hooks/chart/render.js

+ 46 - 38
src/hooks/chart/render.js

@@ -205,47 +205,55 @@ function setAxisPlotLines(axis,axisType) {
 
 
 /* 处理标识区拼接 axisType表示x轴类型处理时间轴的值 datetime/null */
 /* 处理标识区拼接 axisType表示x轴类型处理时间轴的值 datetime/null */
 function setAxisPlotAreas(axis,axisType) {
 function setAxisPlotAreas(axis,axisType) {
-const { MarkersAreas,ChartType } = chartData.value.ChartInfo;
-if(!MarkersAreas) return []
-
-let markerAreas = JSON.parse(MarkersAreas);
-
-let arr = markerAreas.filter(_ => _.isShow&&_.axis===axis)
-let plotBands = arr.map(_ => {
-    //是否是x时间轴
-    let isXDateAxis = axis===3&&axisType==='datetime';
-    let fromMarkerValue,toMarkerValue;
-    if(isXDateAxis) {
-        //季节图x轴额外拼个年份
-        let nowYear = new Date().getFullYear();
-        fromMarkerValue = ChartType===2 
-            ? new Date(`${nowYear}-${_.fromValue}`).getTime()
-            : new Date(_.fromValue).getTime()
-
-        toMarkerValue = ChartType===2 
-            ? new Date(`${nowYear}-${_.toValue}`).getTime()
-            : new Date(_.toValue).getTime()
-    }else {
-        fromMarkerValue = Number(_.fromValue);
-        toMarkerValue = Number(_.toValue);
-    }
+    const { MarkersAreas,ChartType } = chartData.value.ChartInfo;
+    if(!MarkersAreas) return []
+
+    let markerAreas = JSON.parse(MarkersAreas);
 
 
-    return { 
-    from: fromMarkerValue,
-    to: toMarkerValue,
-    color: _.color,
-    label: {
-        text: _.text||'',
-        verticalAlign: _.textPosition,
-        style: {
-        color: _.textColor,
-        fontSize: _.textFontSize
+    let arr = markerAreas.filter(_ => _.isShow&&_.axis===axis)
+    let plotBands = arr.map(_ => {
+        //是否是x时间轴
+        let isXDateAxis = axis===3&&axisType==='datetime';
+        let fromMarkerValue,toMarkerValue;
+        if(isXDateAxis) {
+            //季节图x轴额外拼个年份
+            let nowYear = new Date().getFullYear();
+            fromMarkerValue = ChartType===2 
+                ? new Date(`${nowYear}-${_.fromValue}`).getTime()
+                : new Date(_.fromValue).getTime()
+
+            toMarkerValue = ChartType===2 
+                ? new Date(`${nowYear}-${_.toValue}`).getTime()
+                : new Date(_.toValue).getTime()
+        }else {
+            fromMarkerValue = Number(_.fromValue);
+            toMarkerValue = Number(_.toValue);
         }
         }
-    }
-    }
-})
 
 
-return plotBands
+        //默认label有些偏移 重新归正下
+        let positionMapValue = {
+            'top': 12,
+            'middle': 0,
+            'bottom': -10
+        }
+
+        return { 
+            from: fromMarkerValue,
+            to: toMarkerValue,
+            color: _.color,
+            label: {
+                text: _.text||'',
+                verticalAlign: _.textPosition,
+                y: positionMapValue[_.textPosition],
+                style: {
+                    color: _.textColor,
+                    fontSize: _.textFontSize
+                }
+            }
+        }
+    })
+
+    return plotBands
 }
 }