Published
Edited
Nov 22, 2021
3 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
regression = ss.linearRegression(
box_counting_pic.cnts.map((o) => [-Math.log(o.s), Math.log(o.cnt)])
)
Insert cell
function box_count(canvas) {
let ctx = canvas.getContext("2d");
let im_data = ctx.getImageData(0, 0, canvas.width, canvas.height);

let cnts = [];
for (let s = 1; s <= d3.min([canvas.width, canvas.height]); s = 2 * s) {
let boxes = [];
let cnt = 0;
for (let i = 0; s * (i + 1) <= canvas.height; i++) {
for (let j = 0; s * (j + 1) <= canvas.width; j++) {
if (check_box(i, j, s)) {
cnt = cnt + 1;
boxes.push([i, j]);
}
}
}
cnts.push({ s: s, cnt: cnt, boxes: boxes });
}

function check_box(i, j, s) {
for (let i0 = i * s; i0 < (i + 1) * s; i0++) {
for (let j0 = j * s; j0 < (j + 1) * s; j0++) {
let ij0 = 4 * (j0 + i0 * canvas.width);
if (
im_data.data[ij0] == 0 &&
im_data.data[ij0 + 1] == 0 &&
im_data.data[ij0 + 2] == 0 &&
im_data.data[ij0 + 3] == 255
) {
return true;
}
}
}
return false;
}

return cnts;
}
Insert cell
mesh = ["Rucho_Lewis_Congress_3", "SL 2021-174 Congress"].map((d) =>
topojson.mesh(fractal_district_data, fractal_district_data.objects[d])
)
Insert cell
Insert cell
fractal_district_data = FileAttachment("nc_fractal_districts.json").json()
Insert cell
ss = require("simple-statistics")
Insert cell
topojson = require("topojson-client@3")
Insert cell
MathJax = require("https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js").catch(
() => window["MathJax"]
)
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