antv x6节点node

 1、实现

<template>
  <a-button @click="test1">test1:构造函数</a-button>
  <a-button @click="test21">test2-1</a-button>
  <a-button @click="test22">test2-2</a-button>
  <a-button @click="test31">test3-1</a-button>
  <a-button @click="test32">test3-2</a-button>

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

<script lang="ts">
import {Graph, Shape, Node, ObjectExt} from '@antv/x6';
import {defineComponent, onMounted} from "vue";

export default defineComponent({
  setup() {
    let graph: Graph;

    onMounted(() => {
      graph = new Graph({
        container: document.getElementById('container') as HTMLElement,
        height: 600,
        background: {
          color: '#fffbe6', // 设置画布背景颜色
        },
        grid: {
          size: 10,      // 网格大小 10px
          visible: true, // 渲染网格背景
        },
      });

    })

    // 构造函数创建
    const test1 = () =>{
      // 创建节点
      const rect = new Shape.Rect({
        x: 100,
        y: 200,
        width: 80,
        height: 40,
        angle: 30,
        attrs: {
          body: {
            fill: 'blue',
          },
          label: {
            text: 'Hello',
            fill: 'white',
          },
        },
      })
      // 添加到画布
      graph.addNode(rect)
    }

    let test2Rect: Node;
    const test21 = () =>{
      test2Rect = new Shape.Rect()
      // 添加到画布
      graph.addNode(test2Rect)
    }
    const test22 = () =>{
      test2Rect
          // 设置节点位置
          ?.position(100, 200)
          // 设置节点大小
          ?.resize(80, 40)
          // 旋转节点
          ?.rotate(30)
          // 设置节点样式
          ?.attr({
            body: {
              fill: 'blue',
            },
            label: {
              text: 'Hello',
              fill: 'white',
            },
          })
    }

    let test3Rect: Node;
    const test31 = () => {
      test3Rect = graph.addNode({
        shape: 'rect', // 指定使用何种图形,默认值为 'rect'
        x: 100,
        y: 200,
        width: 80,
        height: 40,
        angle: 30,
        attrs: {
          body: {
            fill: 'blue',
          },
          label: {
            text: 'Hello',
            fill: 'white',
          },
        },
      })
    }
    const test32 = () => {
      test3Rect
          // 设置节点位置
          ?.position(100, 200)
          // 设置节点大小
          ?.resize(80, 40)
          // 旋转节点
          ?.rotate(30)
          // 设置节点样式
          ?.attr({
            body: {
              fill: 'blue',
            },
            label: {
              text: 'Hello',
              fill: 'white',
            },
          })
    }

    return {
      test1,
      test21,
      test22,
      test31,
      test32
    }
  }
})
</script>

<style scoped>

</style>

2、视频

antv x6节点node_哔哩哔哩_bilibiliantv x6节点nodehttps://www.bilibili.com/video/BV1c3411M7Ke?share_source=copy_web

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

<每天一点>

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值