Skip to content

NodeGraph

Interactive 2D node graph canvas supporting movable nodes, pin connections, pan, zoom, grid snapping, and selection.

Overview

Interactive 2D node graph canvas supporting movable nodes, pin connections, pan, zoom, grid snapping, and selection. Provides extensive layout configuration and interaction capabilities.

Basic Usage

NodeGraph graph = new NodeGraph();
NodeGraphItem itemA = graph.addItem("nodeA", new Label("A"), 50, 50);
itemA.addPort("out", NodeGraphPortKind.OUTPUT, NodeGraphPortSide.RIGHT, 10);
NodeGraphItem itemB = graph.addItem("nodeB", new Label("B"), 200, 50);
itemB.addPort("in", NodeGraphPortKind.INPUT, NodeGraphPortSide.LEFT, 10);
graph.addConnection("c1", "nodeA", "out", "nodeB", "in");
  • GraphView: Static or interactive diagram graph widget displaying connected nodes, edges, labels, and tooltips with custom renderers.
  • NodeGraphConnection: Represents a directional or bidirectional connection between two ports in a NodeGraph.
  • NodeGraphItem: Node item container placed in a NodeGraph canvas hosting a content widget and pin ports.

API

NodeGraph()

Constructs a new NodeGraph instance with default viewport, grid, and themes.

NodeGraph::addConnection(NodeGraphConnection)

Adds an existing connection instance to the graph.

Parameter Type Description
connection NodeGraphConnection The connection parameter.

Returns NodeGraphConnection: The created connection instance..

NodeGraph::addConnection(String, NodeGraphPortRef, NodeGraphPortRef)

Creates and adds a connection between port references.

Parameter Type Description
id String The connection identifier.
from NodeGraphPortRef The source port reference.
to NodeGraphPortRef The destination port reference.

Returns NodeGraphConnection: The created connection instance..

NodeGraph::addConnection(String, String, String, String, String)

Creates and adds a connection between specified item and port IDs.

Parameter Type Description
id String The connection identifier.
fromItemId String The source item identifier.
fromPortId String The source port identifier.
toItemId String The destination item identifier.
toPortId String The destination port identifier.

Returns NodeGraphConnection: The created connection instance..

NodeGraph::addItem(NodeGraphItem)

Adds an existing node item to the graph.

Parameter Type Description
item NodeGraphItem The target item.

Returns NodeGraph: This instance for chaining..

NodeGraph::addItem(String, Widget, float, float)

Creates and places a new node item with the given ID, content widget, and canvas coordinates.

Parameter Type Description
id String The item identifier.
content Widget The content widget.
x float The X coordinate position.
y float The Y coordinate position.

Returns NodeGraphItem: The created node item instance..

NodeGraph::backgroundColor()

Returns the background fill color of the canvas.

Returns MutableColor: The mutable color instance..

NodeGraph::bringToFrontOnSelect()

Returns true if selecting an item moves it to the top of the z-order.

Returns boolean: True if enabled; false otherwise..

NodeGraph::bringToFrontOnSelect(boolean)

Sets whether selecting an item moves it to the front.

Parameter Type Description
bringToFrontOnSelect boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::clearConnectionSelection()

Deselects all currently selected connections.

Returns NodeGraph: This instance for chaining..

NodeGraph::clearItems()

Removes all items and connections from the graph.

Returns NodeGraph: This instance for chaining..

NodeGraph::clearSelection()

Deselects all currently selected items.

Returns NodeGraph: This instance for chaining..

NodeGraph::clippingEnabled()

Returns true if canvas rendering is clipped to widget bounds.

Returns boolean: True if clipping is enabled..

NodeGraph::clippingEnabled(boolean)

Sets whether canvas rendering is clipped to widget bounds.

Parameter Type Description
clippingEnabled boolean Whether canvas rendering is clipped.

Returns NodeGraph: This instance for chaining..

NodeGraph::connection(String)

Returns the connection with the given ID, or null if not found.

Parameter Type Description
id String The connection identifier.

Returns NodeGraphConnection: The connection instance, or null if not found..

NodeGraph::connectionColor()

Returns default line color for connections.

Returns MutableColor: The mutable color instance..

NodeGraph::connectionDragging()

Returns true if a new connection is currently being dragged from a port.

Returns boolean: True if enabled; false otherwise..

NodeGraph::connectionPolicy()

Returns the active connection validation policy.

Returns NodeGraphConnectionPolicy: The active connection policy..

NodeGraph::connectionPolicy(NodeGraphConnectionPolicy)

Sets the connection validation policy.

Parameter Type Description
connectionPolicy NodeGraphConnectionPolicy The connection validation policy.

Returns NodeGraph: This instance for chaining..

NodeGraph::connectionPreviewColor()

Returns preview line color for valid drag connections.

Returns MutableColor: The mutable color instance..

NodeGraph::connections()

Returns an unmodifiable list of all connections.

Returns List: An unmodifiable list of connections..

NodeGraph::consumeWheelWhileHovered()

Returns true if mouse wheel events are consumed while hovering the canvas.

Returns boolean: True if enabled; false otherwise..

NodeGraph::consumeWheelWhileHovered(boolean)

Sets whether mouse wheel events are consumed when hovered.

Parameter Type Description
consumeWheelWhileHovered boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::draggingItemId()

Returns the ID of the item currently being dragged, or empty string if none.

Returns String: The ID of the dragged item, or empty string..

NodeGraph::gridColor()

Returns the minor grid lines color.

Returns MutableColor: The mutable color instance..

NodeGraph::gridSize()

Returns the grid cell step size in pixels.

Returns float: The grid cell size in pixels..

NodeGraph::gridSize(float)

Sets the grid cell step size in pixels.

Parameter Type Description
gridSize float The grid cell size in pixels.

Returns NodeGraph: This instance for chaining..

NodeGraph::hasConnection(NodeGraphPortRef, NodeGraphPortRef)

Returns true if a connection already exists between the given ports.

Parameter Type Description
from NodeGraphPortRef The source port reference.
to NodeGraphPortRef The destination port reference.

Returns boolean: True if connection exists; false otherwise..

NodeGraph::hoveredConnectionId()

Returns the ID of the currently hovered connection, or empty string if none.

Returns String: The ID of the hovered connection, or empty string..

NodeGraph::hoveredItemBorderColor()

Returns hover border color for node items.

Returns MutableColor: The mutable color instance..

NodeGraph::hoveredItemId()

Returns the ID of the currently hovered node item, or empty string if none.

Returns String: The ID of the hovered item, or empty string..

NodeGraph::hoveredPort()

Returns reference to the currently hovered port, or null if none.

Returns NodeGraphPortRef: The hovered port reference, or null if none..

NodeGraph::hoveredPortColor()

Returns hover fill color for pin ports.

Returns MutableColor: The mutable color instance..

NodeGraph::invalidConnectionPreviewColor()

Returns preview line color for invalid drag connections.

Returns MutableColor: The mutable color instance..

NodeGraph::item(String)

Returns the item with the given ID, or null if not found.

Parameter Type Description
id String The item identifier.

Returns NodeGraphItem: The node item instance, or null if not found..

NodeGraph::itemBorderColor()

Returns default border color for node items.

Returns MutableColor: The mutable color instance..

NodeGraph::itemContentPadding()

Returns inner padding around item content widgets.

Returns float: The content padding in pixels..

NodeGraph::itemContentPadding(float)

Sets inner padding around item content widgets.

Parameter Type Description
padding float The padding in pixels.

Returns NodeGraph: This instance for chaining..

NodeGraph::itemDraggingEnabled()

Returns true if item dragging is enabled.

Returns boolean: True if enabled; false otherwise..

NodeGraph::itemDraggingEnabled(boolean)

Sets whether item dragging is enabled.

Parameter Type Description
itemDraggingEnabled boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::items()

Returns an unmodifiable list of all node items.

Returns List: An unmodifiable list of node items..

NodeGraph::keyboardEditingEnabled()

Returns true if keyboard shortcuts (Delete, arrows) are enabled.

Returns boolean: True if enabled; false otherwise..

NodeGraph::keyboardEditingEnabled(boolean)

Sets whether keyboard editing shortcuts are enabled.

Parameter Type Description
keyboardEditingEnabled boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::lassoSelecting()

Returns true if a rubber-band lasso selection box is actively being dragged.

Returns boolean: True if enabled; false otherwise..

NodeGraph::lassoSelectionEnabled()

Returns true if rubber-band lasso box selection is enabled.

Returns boolean: True if enabled; false otherwise..

NodeGraph::lassoSelectionEnabled(boolean)

Sets whether rubber-band lasso selection is enabled.

Parameter Type Description
lassoSelectionEnabled boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::majorGridColor()

Returns the major grid lines color.

Returns MutableColor: The mutable color instance..

NodeGraph::maxZoom()

Returns maximum zoom scale factor.

Returns float: The maximum zoom factor..

NodeGraph::minZoom()

Returns minimum zoom scale factor.

Returns float: The minimum zoom factor..

NodeGraph::onConnectionCreated(EventListener)

Registers a listener called when a new connection is created.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onConnectionDragEnded(EventListener)

Registers a listener called when connection drag interaction completes or cancels.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onConnectionDragStarted(EventListener)

Registers a listener called when a connection drag starts from a port.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onConnectionRemoved(EventListener)

Registers a listener called when a connection is deleted.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onConnectionSelectionChanged(EventListener)

Registers a listener called when connection selection state changes.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onItemMoveEnded(EventListener)

Registers a listener called when item drag movement finishes.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onItemMoveStarted(EventListener)

Registers a listener called when item drag movement begins.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onItemMoved(EventListener)

Registers a listener called as an item is dragged across the canvas.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onItemRemoved(EventListener)

Registers a listener called when a node item is removed.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onItemResizeEnded(EventListener)

Registers a listener called when item resizing ends.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onItemResizeStarted(EventListener)

Registers a listener called when item resizing begins.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onItemResized(EventListener)

Registers a listener called as an item is being resized.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onSelectionChanged(EventListener)

Registers a listener called when item selection changes.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::onViewportChanged(EventListener)

Registers a listener called when viewport pan or zoom changes.

Parameter Type Description
listener EventListener The event listener callback.

Returns EventSubscription: The event subscription handle..

NodeGraph::panning()

Returns true if the viewport canvas is currently being panned.

Returns boolean: True if enabled; false otherwise..

NodeGraph::panningEnabled()

Returns true if canvas panning via mouse drag is enabled.

Returns boolean: True if enabled; false otherwise..

NodeGraph::panningEnabled(boolean)

Sets whether canvas panning is enabled.

Parameter Type Description
panningEnabled boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::port(NodeGraphPortRef)

Resolves a port reference to its corresponding port object.

Parameter Type Description
ref NodeGraphPortRef The port reference.

Returns NodeGraphPort: The port instance, or null if not found..

NodeGraph::portColor()

Returns default fill color for pin ports.

Returns MutableColor: The mutable color instance..

NodeGraph::preferredHeight()

Returns the preferred height of this graph.

Returns float: The preferred height in pixels..

NodeGraph::preferredHeight(float)

Sets the preferred height of this graph.

Parameter Type Description
preferredHeight float The preferred height in pixels.

Returns NodeGraph: This instance for chaining..

NodeGraph::preferredSize(float, float)

Sets both preferred width and height dimensions.

Parameter Type Description
width float The preferred width in pixels.
height float The preferred height in pixels.

Returns NodeGraph: This instance for chaining..

NodeGraph::preferredWidth()

Returns the preferred width of this graph.

Returns float: The preferred width in pixels..

NodeGraph::preferredWidth(float)

Sets the preferred width of this graph.

Parameter Type Description
preferredWidth float The preferred width in pixels.

Returns NodeGraph: This instance for chaining..

NodeGraph::removeConnection(NodeGraphConnection)

Removes the specified connection instance.

Parameter Type Description
connection NodeGraphConnection The connection parameter.

Returns NodeGraph: This instance for chaining..

NodeGraph::removeConnection(String)

Removes the connection with the given ID.

Parameter Type Description
id String The connection identifier.

Returns NodeGraph: This instance for chaining..

NodeGraph::removeItem(NodeGraphItem)

Removes the specified node item and all its connected lines.

Parameter Type Description
item NodeGraphItem The target item.

Returns NodeGraph: This instance for chaining..

NodeGraph::removeItem(String)

Removes the node item with the specified ID.

Parameter Type Description
id String The item identifier.

Returns NodeGraph: This instance for chaining..

NodeGraph::removeSelectedConnections()

Removes all currently selected connections.

Returns NodeGraph: This instance for chaining..

NodeGraph::resizeEnabled()

Returns true if interactive resizing of resizable items is enabled.

Returns boolean: True if enabled; false otherwise..

NodeGraph::resizeEnabled(boolean)

Sets whether interactive item resizing is enabled.

Parameter Type Description
resizeEnabled boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::resizeHandleColor()

Returns color of resize grip handles.

Returns MutableColor: The mutable color instance..

NodeGraph::restoreSnapshot(NodeGraphSnapshot, NodeGraphWidgetResolver)

Restores graph items, connections, and viewport from a serialized snapshot using a widget resolver.

Parameter Type Description
snapshot NodeGraphSnapshot The graph snapshot object.
resolver NodeGraphWidgetResolver The widget resolver callback.

Returns NodeGraph: This instance for chaining..

NodeGraph::scaleContentWithZoom()

Returns true if node item content widgets scale with zoom.

Returns boolean: True if enabled; false otherwise..

NodeGraph::scaleContentWithZoom(boolean)

Sets whether node item content widgets scale with zoom.

Parameter Type Description
scaleContentWithZoom boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::selectConnection(NodeGraphConnection)

Selects the specified connection.

Parameter Type Description
connection NodeGraphConnection The connection parameter.

Returns NodeGraph: This instance for chaining..

NodeGraph::selectConnection(String)

Selects the connection with the given ID.

Parameter Type Description
id String The connection identifier.

Returns NodeGraph: This instance for chaining..

NodeGraph::selectItem(NodeGraphItem)

Selects the specified item exclusively.

Parameter Type Description
item NodeGraphItem The target item.

Returns NodeGraph: This instance for chaining..

NodeGraph::selectItem(NodeGraphItem, boolean)

Selects the item with optional additive toggle behaviour.

Parameter Type Description
item NodeGraphItem The target item.
additive boolean Whether selection toggles additively.

Returns NodeGraph: This instance for chaining..

NodeGraph::selectItem(String)

Selects the item with the given ID exclusively.

Parameter Type Description
id String The item identifier.

Returns NodeGraph: This instance for chaining..

NodeGraph::selectedConnectionColor()

Returns highlight line color for selected connections.

Returns MutableColor: The mutable color instance..

NodeGraph::selectedConnectionIds()

Returns an unmodifiable list of IDs of currently selected connections.

Returns List: List of selected connection IDs..

NodeGraph::selectedItemBorderColor()

Returns selected border color for node items.

Returns MutableColor: The mutable color instance..

NodeGraph::selectedItemIds()

Returns an unmodifiable list of IDs of currently selected items.

Returns List: List of selected item IDs..

NodeGraph::selectionBoxBorderColor()

Returns border color for rubber-band selection rectangles.

Returns MutableColor: The mutable color instance..

NodeGraph::selectionBoxFillColor()

Returns fill color for rubber-band selection rectangles.

Returns MutableColor: The mutable color instance..

NodeGraph::selectionMode()

Returns current selection mode: NONE, SINGLE, or MULTIPLE.

Returns NodeGraphSelectionMode: The active selection mode..

NodeGraph::selectionMode(NodeGraphSelectionMode)

Sets selection mode.

Parameter Type Description
selectionMode NodeGraphSelectionMode The selection mode.

Returns NodeGraph: This instance for chaining..

NodeGraph::snapshot()

Captures a full serializable snapshot of the node graph.

Returns NodeGraphSnapshot: The serialized snapshot object..

NodeGraph::validateConnection(NodeGraphPortRef, NodeGraphPortRef)

Validates whether a connection can be established according to the active connection policy.

Parameter Type Description
from NodeGraphPortRef The source port reference.
to NodeGraphPortRef The destination port reference.

Returns NodeGraphConnectionValidation: The connection validation result..

NodeGraph::viewport()

Returns current viewport pan position and zoom factor.

Returns NodeGraphViewport: The current viewport transform..

NodeGraph::viewport(float, float)

Sets viewport pan position without altering zoom.

Parameter Type Description
x float The viewport X pan offset.
y float The viewport Y pan offset.

Returns NodeGraph: This instance for chaining..

NodeGraph::viewport(float, float, float)

Sets viewport pan position and zoom factor.

Parameter Type Description
x float The viewport X pan offset.
y float The viewport Y pan offset.
zoom float The zoom factor.

Returns NodeGraph: This instance for chaining..

NodeGraph::wheelPanStep()

Returns the pixel step distance per wheel tick during wheel panning.

Returns float: The pan distance per wheel tick in pixels..

NodeGraph::wheelPanStep(float)

Sets the pixel step distance per wheel tick.

Parameter Type Description
wheelPanStep float The pan distance per wheel tick in pixels.

Returns NodeGraph: This instance for chaining..

NodeGraph::wheelPanningEnabled()

Returns true if mouse wheel pans instead of zooming.

Returns boolean: True if enabled; false otherwise..

NodeGraph::wheelPanningEnabled(boolean)

Sets whether mouse wheel pans instead of zooming.

Parameter Type Description
wheelPanningEnabled boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::zoomEnabled()

Returns true if canvas zooming via mouse wheel is enabled.

Returns boolean: True if enabled; false otherwise..

NodeGraph::zoomEnabled(boolean)

Sets whether canvas zooming is enabled.

Parameter Type Description
zoomEnabled boolean Whether the feature or item is enabled.

Returns NodeGraph: This instance for chaining..

NodeGraph::zoomRange(float, float)

Configures minimum and maximum allowed zoom levels.

Parameter Type Description
minZoom float The minimum zoom factor.
maxZoom float The maximum zoom factor.

Returns NodeGraph: This instance for chaining..