Skip to content

Labels

Node labels

For node labels, it is possible to show/hide them, specify the data to be displayed as labels, and change the display position.

TIP

In the above example, the key in the node object is specified as configs.node.text. Instead of a key, you can also specify a function that returns a string with the node object as an argument ((node) => string). If so, the return value of the executed function will be displayed as a label.

Override node labels

It is possible to replace an element with an override-node-label slot.
In the following example, two labels are displayed per node.

The props provided by the override-node-label slot are as follows:

propstypedescription
nodeIdstringnode Id
scalenumberscale factor linked to zoom
textstringlabel text
xnumberx position
ynumbery position
configNodeLabelStylestyle config for labels
shapeCircleShapeStyle /
RectangleShapeStyle
shape config of node
textAnchor"middle" / "start" / "end"text-anchor for SVG <text>
dominantBaseline"central" / "text-top" / "hanging"dominant-baseline for SVG <text>

See here for custom types

Automatic adjustment position

Depending on the positional relationship of the nodes, labels may overlap with edges and become difficult to read. For such cases, it is possible to automatically adjust the position of the label display according to the positional relationship of the nodes.

If configs.node.label.directionAutoAdjustment is set to true, the node label will try to avoid overlapping with edges. If it is determined that the edge overlaps at any position, it will be displayed at the position specified in configs.node.label.direction.

TIP

The default implementation determines the display position by determining the possibility of overlap between the edge to which its own node is connected and own node label. It does not determine if the label overlaps with edges between other nodes to which the node is not connected.

To specify the display position of a label in a different way from the default, specify a function that implemented the ideal processing in the configs.node.label.directionAutoAdjustment.

This function is executed for each node, and the arguments and return value are as follows.

Arguments:

typescript
{
    nodeId: string;
    pos: { x: number, y: number};
    oppositeNodes: {
      [edgeId]: {
        nodeId: string,
        pos: { x: number, y: number}
      }
    };
}

Return value:

typescript
"center" | "north" | "north-east" | "east"
| "south-east" | "south" | "south-west" | "west" | "north-west"
| null

Edge labels

For edge labels, use slots similar to custom labels for nodes.

The props provided by the edge-label slot are as follows:

propstypedescription
edgeIdstringedge Id
edgeEdgeuser defined edge object
configEdgeLabelStylestyle config for edge labels
area{source: {above: 0, below: 0},
target: {above: 0, below: 0} }
coordinates of the area to display labels
hoveredbooleanwhether hovered or not
selectedbooleanwhether selected or not

See here for custom types

You can draw the elements as you want using the properties provided by the slot, but you can use <v-edge-label> to automatically calculate the display position and rotation.
Supported attributes are listed below.

props / attrstypedescription
area(same as edge-label slot)coordinates of the area to display labels
configEdgeLabelStylestyle config for edge labels
textstringtext to display
align"center" / "source" / "target"horizontal direction to align text
vertical-align"center" / "above" / "below"vertical direction to align text
(other)anypass through to <text> element

INFO

Of the props provided in the edge-label slot, edgeId and edge are not required for <v-edge-label>. Other props should always be passed on to <v-edge-label> by using v-bind or by specifying them directly.

Multiple edge labels

In many cases, the labels of an edge not only indicate the edge itself, but also the result of the interaction of the nodes connected to the edge.
In the following example, we show three labels per edge. One displays the ID of the edge, and two display the ever-changing data at both ends of the edge.
The data being displayed is a random number.

Customize the edge label style

If you use <v-edge-label> component, the labels of edges can be customized from the config like the node labels.

Modify the style of edge labels when hovering/selecting edges

The edge-label slot prop contains a flag to get the edge selection/hover state. This can be combined with the style of the edge-label.

Summarized edge labels

Labels for summarized edges use a different slot than for normal edges.