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

CSS3 sample code to achieve element arc motion

How to use CSS to control the arc movement of ele...

About the "occupational disease" of designers

I always feel that designers are the most sensiti...

Steps for restoring a single MySQL table

When I was taking a break, a phone call completel...

Implementation of dynamic particle background plugin for Vue login page

Table of contents The dynamic particle effects ar...

Linux Domain Name Service DNS Configuration Method

What is DNS The full name of DNS is Domain Name S...

How to display and format json data on html page

JSON data is displayed and formatted on the HTML ...

Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0

MySQL 5.7 version: Method 1: Use the SET PASSWORD...

Detailed configuration of Nginx supporting both Http and Https

It is almost a standard feature for websites nowa...

Comprehensive website assessment solution

<br />Sometimes you may be asked questions l...

Detailed explanation of MySQL 30 military rules

1. Basic Specifications (1) InnoDB storage engine...

Sharing tips on using vue element and nuxt

1. Element time selection submission format conve...

Vue implementation example using Google Recaptcha verification

In our recent project, we need to use Google robo...