连线数据模型(JsonLine / RGLine)
连线用于表示节点之间的方向关系。
与节点一样,连线也分为:
JsonLine:你输入的配置对象。RGLine:图谱运行时对象。
1. 基础模型
最小连线数据至少包含:
from: string起点节点 idto: string终点节点 id
示例:
const line = {
id: 'line-a-b',
from: 'a',
to: 'b',
text: 'A -> B'
};
2. 核心字段说明
标识与关系
id?: string(建议设置)from: stringto: stringtext?: stringtype?: stringdata?: Record<string, any>
形状与路径控制
lineShape?: RGLineShapefromJunctionPoint?: RGJunctionPointtoJunctionPoint?: RGJunctionPointjunctionOffset?: numberlineRadius?: number(直角折线圆角)polyLineStartDistance?: number(简易折线起始段)
样式与文字
color?: stringlineWidth?: numberopacity?: numberclassName?: stringfontColor?: stringfontSize?: numbertextOffsetX?: numbertextOffsetY?: numberplaceText?: 'start' | 'center' | 'end'textAnchor?: 'start' | 'middle' | 'end'
箭头与效果
startMarkerId?: stringendMarkerId?: stringdashType?: numberanimation?: numberuseTextOnPath?: boolean
行为控制
disablePointEvent?: booleanselected?: booleanhidden?: booleanforDisplayOnly?: boolean
3. 常见 CRUD 操作
// Create
graphInstance.addLine({ from: 'a', to: 'b', text: 'A -> B' });
graphInstance.addLines([{ from: 'b', to: 'c' }]);
// Read
const line = graphInstance.getLineById('line-a-b');
const allLines = graphInstance.getLines();
// Update
graphInstance.updateLine('line-a-b', {
color: '#60a5fa',
lineWidth: 3,
text: 'Updated'
});
// Delete
graphInstance.removeLineById('line-a-b');
4. 实战示例
const lines = [
{
id: 'l1',
from: 'root',
to: 'svc-a',
text: 'request',
lineShape: 2,
color: '#3b82f6',
endMarkerId: 'arrow-default',
data: { weight: 0.8 }
},
{
id: 'l2',
from: 'root',
to: 'svc-a',
text: 'fallback',
dashType: 2,
opacity: 0.8,
textOffsetY: -8
}
];
graphInstance.addLines(lines);
5. 关键注意事项
- 连线端点字段是
from/to,不是source/target。 - 文本字段是
text,不是label。 hidden: true只隐藏渲染,关系计算语义需结合运行时可见性理解。- 同一对节点支持多条连线,运行时会通过
RGLink提供索引信息。