antv/x6使用经验

1、版本

@antv/x6的2个大版本写法和用法不太一样,这里是2.x

2、使用

2.x的版本各类插件和主类是分开的

import { Graph } from '@antv/x6'

//图形的基本信息
const shadowAttrs = {
  name: 'dropShadow',
  args: {
    dx: 3,
    dy: 4,
    blur: 20,
    color:  '#00a6ff62'
  }
}
const commonAttrs = {
  body: {
    stroke: "#18FEFE",
    strokeWidth: 1,
    fill: "#020d23",
    rx: 2,
    ry: 2,
    cursor: 'pointer',
    filter: shadowAttrs
  },
  label: {
    fill: '#fff',
    cursor: 'pointer',
    fontSize: 14,
    textWrap: {
      width: -10, // 宽度减少 10px
      height: '80%', // 高度为参照元素高度的一半
      ellipsis: true, // 文本超出显示范围时,自动添加省略号
      breakWord: true // 是否截断单词
    }
  }
}

let graph: Graph
//初始化图
graph = new Graph({
   	container: containerRef.value,
    width: containerRef.value.offsetWidth,
	height: containerRef.value.offsetHeight,
	interacting: false
 })
 //注册图形
Graph.registerNode('parent-node', {
	inherit: 'path', // 继承自 Shape.Rect
	width: containerRef.value.offsetWidth,
    height: containerRef.value.offsetHeight - distance,
    attrs: {
      body: {
        ...commonAttrs.body,
        stroke: gradient,
        strokeWidth: 5
      }
    },
    path: 'M0.5,668.5L0.5,448L-0.5,448L-0.5,669.5L878.5,669.5L878.5,-0.5L-0.5,-0.5L-0.5,222L0.5,222L0.5,0.5L877.5,0.5L877.5,668.5L0.5,668.5Z'
  })
//新增图形到视图中
  graph.addNode({
   	x: 0,
   	y: distance / 2,
   	shape: 'parent-node',
   	data: { parent: true }
 })


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值