Published
Edited
Apr 30, 2020
2 forks
Importers
12 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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
square_grid = (s=100, n=10, go=[0.5, 0.5], co=[0.5, 0.5]) => {
const cs = s / n;
const x = i => (i % n) * cs - (cs * n * go[0]) + (cs * co[0]);
const y = i => Math.floor(i / n) * cs - (cs * n * go[1]) + (cs * co[1]);
const grid = [...Array(n * n).keys()];
grid.forEach((v, i) => { grid[i] = {i: i, x: x(i), y: y(i), r: cs } });
return grid;
}
Insert cell
Insert cell
dot_matrix = (svg, s, n) => {
// Create a group container for the dots
const g = svg.append("g");
// Create the grid data and join to group
let circles = g.selectAll("circle")
.data(square_grid(s, n));
// Map the data to create a matrix of dots
circles.enter()
.append("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", d => 6)
.attr("fill", "#F9A825");
circles.exit().remove();
// Return the container
return g;
}
Insert cell
line_grid = (svg, s, n) => {
// Create a group container for the squares
const g = svg.append("g");
// Create the grid data and join to group
let squares = g.selectAll("rect")
.data(square_grid(s, n, [0.5, 0.5], [0, 0]));
// Map the data to create a matrix of squares
squares.enter()
.append("rect")
.attr("x", d => d.x)
.attr("y", d => d.y)
.attr("width", d => d.r)
.attr("height", d => d.r)
.attr("fill", "none")
.attr("stroke-width", 1.6)
.attr("stroke", "#212121");
squares.exit().remove();
return g;
}
Insert cell
background = svg => {
const rect = svg.append("rect")
.attr("width", "100%")
.attr("height", "100%")
.attr("fill", "#EEEEEE");
return rect;
}
Insert cell
caption = (svg, txt) => {
const text = svg.append("text");
text
.text(txt)
.attr("text-anchor", "middle")
.attr("x", height/2)
.attr("y", height - 40)
.attr("fill", "#212121")
.attr("font-size", 14)
.attr("font-weight", 900);
return text;
}
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