安装 AntV X6
npm install @antv/x6 --save
html结构
<div class="editor" ref="editor" style="height: 400px"></div>
js结构
initEditor() {
// 获取容器的宽高
const { clientHeight: height, clientWidth: width } = this.$refs["editor"];
console.table({ width, height });
/** 初始化实例 */
this.graph = new Graph({
// 容器
container: this.$refs["editor"],
// 宽高
width: width,
height: 400,
connecting: {
connector: { name: "smooth" },
},
});
console.log("graph: ", this.graph);
const appNodes = [
{
x: 500,
y: 50,
attrs: {
body: {
fill: "#e2e8f0",
stroke: "#cbd5e1",
},
label: {
fill: "#334155",
},
text: {
fontSize: 18,
textWrap: {
text: "数据采集",
width: -15,
},
},
},
},
{
x: 700,
y: 50,
attrs: {
body: {
fill: "#e2e8f0",
stroke: "#cbd5e1",
},
label: {
fill: "#334155",
},
text: {
fontSize: 18,
textWrap: {
text: "计费",
width: -15,
},
},
},
},
{
x: 900,
y: 50,
attrs: {
body: {
fill: "#e2e8f0",
stroke: "#cbd5e1",
},
label: {
fill: "#334155",
},
text: {
fontSize: 18,
textWrap: {
text: "多协议接入",
width: -15,
},
},
},
},
{
x: 1100,
y: 50,
attrs: {
body: {
fill: "#e2e8f0",
stroke: "#cbd5e1",
},
label: {
fill: "#334155",
},
text: {
fontSize: 18,
textWrap: {
text: "数据分发",
width: -15,
},