link.label(index)

Return the label at index.

link.label(index, properties [, opt])

Update properties of the label at index. By default, the new properties are merged into the old ones; pass the { rewrite: true } option along to disregard old properties.

Example usage:

link.label(0, {
    markup: [
        {
            tagName: 'rect',
            selector: 'body'
        }, {
            tagName: 'text',
            selector: 'label'
        }
    ],
    attrs: {
        body: {
            fill: 'white' // white background
        },
        label: {
            text: 'my label', // text to show
            fill: 'blue' // blue text
        }
    },
    position: {
        distance: 0.5, // midway on the connection path
        offset: {
            x: 10, // 10 local x units to the right
            y: -5 // 5 local y units above
        },
        angle: 45, // rotate by 45 degrees clockwise
        args: {
            keepGradient: true, // auto-rotate by path slope at distance
            ensureLegibility: true // auto-rotate label if upside-down
        }
    }
});

Note that all labels are stored in an array on the link model under the attribute labels. Use the link.labels function to access the array.