From 5cfe6db94c1449810a44660b299dba8e7e98e5c5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 六月 2021 14:43:39 +0800
Subject: [PATCH] 2021-06-10

---
 src/tabviews/custom/components/chart/antv-bar-line/index.jsx |  108 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 86 insertions(+), 22 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx
index 85e467d..8b34453 100644
--- a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx
@@ -1054,6 +1054,27 @@
       nice: true
     })
 
+    let lablecfg = {
+      position: 'top',
+      offset: 2,
+      style: {
+        fill: '#fff'
+      }
+    }
+
+    if (plot.label === 'top') {
+      lablecfg.offset = -5
+      lablecfg.style.textBaseline = 'top'
+    } else if (plot.label === 'middle') {
+      lablecfg.position = 'middle'
+      lablecfg.offset = 0
+    } else if (plot.label === 'bottom') {
+      lablecfg.position = 'bottom'
+      lablecfg.offset = 0
+    } else if (plot.label === 'true') {
+      lablecfg.style.fill = plot.color
+    }
+
     if (plot.Bar_axis) {
       const view1 = chart.createView({
         region: {
@@ -1126,15 +1147,17 @@
           _chart.color('key')
         }
         if (plot.label === 'true') {
-          _chart.label('value', (value) => {
+          _chart.label('value*key', (value, key) => {
             if (plot.show === 'percent') {
               value = value + '%'
             }
+
+            if (plot.label === 'true' && plot.labelColor === 'custom' && plot.$colors && plot.$colors.has(key)) {
+              lablecfg.style.fill = plot.$colors.get(key)
+            }
             return {
               content: value,
-              style: {
-                fill: plot.color
-              }
+              ...lablecfg
             }
           })
         }
@@ -1175,15 +1198,16 @@
           _chart.color('key')
         }
         if (plot.label === 'true') {
-          _chart.label('value', (value) => {
+          _chart.label('value*key', (value, key) => {
             if (plot.show === 'percent') {
               value = value + '%'
             }
+            if (plot.label === 'true' && plot.labelColor === 'custom' && plot.$colors && plot.$colors.has(key)) {
+              lablecfg.style.fill = plot.$colors.get(key)
+            }
             return {
               content: value,
-              style: {
-                fill: plot.color
-              }
+              ...lablecfg
             }
           })
         }
@@ -1236,11 +1260,12 @@
             if (plot.show === 'percent') {
               value = value + '%'
             }
+            if (plot.label === 'true' && plot.labelColor === 'custom' && item.color) {
+              lablecfg.style.fill = item.color
+            }
             return {
               content: value,
-              style: {
-                fill: plot.color
-              }
+              ...lablecfg
             }
           })
         }
@@ -1410,10 +1435,44 @@
       })
     }
 
-    let offset = {offsetY: 5}
+    let lablecfg = {
+      position: 'top',
+      offset: 2,
+      style: {
+        fill: '#fff'
+      }
+    }
+
+    if (plot.label === 'top') {
+      lablecfg.offset = -5
+      lablecfg.style.textBaseline = 'top'
+    } else if (plot.label === 'middle') {
+      lablecfg.position = 'middle'
+      lablecfg.offset = 0
+    } else if (plot.label === 'bottom') {
+      lablecfg.position = 'bottom'
+      lablecfg.offset = 0
+    } else if (plot.label === 'true') {
+      lablecfg.style.fill = plot.color
+    }
+
     if (plot.transpose === 'true') {
       chart.coordinate().transpose()
-      offset = {offsetY: 0, offsetX: -10}
+      if (plot.label === 'top') {
+        delete lablecfg.style.textBaseline
+        lablecfg.position = 'right'
+        lablecfg.offset = -3
+        lablecfg.style.textAlign = 'end'
+      } else if (plot.label === 'middle') {
+        lablecfg.position = 'middle'
+        lablecfg.offset = 0
+      } else if (plot.label === 'bottom') {
+        lablecfg.position = 'left'
+        lablecfg.offset = 2
+      } else if (plot.label === 'true') {
+        lablecfg.position = 'right'
+        lablecfg.offset = 2
+      }
     }
 
     if (plot.coordinate === 'polar') {
@@ -1455,16 +1514,18 @@
         _chart.color(_typefield)
       }
       if (plot.label === 'true') {
-        _chart.label(_valfield, (value) => {
+        _chart.label(`${_valfield}*${_typefield}`, (value, key) => {
           if (plot.show === 'percent') {
             value = value + '%'
           }
+
+          if (plot.label === 'true' && plot.labelColor === 'custom' && plot.$colors && plot.$colors.has(key)) {
+            lablecfg.style.fill = plot.$colors.get(key)
+          }
+
           return {
             content: value,
-            style: {
-              fill: plot.color
-            },
-            ...offset
+            ...lablecfg
           }
         })
       }
@@ -1511,15 +1572,18 @@
         _chart.color(_typefield)
       }
       if (plot.label === 'true') {
-        _chart.label(_valfield, (value) => {
+        _chart.label(`${_valfield}*${_typefield}`, (value, key) => {
           if (plot.show === 'percent') {
             value = value + '%'
           }
+
+          if (plot.label === 'true' && plot.labelColor === 'custom' && plot.$colors && plot.$colors.has(key)) {
+            lablecfg.style.fill = plot.$colors.get(key)
+          }
+
           return {
             content: value,
-            style: {
-              fill: plot.color
-            }
+            ...lablecfg
           }
         })
       }

--
Gitblit v1.8.0