Published
Edited
Mar 3, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
html`
${rangeRects.map(
(rangeRect) => html`
<div style="
display: block;
position: absolute;
left: ${rangeRect.x}px;
top: ${rangeRect.y}px;
width: ${rangeRect.width}px;
height: ${rangeRect.height}px;
background: #6af;
z-index: -1;
"> </div>`
)}
${theDiv}
`
Insert cell
theDiv = {
let d = document.createElement("div");
d.textContent =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est.";
return d;
}
Insert cell
textNode = theDiv.childNodes[0]
Insert cell
range = {
let range = document.createRange();
range.setStart(textNode, start);
range.setEnd(textNode, end);
return range;
}
Insert cell
rangeRects = {
let offsetRect = theDiv.getClientRects()[0];
let rv = [];
for (const rect of range.getClientRects()) {
rv.push({
x: rect.x - offsetRect.x,
y: rect.y - offsetRect.y,
width: rect.width,
height: rect.height
});
}
return rv;
}
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