View
Previous
Model
Next
Node Tools
Loading...
Whether the canvas is rendered asynchronously. Asynchronous rendering does not block the UI and significantly improves performance when adding a large number of nodes and edges. However, it's important to note that some synchronous operations may produce unexpected results, such as getting the view of a node or getting the bounding box of nodes/edges, because these synchronous operations may be triggered before the asynchronous rendering is complete.
Whether to render only the elements in the visible area, default is false
. If set to true
, the initial screen load will only render elements in the current visible area. When dragging or zooming the canvas, the remaining elements will be automatically loaded based on the canvas window size. This significantly improves performance in scenarios with a large number of elements.
The number of mouse movements required before triggering a connection, or set to 'onleave' to trigger a connection when the mouse leaves the element. Default is 0
.
The number of mouse movements allowed before triggering the 'mousemove' event, default is 0
.
When the number of mouse movements exceeds the specified number, the mouse click event will not be triggered. Default is 0
.
Whether to disable the default right-click menu of the canvas, default is true
.
Whether to disable the default mouse behavior when responding to mouse events in blank areas of the canvas, default is true
.
(this: Graph,args: {node: Nodeport: Portcontainer: Elementselectors?: Markup.SelectorslabelContainer: ElementlabelSelectors?: Markup.SelectorscontentContainer: ElementcontentSelectors?: Markup.Selectors},) => void
Callback triggered when a port is rendered, with the following parameters:
Name | Type | Required | Description |
---|---|---|---|
node | Node | ✓ | Node instance. |
port | Port | ✓ | Port options. |
container | Element | ✓ | Container element of the port. |
selectors | Markup.Selectors | Selector key-value pairs after port Markup rendering. | |
labelContainer | Element | ✓ | Container element of the port label. |
labelSelectors | Markup.Selectors | Selector key-value pairs after port label Markup rendering. | |
contentContainer | Element | ✓ | Container element of the port content. |
contentSelectors | Markup.Selectors | Selector key-value pairs after port content Markup rendering. |
For example, we can render a React-type port:
const graph = new Graph({container: this.container,onPortRendered(args) {const selectors = args.contentSelectorsconst container = selectors && selectors.foContentif (container) {ReactDOM.render(<Tooltip title="port"><div className="my-port" /></Tooltip>,container,)}},})
(this: Graph,args: {edge: Edgelabel: Edge.Labelcontainer: Elementselectors: Markup.Selectors},) => void
Callback triggered when an edge's text label is rendered, with the following parameters:
Name | Type | Required | Description |
---|---|---|---|
edge | Edge | ✓ | Edge instance. |
label | Edge.Label | ✓ | Text label options. |
container | Element | ✓ | Text label container. |
selectors | Markup.Selectors | ✓ | Selector key-value pairs after text label Markup rendering. |
We can add a <foreignObject>
element when defining the Label Markup to support HTML and React rendering capabilities.
const graph = new Graph({container: this.container,onEdgeLabelRendered: (args) => {const { selectors } = argsconst content = selectors.foContent as HTMLDivElementif (content) {content.style.display = 'flex'content.style.alignItems = 'center'content.style.justifyContent = 'center'ReactDOM.render(<Button size="small">Antd Button</Button>, content)}},})
(this: Graph, cell: Cell) => CellView | null | undefined
Customize the view of an element. It can return a CellView
to replace the default view. If it returns null
, the element won't be rendered. If it returns undefined
, the element will be rendered in the default way.
findView(ref: Cell | Element): CellView | null
Find the corresponding view based on the node/edge or element.
findViewByCell(cellId: string | number): CellView | nullfindViewByCell(cell: Cell | null): CellView | null
Find the corresponding view based on the node/edge ID or instance.
findViewByElem(elem: string | Element | undefined | null): CellView | null
Find the corresponding view based on the element selector or element object.
findViewsFromPoint(x: number, y: number): CellView[]findViewsFromPoint(p: Point.PointLike): CellView[]
Return views of nodes/edges whose bounding boxes contain the specified point.
findViewsInArea(x: number,y: number,width: number,height: number,options?: FindViewsInAreaOptions,): CellView[]findViewsInArea(rect: Rectangle.RectangleLike,options?: FindViewsInAreaOptions,): CellView[]
Return views of nodes/edges whose bounding boxes intersect with the specified rectangle. When options.strict
is true
, the bounding box of the node/edge must completely contain the specified rectangle.
findViews(ref: Point.PointLike | Rectangle.RectangleLike): CellView[]
Return views of nodes/edges whose bounding boxes contain the specified point or intersect with the specified rectangle.