This is a replacement for the d3.svg.chord() ribbon generator. The native d3 implementation is efficient, but its chords can become ‘twisted’ in certain curcumatances.
A chord has up to 4 components:
Components 2 and 3 are dropped if the chord has only one endpoint.
The problem arises when the arcs are very close to each other and one arc is significantly larger than the other. The inner bezier curve connecting the arcs extends towards the center of the circle. The outer bezier curve connecting the outer ends of the arc crosses the inner bezier curve causing the chords to look twisted.
The solution implemented here is to adjust the inner bezier curve to not extend into the circle very far. That is done by changing its control point. Instead of the control point being at the center of the circle, it is moved towards the edge of the circle in the direction of the midpoint of the bezier curve's end points.