Published
Edited
Mar 27, 2021
Importers
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function greedyLabeller(label_coords, xScale, yScale, p){
var L = label_coords.slice();

var popSplit = p.popSplit;
var textSize = p.textSize;
var textSize2 = p.textSize2;
var bufferSizeX = p.bufferSizeX;
var bufferSizeY = p.bufferSizeY;


L.forEach(d =>{
var svg = html`<svg style="border:solid 0px red;"><g name="content"><text font-size="
${((d.P > (1e6 * popSplit)) ? textSize : textSize2)}">
${DOM.text(d.Name)}
</text></g></svg>`;
document.body.appendChild(svg);
var box = svg.querySelector("[name=content]").getBBox();

d.boxWidth = box.width;
d.boxHeight = box.height;
svg.remove();
})



L.forEach(d => d.display = false);
for(var ii in d3.range(L.length)){
var d = L[ii];
var myTop = yScale(d.Y)-d.boxHeight;
var myBot = yScale(d.Y);
var myLeft = xScale(d.X)-d.boxWidth/2;
var myRight = xScale(d.X)+d.boxWidth/2;

var soFarSoGood = true;
console.log(L.filter(d => (d.display == true)))
for (var T of L.filter(x => x.display)){
var theirTop = yScale(T.Y)-T.boxHeight;
var theirBot = yScale(T.Y);
var theirLeft = xScale(T.X)-T.boxWidth/2;
var theirRight = xScale(T.X)+T.boxWidth/2;
if((theirRight<myLeft-bufferSizeX)|
(theirLeft>myRight+bufferSizeX)|
(theirTop>myBot+bufferSizeY)|
(theirBot<myTop-bufferSizeY)){
soFarSoGood &= true;
}else{
soFarSoGood &= false;
}
}
L[ii].display = soFarSoGood;
}
return L
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more