Published
Edited
Jun 19, 2022
12 forks
Importers
63 stars
Insert cell
Insert cell
Insert cell
grid = html`<div style="
background: #fff;
display: grid;
height: ${screen.height / screen.width * 100}vw;
grid-template-areas:
'a b'
'a b'
'a b'
'c c';
grid-gap: 10px;
">
<div name="a" style="grid-area: a; border: solid 1px #ccc; position: relative;"></div>
<div name="b" style="grid-area: b; border: solid 1px #ccc; position: relative;"></div>
<div name="c" style="grid-area: c; border: solid 1px #ccc; position: relative;"></div>
</div>`
Insert cell
class Cell {
constructor(element) {
this.element = element;
element.style.position = "relative";
}
get width() {
return resizer(this.element, "clientWidth");
}
get height() {
return resizer(this.element, "clientHeight");
}
embed(content) {
content.style.position = "absolute";
content.style.width = "100%";
content.style.height = "auto";
if (this.element.firstChild) this.element.replaceChild(content, this.element.firstChild);
else this.element.appendChild(content);
}
}
Insert cell
function resizer(element, dimension = "clientWidth") {
return Generators.observe(notify => {
let width = notify(element[dimension]);
const resized = () => {
let w = element[dimension];
if (w !== width) notify(width = w);
};
window.addEventListener("resize", resized);
return () => window.removeEventListener("resize", resized);
});
}
Insert cell
cellA = new Cell(grid.querySelector("[name=a]"))
Insert cell
cellB = new Cell(grid.querySelector("[name=b]"))
Insert cell
cellC = new Cell(grid.querySelector("[name=c]"))
Insert cell
widthA = cellA.width
Insert cell
widthB = cellB.width
Insert cell
widthC = cellC.width
Insert cell
heightA = cellA.height
Insert cell
heightB = cellB.height
Insert cell
heightC = cellC.height
Insert cell
import {chart as chartA} with {widthA as width, heightA as height} from "@d3/bar-chart@268"
Insert cell
import {chart as chartB} with {widthB as width, heightB as height} from "@d3/force-directed-graph@149"
Insert cell
import {chart as chartC} with {widthC as width, heightC as height} from "@d3/band-chart@129"
Insert cell
cellA.embed(chartA)
Insert cell
cellB.embed(chartB)
Insert cell
cellC.embed(chartC)
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