From d5ce81026882ada34e5d49411be7c90ee96cc102 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 17 一月 2023 18:20:11 +0800
Subject: [PATCH] 2023-01-17

---
 src/menu/components/chart/antv-G6/index.jsx |  105 ++++++++++++++++++++++------------------------------
 1 files changed, 44 insertions(+), 61 deletions(-)

diff --git a/src/menu/components/chart/antv-G6/index.jsx b/src/menu/components/chart/antv-G6/index.jsx
index 2900881..82d8bf3 100644
--- a/src/menu/components/chart/antv-G6/index.jsx
+++ b/src/menu/components/chart/antv-G6/index.jsx
@@ -60,7 +60,8 @@
   purple: '#722ed1',
   magenta: '#eb2f96',
   grass_green: '#aeb303',
-  deep_red: '#c32539'
+  deep_red: '#c32539',
+  deep_blue: '#1d3661'
 }
 
 let systemColor = '#1890ff'
@@ -93,29 +94,7 @@
   },
   'single-node',
 )
-G6.registerNode(
-  'dice-mind-map-sub', {
-    jsx: (cfg) => {
-      const width = Util.getTextSize(cfg.label, 14)[0] + 24
 
-      return `
-        <group>
-          <rect style={{width: ${width}, height: 22, cursor: pointer}}>
-            <text style={{ fontSize: 14, fill: ${cfg.selected ? systemColor : '#000000'}, marginLeft: 12, marginTop: 6, cursor: pointer }}>${cfg.label}</text>
-          </rect>
-          <rect style={{ fill: ${cfg.color}, width: ${width}, height: 2, x: 0, y: 22, cursor: pointer }} />
-        </group>
-      `
-    },
-    getAnchorPoints() {
-      return [
-        [0, 0.965],
-        [1, 0.965]
-      ]
-    }
-  },
-  'single-node',
-)
 G6.registerNode(
   'dice-mind-map-leaf', {
     jsx: (cfg) => {
@@ -203,38 +182,6 @@
     ev.preventDefault()
   }
 })
-
-const dataMapTransform = (data) => {
-  const changeData = (d, level = 0, color) => {
-    const data = { ...d }
-
-    switch (level) {
-      case 0:
-        data.type = 'dice-mind-map-root'
-        break
-      case 1:
-        data.type = 'dice-mind-map-sub'
-        break
-      default:
-        data.type = 'dice-mind-map-leaf'
-        break
-    }
-
-    if (color) {
-      data.color = color
-    }
-
-    if (level === 1 && !d.direction) {
-      data.direction = 'right'
-    }
-
-    if (d.children) {
-      data.children = d.children.map((child) => changeData(child, level + 1, data.color))
-    }
-    return data
-  }
-  return changeData(data)
-}
 
 // 缂╄繘鏂囦欢鏍�
 G6.registerNode('indentedRoot', {
@@ -1137,9 +1084,27 @@
         if (item.direction === 'left') {
           item.color = card.plot.leftColor || '#26C281'
         } else {
+          item.direction = 'right'
           item.color = card.plot.nodeColor || '#1890ff'
         }
       })
+
+      data.collapsed = false
+      data.type = 'dice-mind-map-root'
+
+      const collapse = (item) => {
+        if (!item.children) return
+
+        item.children.forEach(cell => {
+          cell.collapsed = card.plot.collapsed === 'true'
+          cell.direction = cell.direction || 'right'
+          cell.type = 'dice-mind-map-leaf'
+          cell.color = cell.color || item.color
+          collapse(cell)
+        })
+      }
+
+      collapse(data)
     } else if (card.plot.subtype === 'indentTree') {
       data.isRoot = true
       data.collapsed = false
@@ -1184,11 +1149,12 @@
     const { card } = this.state
     const plot = card.plot
     const data = this.getdata()
+    const height = getHeight(plot.height)
 
     const graph = new G6.TreeGraph({
       container: card.uuid + 'canvas',
       width: this.wrap.scrollWidth - 30,
-      height: getHeight(plot.height),
+      height: height,
       modes: {
         default: [
           {
@@ -1235,6 +1201,10 @@
     graph.data(data)
     graph.render()
     graph.fitView()
+
+    if (plot.collapsed === 'true') {
+      graph.zoomTo(1, { x: 0, y: height / 2 })
+    }
   }
 
   indentrender = () => {
@@ -1306,11 +1276,18 @@
     const { card } = this.state
     const plot = card.plot
     const data = this.getdata()
+    const width = this.wrap.scrollWidth - 30
+    const height = getHeight(plot.height)
+    let modes = ['drag-canvas', 'zoom-canvas', 'dice-mindmap']
+
+    if (plot.collapsed === 'true') {
+      modes = [{ type: 'collapse-expand' },'drag-canvas', 'zoom-canvas', 'dice-mindmap']
+    }
 
     const tree = new G6.TreeGraph({
       container: card.uuid + 'canvas',
-      width: this.wrap.scrollWidth - 30,
-      height: getHeight(plot.height),
+      width: width,
+      height: height,
       fitView: true,
       layout: {
         type: 'mindmap',
@@ -1341,13 +1318,19 @@
       },
       minZoom: 0.5,
       modes: {
-        default: ['drag-canvas', 'zoom-canvas', 'dice-mindmap']
+        default: modes
       }
     })
 
-    tree.data(dataMapTransform(data))
-
+    tree.data(data)
+    
     tree.render()
+
+    if (plot.collapsed === 'true' && plot.dirField) {
+      tree.zoomTo(1, { x: width / 2, y: height / 2 })
+    } else if (plot.collapsed === 'true') {
+      tree.zoomTo(1, { x: 0, y: height / 2 })
+    }
   }
 
   updateComponent = (card) => {

--
Gitblit v1.8.0