Example steps for using AntV X6 with Vue.js

Example steps for using AntV X6 with Vue.js

0x0 Introduction

Because the project uses flowcharts and the requirements are not detailed, the more flexible x6 graphic editor is chosen as the flowchart editor. From the documentation, it is not complicated, so this is just a reference tutorial.

Antv X6 Documentation

0x1 Installation

Install the x6 dependency according to the tutorial instructions, and then create a new container for instantiation:

<div ref="containerRef" class="area-center-container" />
const data = {
  // Nodes: [
    {
      id: 'node1', // String, optional, unique identifier of the node x: 40, // Number, required, x value of the node position y: 40, // Number, required, y value of the node position width: 80, // Number, optional, width value of the node size height: 40, // Number, optional, height value of the node size label: 'hello', // String, node label },
    {
      id: 'node2', // String, unique identifier of the node x: 160, // Number, required, x value of the node position y: 180, // Number, required, y value of the node position width: 80, // Number, optional, width value of the node size height: 40, // Number, optional, height value of the node size label: 'world', // String, node label },
  ],
  // edges: [
    {
      source: 'node1', // String, required, starting node id
      target: 'node2', // String, required, target node id
    },
  ],
}

function initGraph() {
  const graph = new Graph({
    container: this.$refs.containerRef,
    grid: {
      size: 10, // grid size 10px
      visible: true // render mesh background},
    snapline:
      enabled: true, // Alignment sharp: true
    },
    scroller:
      enabled: true,
      pageVisible: false,
      pageBreak: false,
      pannable: true
    }
  })
  // Center the canvas graph.centerContent()

  graph.fromJSON(data)
}

This is the simplest example. Please refer to the corresponding explanations in the documentation for the different parameters above.

0x2 Node Sidebar

According to the stencil example in the document, a lot of code can be simplified. You can just use the encapsulated business directly. Just write a container instantiation as above:

<el-aside ref="stencilRef" class="area-left" />
this.stencil = new Stencil({
    title: 'Process Node Sidebar',
    target: graph,
    search: false,
    collapsable: true,
    stencilGraphWidth: this.$refs.stencilRef.$el.clientWidth,
    stencilGraphHeight: this.$refs.stencilRef.$el.clientHeight,
    groups: [
        {
            name: 'group',
            title: 'Flowchart Node',
            collapsable: false
          }
        ],
    getDropNode: node => {
        let cloneNode = node.clone()
        switch (node.shape) {
            case 'rect':
                cloneNode = new RectShape()
                break
            case 'circle':
                cloneNode = new CircleShape()
                break
            case 'polygon':
                cloneNode = new PolylineShape()
                break
        }
        cloneNode.updateInPorts(graph)
        return cloneNode
    }
})
// Load nodes this.stencil.load([new Rect(rectInfo), new Circle(circleInfo), new Polygon(polygonInfo)], 'group')

0x3 Integration Example

Online: https://codesandbox.io/s/icy-meadow-rqihx

The above is the details of the example steps of using Antv X6 with Vue.js. For more information about using Antv X6 with Vue.js, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Reference Antv G2 in the vue project, taking the pie chart as an example
  • Sample code for using antv in Vue
  • Sample code for using G2 charts in Vue
  • Using AntV in vue2 with g2plot as an example

<<:  Upgrade Docker version of MySQL 5.7 to MySQL 8.0.13, data migration

>>:  About MySQL 8.0.13 zip package installation method

Recommend

Essential bonus items for optimizing and packaging the front end of Vue projects

Table of contents Preface 1. Routing lazy loading...

Vue uses echart to customize labels and colors

This article example shares the specific code of ...

This article will show you how JavaScript garbage collection works

Table of contents 1. Overview 2. Memory Managemen...

Solve the problem of garbled data in MySQL database migration

Under the instructions of my leader, I took over ...

Fixed a bug caused by scrollbar occupying space

background This bug was caused by滾動條占據空間. I check...

Notes on element's form components

Element form and code display For details, please...

Example of how to deploy a Django project using Docker

It is also very simple to deploy Django projects ...

Detailed tutorial on installing VirtualBox and Ubuntu 16.04 under Windows system

1. Software Introduction VirtualBox VirtualBox is...

Mini Program implements custom multi-level single-select and multiple-select

This article shares the specific code for impleme...

Specific use of the wx.getUserProfile interface in the applet

Recently, WeChat Mini Program has proposed adjust...

JavaScript tips to help you improve your coding skills

Table of contents 1. Filter unique values 2. Shor...

Methods for deploying MySQL services in Docker and the pitfalls encountered

I have been learning porters recently. I feel lik...

Implementation of Nginx filtering access logs of static resource files

Messy log Nginx in daily use is mostly used as bo...