Code Monkey home page Code Monkey logo

vue-x6's Introduction

vue-x6

NPM Package npm bundle size npm MIT License

提供自定义渲染器在vue中直接渲染x6画布

  1. 使用createRender自定义渲染器
  2. 只需抽象create/insert/update/remove既可
  3. 最后渲染出来的instance就是Graph/Node/Edge对象,这些对象使用ref可以直接绑定
  4. Graph内部将Children做进一步处理,生成带key的子组件(避免list diff导致元素id变化)

安装

npm install vue-x6
yarn add vue-x6

demo

online demo

<script setup lang="ts">
import { ref } from 'vue'
import { Snapline } from "@antv/x6-plugin-snapline";
import { Graph, Node, Edge, ElementOfPlugin } from 'vue-x6'
const click = (e) => {
  console.log(e)
}
const SnaplinePlugin = ElementOfPlugin('Snapline', Snapline)
const visible = ref(true)
const toggle = () => visible.value = !visible.value
</script>

<template>
  <button @click="toggle">显示/隐藏node2</button>
  <Graph grid>
    <SnaplinePlugin key="Snapline" />
    <Node id="1" label="node1" :x="100" :y="100" :width="80" :height="40" @click="click" >
    </Node>
    <Node id="2" label="node2" :x="200" :y="200" :width="80" :height="40" @click="click" v-if="visible" />
    <Node id="3" label="node3" :x="200" :y="100" :width="80" :height="40" parent="1" @click="click" />
    <Edge v-if="visible" source="1" target="2" @click="click">
      <EdgeTool name="button-remove" :args='{ x: 10, y: 10 }' />
      <Label :attrs='{text: {text: "Hello Label1"}}' :position='{distance: 0.3}' />
      <Label :attrs='{text: {text: "Hello Label3"}}' :position='{distance: 0.5}' />
      <Label :attrs='{text: {text: "Hello Label2"}}' :position='{distance: 0.7}' />
      <SourceMarker name="diamond" />
      <TargetMarker name="ellipse" />
    </Edge>
  </Graph>
</template>

x6-vue-shape demo

import { register, getTeleport } from "@antv/x6-vue-shape";
import ProgressNode from "./ProgressNode.vue";

register({
  shape: "custom-vue-node",
  width: 100,
  height: 100,
  component: ProgressNode,
});

const TeleportContainer = getTeleport();

<template>
  <TeleportContainer />
  <Graph grid>
    <Node shape="custom-vue-node" :x="400" :y="100" />
  </Graph>
</template>

TODO

  • 提供渲染器
  • Graph组件
  • Node/Edge组件
  • ElementOfPlugin函数方便封装官方plugin
  • Label(Edge)
  • NodePort
  • NodeTool/EdgeTool
  • SourceMarker/TargetMarker

TIP

  1. vue createRenderer中的createElement也通过包装一层传递root(graph)进去
  2. vue createRenderer传递patchProp,这里通过包装一个patchProps一次性更新整个props
  3. 这里patchProps中有延时逻辑,所以增加updated:props事件监听

vue-x6's People

Contributors

lloydzhou avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

6313504 daylyt247

vue-x6's Issues

不支持 v-for

或者

  <Node :id="node.id" parent="102" :label="node.label" :height="node.height" :width="node.width" :x="node.x"
    :y="node.y" v-for="node in nodes" />

都不支持

const nodes = [
{
id: '1-1',
label: '1-1',
height: 10,
width: 10,
x: 10,
y: 10
}
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.