From 0667b630fbaf29ee12d5d332fb6da5c32231cd0f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 06 六月 2023 17:59:38 +0800
Subject: [PATCH] 2023-06-06

---
 src/menu/components/chart/antv-X6/index.jsx |  169 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 119 insertions(+), 50 deletions(-)

diff --git a/src/menu/components/chart/antv-X6/index.jsx b/src/menu/components/chart/antv-X6/index.jsx
index 2cf20cf..c6c84cd 100644
--- a/src/menu/components/chart/antv-X6/index.jsx
+++ b/src/menu/components/chart/antv-X6/index.jsx
@@ -1,8 +1,8 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Popover, Tooltip } from 'antd'
-import { ToolOutlined, DeleteOutlined, FontColorsOutlined, VerticalAlignTopOutlined, VerticalAlignBottomOutlined, SaveOutlined, ZoomInOutlined, ZoomOutOutlined, OneToOneOutlined } from '@ant-design/icons'
+import { Popover, Tooltip, message } from 'antd'
+import { ToolOutlined, DeleteOutlined, FontColorsOutlined, VerticalAlignTopOutlined, VerticalAlignBottomOutlined, SaveOutlined, ZoomInOutlined, ZoomOutOutlined, OneToOneOutlined, DoubleLeftOutlined } from '@ant-design/icons'
 import { Graph, Shape } from '@antv/x6'
 import { Stencil } from '@antv/x6-plugin-stencil'
 import { Transform } from '@antv/x6-plugin-transform'
@@ -248,8 +248,14 @@
 
   state = {
     card: null,
-    eventListener: null
+    eventListener: null,
+    toolunfold: true,
+    nodeunfold: true,
+    node: null
   }
+
+  selectNode = null
+  mkGraph = null
 
   UNSAFE_componentWillMount () {
     const { card } = this.props
@@ -348,14 +354,14 @@
       autoResize: true,
       panning: true,
       background: {
-        color: '#ffffff',
+        color: '#ffffff'
       },
       mousewheel: {
         enabled: true,
         zoomAtMousePosition: true,
         modifiers: 'ctrl',
         minScale: 0.5,
-        maxScale: 5,
+        maxScale: 2
       },
       connecting: {
         router: 'manhattan',
@@ -380,16 +386,16 @@
                 targetMarker: {
                   name: 'block',
                   width: 12,
-                  height: 8,
-                },
-              },
+                  height: 8
+                }
+              }
             },
-            zIndex: 0,
+            zIndex: 0
           })
         },
         validateConnection({ targetMagnet }) {
           return !!targetMagnet
-        },
+        }
       },
       highlighting: {
         magnetAdsorbed: {
@@ -397,21 +403,19 @@
           args: {
             attrs: {
               fill: '#5F95FF',
-              stroke: '#5F95FF',
-            },
-          },
-        },
-      },
+              stroke: '#5F95FF'
+            }
+          }
+        }
+      }
     })
 
     // #region 浣跨敤鎻掍欢
     graph
-      .use(
-        new Transform({
-          resizing: true,
-          rotating: true
-        })
-      )
+      .use(new Transform({
+        resizing: true,
+        rotating: true
+      }))
       .use(new Selection())
       .use(new Snapline())
       .use(new Keyboard())
@@ -502,18 +506,18 @@
     })
 
     // zoom
-    graph.bindKey(['ctrl+1', 'meta+1'], () => {
-      const zoom = graph.zoom()
-      if (zoom < 1.5) {
-        graph.zoom(0.1)
-      }
-    })
-    graph.bindKey(['ctrl+2', 'meta+2'], () => {
-      const zoom = graph.zoom()
-      if (zoom > 0.5) {
-        graph.zoom(-0.1)
-      }
-    })
+    // graph.bindKey(['ctrl+1', 'meta+1'], () => {
+    //   const zoom = graph.zoom()
+    //   if (zoom < 1.5) {
+    //     graph.zoom(0.1)
+    //   }
+    // })
+    // graph.bindKey(['ctrl+2', 'meta+2'], () => {
+    //   const zoom = graph.zoom()
+    //   if (zoom > 0.5) {
+    //     graph.zoom(-0.1)
+    //   }
+    // })
 
     // 鎺у埗杩炴帴妗╂樉绀�/闅愯棌
     const showPorts = (ports, show) => {
@@ -533,18 +537,29 @@
     })
 
     // graph.on('cell:click', ({ e, x, y, cell, view }) => {
-
+    //   cell.attr('body/stroke', "red")
     // })
     graph.on('node:click', ({ e, x, y, node, view }) => {
-
+      this.selectNode = node
+      
+      this.setState({node: this.selectNode.store.data})
     })
     graph.on('edge:click', ({ e, x, y, edge, view }) => {
-
+      this.selectNode = edge
+      
+      this.setState({node: this.selectNode.store.data})
+      
+      let trans = document.querySelectorAll('.x6-widget-transform')
+      if (trans && trans[0]) {
+        trans[0].style.display = 'none'
+      }
     })
     graph.on('blank:click', ({ e, x, y }) => {
-
+      this.selectNode = null
+      
+      this.setState({node: null})
     })
-
+    
     const r1 = graph.createNode({
       shape: 'mk-rect',
       label: '寮�濮�',
@@ -591,9 +606,9 @@
       shape: 'mk-circle',
       label: '杩炴帴'
     })
-
+    
     stencil.load([r1, r2, r3, r4, r5, r6], 'group1')
-
+    
     const p1 = graph.createNode({
       shape: 'mk-ellipse',
       label: 'ellipse'
@@ -602,8 +617,51 @@
       shape: 'mk-star',
       label: ''
     })
-
+    
     stencil.load([p1, p2], 'group2')
+    
+    this.mkGraph = graph
+  }
+  
+  setTop = () => {
+    if (!this.selectNode) {
+      message.warning('璇烽�夋嫨鑺傜偣锛�')
+      return
+    }
+    this.selectNode.toFront()
+  }
+
+  setBottom = () => {
+    if (!this.selectNode) {
+      message.warning('璇烽�夋嫨鑺傜偣锛�')
+      return
+    }
+    // let cells = this.mkGraph.getCells()
+    this.selectNode.toBack()
+  }
+
+  setZoomIn = () => {
+    const zoom = this.mkGraph.zoom()
+
+    if (zoom < 2) {
+      this.mkGraph.zoom(0.1)
+    }
+  }
+
+  setZoomOut = () => {
+    const zoom = this.mkGraph.zoom()
+
+    if (zoom > 0.5) {
+      this.mkGraph.zoom(-0.1)
+    }
+  }
+
+  setZoomInt = () => {
+    this.mkGraph.zoomTo(1)
+  }
+
+  save = () => {
+    // let nodes = this.mkGraph.toJSON()
   }
 
   updateComponent = (card) => {
@@ -649,11 +707,11 @@
   }
 
   render() {
-    const { card } = this.state
+    const { card, toolunfold, nodeunfold, node } = this.state
     let _style = resetStyle(card.style)
 
     return (
-      <div className="menu-scatter-chart-edit-box" style={_style} onClick={this.clickComponent} id={card.uuid}>
+      <div className="menu-x6-chart-edit-box" style={_style} onClick={this.clickComponent} id={card.uuid}>
         <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
           <div className="mk-popover-control">
             <ChartCompileForm config={card} plotchange={this.updateComponent}/>
@@ -669,30 +727,41 @@
         <div className="mk-toolbar">
           <div className="left-tool">
             <Tooltip title="缃墠">
-              <VerticalAlignTopOutlined />
+              <VerticalAlignTopOutlined onClick={this.setTop}/>
             </Tooltip>
             <Tooltip title="缃悗">
-              <VerticalAlignBottomOutlined />
+              <VerticalAlignBottomOutlined onClick={this.setBottom}/>
             </Tooltip>
             <Tooltip title="淇濆瓨">
-              <SaveOutlined />
+              <SaveOutlined onClick={this.save}/>
             </Tooltip>
           </div>
           <div className="right-tool">
             <Tooltip title="鏀惧ぇ">
-              <ZoomInOutlined />
+              <ZoomInOutlined onClick={this.setZoomIn}/>
             </Tooltip>
             <Tooltip title="缂╁皬">
-              <ZoomOutOutlined />
+              <ZoomOutOutlined onClick={this.setZoomOut}/>
             </Tooltip>
             <Tooltip title="1:1">
-              <OneToOneOutlined />
+              <OneToOneOutlined onClick={this.setZoomInt}/>
             </Tooltip>
           </div>
         </div>
         <div className="canvas" style={{width: '100%', minHeight: card.plot.height, height: card.plot.height}} id={card.uuid + 'canvas'}>
-          <div id={card.uuid + 'stencil'} className="mk-stencil"></div>
+          <div id={card.uuid + 'stencil'} className={'mk-stencil ' + (toolunfold ? '' : 'merge')}>
+            <div className="tool-control" onClick={() => this.setState({toolunfold: !toolunfold})}>
+              <DoubleLeftOutlined />
+            </div>
+          </div>
           <div id={card.uuid + 'container'} className="mk-container"></div>
+          <div className={'mk-node-edit ' + (nodeunfold ? '' : 'merge')}>
+            <div className="tool-control" onClick={() => this.setState({nodeunfold: !nodeunfold})}>
+              <DoubleLeftOutlined />
+            </div>
+            <div className="header">璁剧疆</div>
+            {!node ? <div className="empty">鏈�変腑</div> : <div></div>}
+          </div>
         </div>
         <div className="component-name">
           <div className="center">

--
Gitblit v1.8.0