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

Summary of some common uses of refs in React

Table of contents What are Refs 1. String type Re...

How to limit the input box to only input pure numbers in HTML

Limit input box to only pure numbers 1、onkeyup = ...

About the layout method of content overflow in table

What is content overflow? In fact, when there is ...

js to achieve simple front-end paging effect

Some projects have relatively simple business, bu...

Summary of the understanding of virtual DOM in Vue

It is essentially a common js object used to desc...

Implement QR code scanning function through Vue

hint This plug-in can only be accessed under the ...

How to Dockerize a Python Django Application

Docker is an open source project that provides an...

Mysql table creation foreign key error solution

Database Table A: CREATE TABLE task_desc_tab ( id...

Installing MySQL 8.0.12 based on Windows

This tutorial is only applicable to Windows syste...

Graphical explanation of the underlying principle of JavaScript scope chain

Table of contents Preface Scope 1. What is scope?...

Detailed process of decompressing and installing mysql5.7.17 zip

1. Download address https://dev.mysql.com/downloa...

Implementation of mysql decimal data type conversion

Recently, I encountered a database with the follo...