Skip to content

Instantly share code, notes, and snippets.

@nautilytics
Last active August 19, 2020 16:43
Show Gist options
  • Save nautilytics/e8a2ac703fb937b5c02fff510547fe3a to your computer and use it in GitHub Desktop.
Save nautilytics/e8a2ac703fb937b5c02fff510547fe3a to your computer and use it in GitHub Desktop.
Use Labella for placing labels on a vertical axis
import labella from 'labella';
let points = [];
const force = new labella.Force()
.nodes(points.map((d) => new labella.Node(d.y, 15, d))) // 15 is label height/spacing
.compute();
points = points.map((d) => {
const matchingNode = force.nodes().find((node) => node.data.id === d.id);
return {
...d,
labelY: matchingNode.currentPos,
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment