首页 > 其他分享 >antV x6 禁止拖拽出新的线,鼠标滑过线设置高亮

antV x6 禁止拖拽出新的线,鼠标滑过线设置高亮

时间:2024-06-03 16:22:27浏览次数:24  
标签:11 过线 text antV port cell item x6 id

antV x6中的ER图;

 

代码如下:

// 鼠标滑过事件
    graph.on('edge:mouseenter', ({ cell }) => {
      cell.removeTools()
      cell.attr('line', { stroke: 'blue', strokeWidth: 2 })
      cell.zIndex = 0
    })

    // 鼠标滑出事件
    graph.on('edge:mouseleave', ({ cell, index, options }) => {
      cell.attr('line', { stroke: '#A2B1C3', strokeWidth: 2 })
    })

    //新增线的时候,将当前线删除
    graph.on('edge:added', ({ edge, options }) => {
      console.log(edge, options);
      graph.removeEdge(edge.id);
    })

以下为完整代码:

其中  antV.x6.js  可在antV官方网站下载    快速上手 | X6 (antgroup.com)

re.js是当前ER图需要的数据

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <script src="js/antV.x6.js"></script>
  <script src="./data/re.js"></script>

  <style type="text/css">
    #container {
      width: 100%;
      height: 600px;
      overflow: auto;
      display: flex;
    }
  </style>

</head>

<body>

  <div id="container">
  </div>

  <script>

    const LINE_HEIGHT = 24
    const NODE_WIDTH = 250
    X6.Graph.registerPortLayout(
      'erPortPosition',
      (portsPositionArgs) => {
        return portsPositionArgs.map((_, index) => {
          return {
            position: {
              x: 0,
              y: (index + 1) * LINE_HEIGHT,
            },
            angle: 0,
          }
        })
      },
      true,
    )

    X6.Graph.registerNode(
      'er-rect',
      {
        inherit: 'rect',
        markup: [
          {
            tagName: 'rect',
            selector: 'body',
          },
          {
            tagName: 'text',
            selector: 'label',
          },
        ],
        attrs: {
          rect: {
            strokeWidth: 1,
            stroke: '#5F95FF',
            fill: '#5F95FF',
          },
          label: {
            fontWeight: 'bold',
            fill: '#ffffff',
            fontSize: 12,
          },
        },
        ports: {
          groups: {
            list: {
              markup: [
                {
                  tagName: 'rect',
                  selector: 'portBody',
                },
                {
                  tagName: 'text',
                  selector: 'portNameLabel',
                },
                {
                  tagName: 'text',
                  selector: 'portTypeLabel',
                },
              ],
              attrs: {
                portBody: {
                  width: NODE_WIDTH,
                  height: LINE_HEIGHT,
                  strokeWidth: 1,
                  stroke: '#5F95FF',
                  fill: '#EFF4FF',
                  magnet: true,
                },
                portNameLabel: {
                  ref: 'portBody',
                  refX: 6,
                  refY: 6,
                  fontSize: 10,
                },
                portTypeLabel: {
                  ref: 'portBody',
                  refX: 95,
                  refY: 6,
                  fontSize: 10,
                },
              },
              position: 'erPortPosition',
            },
          },
        },
      },
      true,
    )

    const graph = new X6.Graph({
      container: document.getElementById('container'),
      interactions: [],
      connecting: {
        router: {
          name: 'er',
          args: {
            offset: 25,
            direction: 'H',
          },
        },
        createEdge() {
          return new X6.Shape.Edge({
            attrs: {
              line: {
                stroke: '#A2B1C3',
                strokeWidth: 1,
              },
            },
          })
        },
      },
    })

    // 鼠标滑过事件
    graph.on('edge:mouseenter', ({ cell }) => {
      cell.removeTools()
      cell.attr('line', { stroke: 'blue', strokeWidth: 2 })
      cell.zIndex = 0
    })

    // 鼠标滑出事件
    graph.on('edge:mouseleave', ({ cell, index, options }) => {
      cell.attr('line', { stroke: '#A2B1C3', strokeWidth: 2 })
    })

//新增线的时候,将当前线删除 graph.on('edge:added', ({ edge, options }) => { graph.removeEdge(edge.id); }) const cells = [] data.forEach((item) => { if (item.shape === 'edge') { cells.push(graph.createEdge(item)) } else { cells.push(graph.createNode(item)) } }) graph.resetCells(cells) graph.zoomToFit({ padding: 10, maxScale: 1 }) </script> </body> </html>

re.js文件

var biaoList = [
  {
    id:'-1',
    name:'兴趣班',
    level:'-2', //层级
    number:1,  //当前层第几个
    ports:[
      {id:'-1-1',text:'ID'},
      {id:'-1-2',text:'跆拳道'},
    ]
  },
  {
    id:1,
    name:'学生1',
    level:'-1', //层级
    number:1,  //当前层第几个
    ports:[
      {id:'1-1',text:'ID'},
      {id:'1-2',text:'张晓明'},
      {id:'1-3',text:'9'}
    ]
  },
  {
    id:2,
    name:'学生2',
    level:'-1',
    number:2,
    ports:[
      {id:'2-1',text:'ID'},
      {id:'2-2',text:'王一一'},
      {id:'2-3',text:'7'}
    ]
  },
  {
    id:3,
    name:'学生3',
    level:'-1',
    number:3,
    ports:[
      {id:'3-1',text:'ID'},
      {id:'3-2',text:'张伟伟'},
      {id:'3-3',text:'8'}
    ]
  },
  {
    id:11,
    level:'0',
    number:1,
    name:'班级1',
    ports:[
      {id:'11-1',text:'ID'},
      {id:'11-2',text:'学号'},
      {id:'11-3',text:'学生姓名'},
      {id:'11-4',text:'学生年龄'},
    ]
  },
  {
    id:21,
    name:'教师1',
    number:1,
    level:'1',
    ports:[
      {id:'21-1',text:'ID'},
      {id:'21-2',text:'教师姓名'},
      {id:'21-3',text:'专业'}
    ]
  },
  {
    id:22,
    name:'教师2',
    level:'1',
    number:2,
    ports:[
      {id:'22-1',text:'ID'},
      {id:'22-2',text:'教师姓名'},
      {id:'22-3',text:'专业'}
    ]
  },
  {
    id:31,
    name:'毕业院校1',
    level:'2',
    number:1,
    ports:[
      {id:'31-1',text:'ID'},
      {id:'31-2',text:'毕业院校名称'},
    ]
  },
]

var sortArr = biaoList.sort((a, b) => a.level - b.level)

var linkList = [
  {
    "source": {
      "cell": "-1",
      "port": "-1-1"
    },
    "target": {
      "cell": "1",
      "port": "1-1"
    },
  },
  {
    "source": {
      "cell": "-1",
      "port": "-1-1"
    },
    "target": {
      "cell": "2",
      "port": "2-1"
    },
  },
  {
    "source": {
      "cell": "1",
      "port": "1-1"
    },
    "target": {
      "cell": "11",
      "port": "11-2"
    },
  },
  {
    "source": {
      "cell": "2",
      "port": "2-1"
    },
    "target": {
      "cell": "11",
      "port": "11-2"
    },
  },
  {
    "source": {
      "cell": "3",
      "port": "3-1"
    },
    "target": {
      "cell": "11",
      "port": "11-2"
    },
  },
  {
    "source": {
      "cell": "11",
      "port": "11-1"
    },
    "target": {
      "cell": "21",
      "port": "21-1"
    },
  },
  {
    "source": {
      "cell": "11",
      "port": "11-1"
    },
    "target": {
      "cell": "22",
      "port": "22-1"
    },
  },
  {
    "source": {
      "cell": "21",
      "port": "21-1"
    },
    "target": {
      "cell": "31",
      "port": "31-1"
    },
  },
  {
    "source": {
      "cell": "1",
      "port": "1-2"
    },
    "target": {
      "cell": "11",
      "port": "11-3"
    },
  },
  {
    "source": {
      "cell": "2",
      "port": "2-2"
    },
    "target": {
      "cell": "11",
      "port": "11-3"
    },
  },
  {
    "source": {
      "cell": "3",
      "port": "3-2"
    },
    "target": {
      "cell": "11",
      "port": "11-3"
    },
  },
]

var dataList =[];
var pointY ,pointX ;

sortArr.map((item,index)=>{
  var ports=[]
  cLevel = item.level
 
  item.ports.map((cItem,cIndex)=>{
    var ceil = {
      "id": cItem.id,
      "group": "list",
      "attrs": {
        "portNameLabel": {
          "text": cItem.text
        }
      }
    }
    ports.push(ceil)
  })

  pointY = item.level == 0?280:150*item.number
  var ceil = {
    "id": item.id,
    "shape": "er-rect",
    "label": item.name,
    "width": 150,
    "height": 24,
    "position": {
      "x": 250*(item.level),
      "y": pointY
    },
    'ports':ports
  }
  dataList.push(ceil)
})

linkList.map((item,index)=>{
  var ceil = {
    "id": "5"+index+1,
    "shape": "edge",
    "source":item.source,
    "target": item.target,
    "attrs": {
      "line": {
        "stroke": "#A2B1C3",
        "strokeWidth": 2
      }
    },
    "zIndex": 0,
    connector: {
      name: 'rounded',
      args: {
        radius: 10,
      },
    },
  }
  dataList.push(ceil)
})

var data = dataList

 

标签:11,过线,text,antV,port,cell,item,x6,id
From: https://www.cnblogs.com/yeziyou/p/18229113

相关文章

  • 「AntV」X6 自定义vue节点(vue3)
    官方文档本篇文档只讲解vue3中如何使用,vue2的可以参考下官方文档安装插件@antv/x6-vue-shape添加vue组件既然使用vue节点,那么我们就需要准备一个vue的组件,这个组件就是节点的一些样式,根据你们的ui自行写代码即可<template><div>节点名称</div><div>节点描述</div>......
  • 借助x64dbg及Scylla的UPX手工脱壳
    参考文章:https://bbs.kanxue.com/thread-268159.htm很多地方都是复制粘贴的,学习学习大佬的文章。寻找入口点1、加载程序F9运行,会发现停在push处,push操作将所有寄存器的值压栈,这一步之后会加载UPX的解压代码用于将原始程序解压。2、upx工作原理首先将程序压缩。所谓的压缩......
  • 红米AX6000 Openwrt FIP 没权限 Can't open device for writing!
     ......
  • 逆向 | Win7扫雷x64版本内存雷区读取
    逆向|Win7扫雷x64版本内存雷区读取继续写书,这是我为书中实验编写的测试代码。#include<windows.h>#include<stdio.h>#include<tlhelp32.h>#include<string.h>intmain(){ //获取pid HWNDhWnd=FindWindow(NULL,L"扫雷"); DWORDpid=NULL; GetWindowThr......
  • [IMX6ULL驱动开发]-Linux对中断的处理(二)
    上一篇文章中,引入了Linux对于中断的一些简略流程以及中断抽象为具体实际形象。此文章主要是继续加深对Linux对中断的处理流程以及一些相应的数据结构。目录Linux对中断的扩展:硬件中断、软件中断多中断处理中断上下部处理流程发生中断A,并被中断A打断发生中断A,并被中断B打......
  • [IMX6ULL驱动开发]-Linux对中断的处理(一)
    目录中断概念的引入ARM架构中断的流程异常向量表Linux系统对中断的处理ARM对程序和中断的处理Linux进程中断处理中断概念的引入如何理解中断,我们可以进行如下抽象。把CPU看做一个母亲,当它正在执行任务的时候,可以看为是一个母亲在看书。此时可能发生许多不同的情况,比......
  • x64 环境下_findnext() 函数报错——0xC0000005: 写入位置 0xFFFFFFFFDF47C5A0 时发生
    CSDN搬家失败,手动导出markdown后再导入博客园最近在搞单目相机位姿估计,相机标定参考了【OpenCV3学习笔记】相机标定函数calibrateCamera()使用详解(附相机标定程序和数据)提供的代码。/*@paramFile_Directory为文件夹目录@paramFileType为需要查找的文件类型@param......
  • IMX6ULL Linux内核网络驱动修改
    IMX6ULL网络驱动修改主要修改arch/arm/boot/dts/imx6ul-14x14-evk.dtsi设备树文件即可,修改方式和u-boot的设备树修改一致。硬件电路设备树修改需要修改的设备树位置:arch/arm/boot/dts/imx6ul-14x14-evk.dtsi增加复位引脚信息从上面的原理图可知网口1使用的复位引脚是GPIO......
  • 学习imx6dl遇到的困难总结 持续更新 很痛也很傻
    最近进了新公司开始鼓捣imx6,虽然说之前弄过imx8的应用层,但是底层移植完全不一样简直太无助了。首先介绍下故事背景,拿到一个imx6dl的板子,是基于飞凌的板子改的。网上资料又少,一无所知的我开始了踩坑之路。拿到板子和一套飞凌板子送的源码,本以为是简单的uboot移植,还是厂家给的代码......
  • x64汇编——汇编指令
     汇编指令 movdest,srcmovmove的简称将src的内容赋值给dest,类似于dest=src[地址值]中扩号[]里面放的都是内存地址一个变量的地址值,是它所有字节地址中的最小值word是2字节,dword是4字节(doubleword),qword是8字节(quadword)  注意地址取值是向高位扩展,如......