Skip to content

Instantly share code, notes, and snippets.

@BadCoder1337
BadCoder1337 / force_labels.js
Last active May 18, 2023 09:06 — forked from ZJONSSON/force_labels.js
Automatic floating labels using d3 force-layout
(function() {
d3.force_labels = function force_labels() {
var labels = d3.layout.force();
// Update the position of the anchor based on the center of bounding box
function updateAnchor() {
if (!labels.selection) return;
labels.selection.each(function(d) {
var bbox = this.getBBox(),
x = bbox.x + bbox.width / 2,