Node Data (JsonNode / RGNode)
Node is the fundamental data unit in relation-graph.
In practice you work with two forms:
JsonNode: the input/config object you provide.RGNode: the runtime object generated by graph engine after data is added.
1. JsonNode vs RGNode
- Use
JsonNodeto define data. - Use
RGNodewhen reading runtime state from instance APIs. RGNodecontains extra runtime-calculated fields (visibility/layout/runtime dimensions).
Typical flow:
const nodeA = { id: 'a', text: 'Node A' };
graphInstance.addNodes([nodeA]);
const rgNodeA = graphInstance.getNodeById('a'); // RGNode
2. Core Fields You Should Know
Identity and Label
id: stringrequired and unique.text?: stringlabel text.
relation-graph uses
text, notlabel.
Interaction and State
expanded?: booleanselected?: booleandisablePointEvent?: booleandisableDrag?: booleanhidden?: boolean
Visual Style
className?: stringnodeShape?: RGNodeShapecolor?: stringborderColor?: stringborderWidth?: numberborderRadius?: numberfontColor?: stringfontSize?: numberopacity?: number
Geometry
width?: number,height?: numberx?: number,y?: numberzIndex?: number- runtime-only measured size:
el_W,el_H
Business and Tree Fields
data?: Record<string, any>business payload.children?: JsonNode[]tree shorthand for import.type?: stringuseful for style grouping (rg-node-type-{type}).
3. CRUD Operations
// Create
graphInstance.addNode({ id: 'n1', text: 'N1' });
graphInstance.addNodes([{ id: 'n2', text: 'N2' }]);
// Read
const node = graphInstance.getNodeById('n1');
const allNodes = graphInstance.getNodes();
// Update
graphInstance.updateNode('n1', {
text: 'N1 Updated',
color: '#4ade80'
});
// Delete
graphInstance.removeNodeById('n2');
4. Practical Example
const nodes = [
{
id: 'root',
text: 'Root',
type: 'service',
className: 'node-root',
color: '#dbeafe',
width: 140,
height: 48,
data: { owner: 'team-a' }
},
{
id: 'worker-1',
text: 'Worker 1',
type: 'worker',
x: 420,
y: 180,
fixed: true
}
];
graphInstance.addNodes(nodes);
5. Important Notes
- Keep
idstable and unique across updates. - If you manually assign
x/y, avoid automatic layout or use fixed/manual layout strategy. childrenis for import convenience; graph runtime works on flattened node/link structures.- If width/height are not specified, layout may need a short delay to wait for measured node size.