Self Links
A link is a connection between two different nodes. A "self link" is a single or multiple link from a node back to itself. They can help you to visualise certain scenarios, such as an organisation suspected of fraud that’s sending payments to itself, or direct loopbacks in an IT network.
Enabling Self Links
By default, support for self links is disabled and KeyLines discards them if they’re
loaded onto a chart. To enable support, use the chart selfLinks
option. For example:
chart.options({ selfLinks: true });
To create a self link, enter the same node id for the link’s id1
and id2
properties:
chart.load({ type: 'LinkChart', items: [ { type: 'node', id: 'a', c: 'blue' }, { type: 'link', id: 'b', id1: 'a', id2: 'a', a2: true } ]});
The a1 end of the self link is on the left side of the node; the a2 end is on the upper side.
If you want to use self links with the graph engine, see Using Self Links with Graph Functions.
Self Link Offsets
The off
property of a link specifies how far to offset its midpoint. For a direct link
between two nodes, this offset is measured from a straight line. Here's an example of a
direct link with its off
property set to 50:
For a self link, the off
property specifies how far the link is offset from its
default position. Here's a self link with an off
property of 50:
If a self link has a zero or unspecified off
property, it is centred on the position
where the upper left glyph is displayed:
You can specify multiple self links for a node. They'll be spaced apart in a similar way to multiple links between two standard nodes.
Note that self links cannot be dragged even when link dragging is set to true in the links property.
To see an example of implementing self links, see the Style Links demo.
Using Self Links with Graph Functions
Self links affect the following graph functions:
- The components function includes self links in each component's links array
- The neighbours function includes self links in its results
Self links don’t affect the majority of functions in the graph namespace:
- The centrality metrics (betweenness, closeness, eigenCentrality and pageRank) don't consider self links in their calculations
- The clusters function groups nodes into clusters and doesn't consider self links
- The degrees function doesn't count self links in the number of each node's links. This also means the kCores function isn't affected by them either.
- The distances and shortestPaths functions aren't affected, because no self link lies on a shortest path.
By default, the ability to use self links in the graph engine via KeyLines.getGraphEngine() is disabled and KeyLines discards them if they’re loaded onto a chart. To support
them, use the getGraphEngine() selfLinks
option. For example:
var graphEngine = KeyLines.getGraphEngine({ selfLinks: true });
This is only necessary if you're using the graph engine via KeyLines.getGraphEngine; if you are using it via chart.graph(), then you only need to call
chart.options({ selfLinks: true });