Overview
The WeaveConnectorNode class represents a line that connects two nodes pre-defined anchor points, the line is sticked to both nodes, if anyone of them moves, the line automatically adjusts and moves also.
The class extends the WeaveNode class
TypeScript types
type WeaveConnectorLineTypeKeys = keyof typeof WEAVE_CONNECTOR_NODE_LINE_TYPE;
type WeaveConnectorLineType =
(typeof WEAVE_CONNECTOR_NODE_LINE_TYPE)[WeaveConnectorLineTypeKeys];
type WeaveConnectorNodeDecoratorTypeKeys =
keyof typeof WEAVE_CONNECTOR_NODE_DECORATOR_TYPE;
type WeaveConnectorNodeDecoratorType =
(typeof WEAVE_CONNECTOR_NODE_DECORATOR_TYPE)[WeaveConnectorNodeDecoratorTypeKeys];
type WeaveConnectorNodeDecoratorOriginKeys =
keyof typeof WEAVE_CONNECTOR_NODE_DECORATOR_ORIGIN;
type WeaveConnectorNodeDecoratorOrigin =
(typeof WEAVE_CONNECTOR_NODE_DECORATOR_ORIGIN)[WeaveConnectorNodeDecoratorOriginKeys];
type WeaveConnectorNodeProperties = {
style: {
line: {
stroke: string;
strokeWidth: number;
tension: number;
lineCap: "butt" | "round" | "square";
lineJoin: "bevel" | "round" | "miter";
dash: number[];
hitStrokeWidth: number;
};
anchorNode: {
radius: number;
stroke: string;
strokeWidth: number;
anchoredFill: string;
hoveredFill: string;
fill: string;
};
pointsHandler: {
radius: number;
stroke: string;
strokeWidth: number;
fill: string;
};
curvedControl: {
radius: number;
stroke: string;
strokeWidth: number;
fill: string;
};
dot: {
radius: number;
stroke: string;
strokeWidth: number;
};
arrow: {
size: number;
stroke: string;
strokeWidth: number;
};
selection: {
color: string;
};
};
handlerSnapping: {
activateThreshold: number;
releaseThreshold: number;
};
lineType: WeaveConnectorLineType;
startNodeDecoratorType: WeaveConnectorNodeDecoratorType;
endNodeDecoratorType: WeaveConnectorNodeDecoratorType;
transform?: WeaveNodeTransformerProperties;
};
type WeaveConnectorNodeParams = {
config: DeepPartial<WeaveConnectorNodeProperties>;
};
type WeaveConnectorAnchor = {
name: string;
point: Konva.Vector2d;
};
type WeaveAnchorSnap = {
name: string | undefined;
position: Konva.Vector2d;
};
type WeaveConnectorInfo =
| {
type: "node";
node: Konva.Node;
anchor: string;
}
| {
type: "point";
point: Konva.Vector2d;
};
type WeaveConnectorPointPosition = "top" | "bottom" | "left" | "right";
Parameters
For WeaveConnectorNodeParams:
| Property | Type | Required | Description |
|---|---|---|---|
|
|
Required |
Config parameters for the node. |
For WeaveConnectorNodeProperties:
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
|
|
|
Defines stroke (color) of the connector line |
|
|
|
|
Width of the line |
|
|
|
|
Defines the line-cap (how the line is terminated at their ends) of the line |
|
|
|
|
Defines the line-join (how the line is connected - when multi segments like an elbow) of the line |
|
|
|
|
Defines the dashing properties of the line |
|
|
|
|
Defines the line hit stroke (making easies to select the line) |
|
|
|
|
Defines the anchor node radius |
|
|
|
|
Defines the anchor border color |
|
|
|
|
Defines the anchor border size |
|
|
|
|
Defines the anchor fill color when selected (anchored) |
|
|
|
|
Defines the anchor fill color when hovered |
|
|
|
|
Defines the anchor fill color (normal state) |
|
|
|
|
Defines the handlers (that allow to move the connector) radius |
|
|
|
|
Defines the handlers border color |
|
|
|
|
Defines the handlers border size |
|
|
|
|
Defines the handlers fill color |
|
|
|
|
Defines the handler (for the curved line control) radius |
|
|
|
|
Defines the handler border color |
|
|
|
|
Defines the handler border size |
|
|
|
|
Defines the handler fill color |
|
|
|
|
The color when an connector is selected |
|
|
|
|
The radius of the start and end line dot decorator |
|
|
|
|
The border color for the line dot decorator |
|
|
|
|
The border size for the line dot decorator |
|
|
|
|
The size of the start and end line arrow decorator |
|
|
|
|
The border color for the line arrow decorator |
|
|
|
|
The border size for the line arrow decorator |
|
|
|
|
Amount of pixels to activate the snapping to an anchor |
|
|
|
|
Amount of pixels to de-activate the snapping to an anchor |
|
|
|
|
Default line type |
|
|
|
|
Default start-line decorator type |
|
|
|
|
Default end-line decorator type |
Default values
const WEAVE_CONNECTOR_NODE_DEFAULT_CONFIG: WeaveConnectorNodeProperties = {
style: {
line: {
stroke: "#000000",
strokeWidth: 1,
lineCap: "butt",
lineJoin: "miter",
dash: [],
hitStrokeWidth: 10,
},
anchorNode: {
radius: 7,
stroke: "#000000",
strokeWidth: 1,
anchoredFill: "#ff2c2c",
hoveredFill: "#ff2c2cff",
fill: "#ffffff",
},
pointsHandler: {
radius: 7,
stroke: "#000000",
strokeWidth: 1,
fill: "#ffffff",
},
curvedControl: {
radius: 7,
stroke: "#000000",
strokeWidth: 1,
fill: "#ffffff",
},
selection: {
color: "#1a1aff",
},
dot: {
radius: 4,
stroke: "#000000",
strokeWidth: 0,
},
arrow: {
size: 10,
stroke: "#000000",
strokeWidth: 0,
},
},
handlerSnapping: {
activateThreshold: 20,
releaseThreshold: 25,
},
lineType: WEAVE_CONNECTOR_NODE_LINE_TYPE.STRAIGHT,
startNodeDecoratorType: WEAVE_CONNECTOR_NODE_DECORATOR_TYPE.NONE,
endNodeDecoratorType: WEAVE_CONNECTOR_NODE_DECORATOR_TYPE.NONE,
};