
new Node(): Node
A Node is a singular processing unit in a Flow accepting inputs through input terminals and producing output through output terminals for other connected nodes/flows.
A node can also have interactive UI inside it, using UINodes for showing labels, selectors, toggles, files, sliders, buttons, dials, images, and a lot more.
new Node(): Node
flow: Flow
focused: boolean
group: Group
id: string
inputs: Terminal
inputsUI: Terminal
name: string
nodeButtons: Map<string, NodeButton>
outputs: Terminal
outputsUI: Terminal
renderers: NodeRenderers
Any custom render functions specified using this resolver will affect everything only inside this node instance.
renderState: RenderState
{ viewport: ViewPort.INSIDE, nodeState: NodeState.MAXIMIZED, lod: LOD.LOD2 }
state: Record<string, any>
let customNode = flow.createNode("Custom Node", Vector.create(50, 50), 170, {
state: {
name: "John Doe",
age: 24,
},
});
style: NodeStyle
{
font: 'arial',
fontSize: '.75rem',
titleFont: 'arial',
titleFontSize: '.85rem',
color: '#000',
titleColor: '#000',
maximizeButtonColor: 'darkgrey',
nodeButtonSize: 10,
nodeButtonSpacing: 5,
expandButtonColor: '#000',
minimizedTerminalColor: 'green',
outlineColor: '#000',
padding: 10,
spacing: 10,
rowHeight: 20,
titleHeight: 29,
terminalRowHeight: 24,
terminalStripMargin: 8
}
terminalStyle: TerminalStyle
terminals: Map<string, Terminal>
ui: Container
uiNodes: Map<string, UINode>
height: number
position: Vector
width: number
zIndex: number
addNodeButton(callback: () => void, render: RenderFn<NodeButton, NodeButtonRenderParams>, align: Align): NodeButton
node.addNodeButton(
() => doSomething(),
(context: CanvasRenderingContext2D, params: NodeButtonRenderParams, nodeButton: NodeButton) => {
let style = nodeButton.node.style;
context.strokeStyle = style.color;
context.beginPath();
context.arc(params.position.x, params.position.y, 10, 0, 2 * Math.PI);
context.closePath();
context.stroke();
},
Align.Right
);
addTerminal(terminal: Terminal | SerializedTerminal): void
node.addTerminal(new Terminal(node, TerminalType.IN, "string", "first-name"));
addTerminals(terminals: Terminal[] | SerializedTerminal[]): void
call(eventKey: string, ...args: any): void
Not Recommended
Using the create
method can lead to unexpected results, use the Flow.createNode method instead
create<T extends Node>( type: string, flow: Flow, position: Vector, options: NodeOptions, isDeserialized: boolean ): T
created<T extends NodeOptions>( options: T ): void
creatUI<T extends UINode, O extends UINodeOptions>( type: string, options: O ): T
let button = node.createUI("core/button", { text: "Click me" });
node.ui.append(button);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 150,
state: { dialValue: 65 },
});
let dial = node.createUI("core/dial", {
min: 0,
max: 100,
height: 100,
propName: "dialValue",
});
let label = node.createUI("core/label", {
text: node.state.dialValue,
propName: "dialValue",
style: { align: Align.Center, fontSize: "14px", precision: 0 },
});
node.ui.append([dial, label]);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
});
let display = node.createUI("core/display", {
height: 150,
customRenderers: [
{
auto: true,
clear: true,
renderer: (context, width, height) => {
for (let i = 0; i < 100; i++) {
context.fillStyle = Color.Random().hexValue;
context.fillRect(Math.random() * width, Math.random() * height, 5, 5);
}
return true;
},
},
],
});
node.ui.append(display);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
});
let envelope = node.createUI("core/envelope", {
height: 150,
values: [Vector.create(0.1, 0.1), Vector.create(0.3, 0.8), Vector.create(0.75, 0.3), Vector.create(0.9, 0.7)],
});
node.ui.append(envelope);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
});
let hozLayout = node.createUI("core/x-layout", {
childs: [
node.createUI("core/label", {
text: "W: 0.2",
style: { grow: 0.2, backgroundColor: "#0f0", align: Align.Center },
}),
node.createUI("core/label", {
text: "W: 0.5",
style: { grow: 0.5, backgroundColor: "#e0e", align: Align.Center },
}),
node.createUI("core/label", {
text: "W: 0.3",
style: { grow: 0.3, backgroundColor: "#0ff", align: Align.Center },
}),
],
});
node.ui.append(hozLayout);
let node = flow.createNode("cpre/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
});
let image = node.createUI("core/image", {
src: "/assets/hero.png",
style: { align: Align.Center },
});
node.ui.append(image);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
});
let input = node.createUI("core/input", { value: "Sample Text" });
node.ui.append(input);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
});
let label = node.createUI("core/label", { text: "Sample Label" });
node.ui.append(label);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
});
let radioGroup = node.createUI("core/radio-group", {
values: ["Sample A", "Sample B", "Sample C"],
selected: "Sample B",
});
node.ui.append(radioGroup);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
style: { rowHeight: 10 },
});
let select = node.createUI("core/select", { values: ["Sample A", "Sample B", "Sample C"] });
node.ui.append(select);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
style: { rowHeight: 10 },
state: { sliderValue: -18 },
});
let hozLayout = node.createUI("core/x-layout", {
childs: [
node.createUI("core/slider", {
min: -100,
max: 100,
propName: "sliderValue",
style: { grow: 0.8 },
}),
node.createUI("core/label", {
text: node.state.sliderValue,
propName: "sliderValue",
style: { grow: 0.2, align: Align.Center, precision: 0 },
}),
],
});
node.ui.append(hozLayout);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
style: { rowHeight: 10 },
});
let slider2D = node.createUI("core/2d-slider", {
height: 100,
value: Vector.create(0.2, 0.8),
});
node.ui.append(slider2D);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
style: { rowHeight: 20 },
});
let source = node.createUI("core/source");
node.ui.append(source);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
});
let stack = node.createUI("core/stack", {
childs: [
node.createUI("core/label", {
text: "A",
height: 20,
style: { backgroundColor: "#0f0", align: Align.Center },
}),
node.createUI("core/label", {
text: "B",
height: 60,
style: { backgroundColor: "#e0e", align: Align.Center },
}),
node.createLabel("core/label", {
text: "C",
height: 30,
style: { backgroundColor: "#0ff", align: Align.Center },
}),
],
spacing: 5,
});
node.ui.append(stack);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
style: { rowHeight: 10 },
});
let toggle = node.createUI("core/toggle");
node.ui.append(toggle);
let node = flow.createNode("core/empty", Vector.create(50, 50), {
name: "Node",
width: 230,
state: { vSliderValue: -22 },
});
let stack = node.createUI("core/stack", {
childs: [
node.createUI("core/v-slider", {
min: -50,
max: 50,
height: 150,
propName: "vSliderValue",
}),
node.createUI("core/label", {
text: node.state.vSliderValue,
propName: "vSliderValue",
style: { align: Align.Center, fontSize: "16px" },
}),
],
style: { spacing: 20 },
});
node.ui.append(stack);
dispose(): void
getInput(terminal: string | number): any
getInputs(): any[]
off(eventKey: string, id: number): void
offAll(): void
on(eventKey: string, callback: (...args: any) => void): number
process(inputs: any[]): void
removeTerminal(terminal: Terminal): void
serialize( persist?: DataPersistenceProvider ): Promise<SerializedNode>
setOutputs(outputs: string | number | Record<string, any>, data?: any): void
node.setOutputs("first-name", "John");
Setting output on single terminal using it's index:
node.setOutputs(2, "John");
Setting output on mulitple terminals at once:
node.setOutputs({
"first-name": "John",
"last-name": "Doe",
age: 24,
});
setupIO(options: NodeOptions): void
toggle(): void
toggleNodeState(): void
watch(propName: string, callback: (oldVal: any, newVal: any) => void): number
unwatch(propName: string, id: number): void