Arrows Customization
Arrow shape can be customized by setting arrowRenderer edge shape parameter,
for example:
const element = document.getElementById('canvas');
const canvas = new CanvasBuilder(element)
.setDefaults({
edges: {
shape: {
arrowRenderer: {
type: "triangle",
radius: 7,
}
}
}
})
.build();
The following arrow types are available:
| Type | Preview | Optional Parameters |
|---|---|---|
"wedge" | ![]() | radius,smallRadius,angle (in radians) |
"triangle" | ![]() | radius |
"arc" | ![]() | radius |
Also custom renderer function can be specified such as:
const arrowRenderer = (renderingParams) => {
const { arrowLength, direction, shift } = renderingParams;
const arrowPoints = [
{ x: 4, y: 0 },
{ x: arrowLength, y: 10 },
{ x: arrowLength, y: -10 },
];
const points = arrowPoints.map((point) => ({
x: direction.x * point.x - direction.y * point.y + shift.x,
y: direction.y * point.x + direction.x * point.y + shift.y,
}));
const move = `M ${points[0].x} ${points[0].y}`;
const line1 = `L ${points[1].x} ${points[1].y}`;
const line2 = `L ${points[2].x} ${points[2].y}`;
return `${move} ${line1} ${line2} Z`;
};
renderingParams.direction- vector to which arrow should be rotatedrenderingParams.shift- vector to which arrow should be shiftedrenderingParams.arrowLength- length that arrow should cover


