const Node = require('butterfly-dag').Node;
class ANode extends Node {
draw(obj) {
// here you can custom dom according to your needs.
}
}
// Initialize draw
canvas.draw({
nodes: [{
id: 'xxxx',
top: 100,
left: 100,
Class: ANode // after setting the base class, the canvas will render based on the custom class.
// the attribute below
...
}]
})
// Dynamic adding node to canvas
canvas.addNode({
id: 'xxx',
top: 100,
left: 100,
Class: ANode
// the attribute below
...
});unique id
y-axis coordinates: the coordinates of the node in the canvas. if it is in the group, it is relative to the internal coordinates of the group
x-axis coordinates: the coordinates of the node in the canvas. if it is in the group, it is relative to the internal coordinates of the group
set whether the node can be dragged: can override the global draggable attribute
group id: after setting, the node will be added to the group
system endpoints configuration: system endpoints will be added when this configuration is present
Extended class: when the extended class is passed in, the node will be rendered according to the draw method of the extended class, and the related methods of the extended class will also override the methods of the parent class
scope: only nodes with the same scope can be dragged into the group
// single scope
node.scope = 'xxx';
// multiple scopes, can be connected in any one match
node.scope = 'xxx1 xxx2 xxx3';The returned dom of the node must be set to position: absolute;
import {Node} from 'butterfly-dag';
Class YourNode extends Node {
/**
* callback after node mount
*/
mounted() {}
/**
* node draw function
* @param {obj} data - node data
* @return {dom} - node dom
*/
draw(obj) {}
}description: get group width
return
numberthe width of the node
getWidth = () => {}description: get group height
return
numberthe height of the node
getHeight = () => {}description: set whether the node is movable
params
booleanset whether the node can be moved
setDraggable = (boolean) => {}description: add an endpoint point to the node。can add system endpoint or custom endpoint which is a sub dom in node. *Note: *This method must be executed after the node is mounted .
params
{obj} paramendpoint info (This method must be executed after the node is mounted ){string} param.idendpoint id{string} param.orientationendpoint direction (can control the direction of entry and exit of edges){string} param.scopeconnection scope{string} param.type'source' / 'target' / undefined / 'onlyConnect',please check endpoint document.{string} param.domany sub DOM in the node can be used as a custom endpoint
addEndpoint = (obj) => {}description:remove an endpoint point from the node
params
{string} pointIdendpoint id(This method must be executed after the node is mounted)
return
{Endpoint}Endpoint instance
removeEndpoint = (string) => {}description:get an endpoint point from the node
params
{string(Require)} pointIdendpoint id{string(Optional)} typeendpoint type . If the type is passed, both id and type of endpoint are exactly the same to match
return
{Endpoint}Endpoint instance
getEndpoint = (id, type) => {}
description: the method of node moving coordinates
params
{number} xx coordinate{number} yy coordinate
moveTo = (x, y) => {}description: the method of node deletion. Consistent with the method canvas.removeNode
remove = () => {}description: emit events, canvas or any elements can receive event from the node
params
{string} eventemit event name{number} dataemit event data
emit = (string, obj) => {}description: receive events, the node can receive events from canvas or any elements
params
{string} eventreceive event name{function} datareceive event callback
on = (string, callback) => {}description: the method of node shrinkage
params
{string} nodeIdnode id
collapseNode = (string) => {}description: the method of node expansion
params
{string} nodeIdnode id
expandNode = (string) => {}