Published
Edited
1 fork
28 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
patternWeights = {
const wght = bias * 0.5 + 0.5;

return [
{ value: 0, weight: wght },
{ value: 1, weight: 1 - wght }
];
}
Insert cell
centers = hexbin.centers().map((pos) => {
const p = [...pos];
p.pattern = "hex-" + random.weightedSet(patternWeights);
return p;
})
Insert cell
function hexgonTile(opts = {}) {
const { id, r, strokeWidth, spokes, drawBorder, background } = Object.assign(
{
r: 1,
strokeWidth: 1,
spokes: [0, 2, 4],
drawBorder: true,
background: false
},
opts
);
const vertices = 6;
const dAngle = (Math.PI * 2) / vertices;
const angleOffset = -dAngle / 2;
const points = d3.range(6).map((i) => {
const angle = i * dAngle;
return [
r * Math.cos(angle + angleOffset),
r * Math.sin(angle + angleOffset)
];
});

const [x0, y0] = [0, 0];
function drawSpokes() {
return points
.map((p, i) => {
if (spokes.includes(i)) {
return svg`<line x1=${x0} y1=${y0} x2=${p[0]} y2=${p[1]}></line>`;
}
})
.filter(Boolean);
}

// transform=${`rotate(${radToDeg(-rotate * dAngle)})`}
return svg`<g
id=${id}
stroke="${palette.fg}"
stroke-width=${strokeWidth}
stroke-linecap="round"
>
<path
d="${d3.line()(points)}z"
fill=${background ? palette.bg : "none"}
stroke=${drawBorder ? palette.fg : "none"}
></path>
${drawSpokes()}
</g>`;
}
Insert cell
hexbin = d3Hexbin()
.extent([
[0, 0],
[w, h]
])
.radius(radius)
Insert cell
w = width
Insert cell
aspectRatio = 16 / 9
Insert cell
h = w / aspectRatio
Insert cell
palette = ({
bg: `hsl(0,0%,95%)`,
fg: `hsl(0,0%,5%)`,
debug: "#f0f"
})
Insert cell
svg = htl.svg
Insert cell
random = {
rnd.setSeed(randomize);
return rnd;
}
Insert cell
Insert cell
radToDeg = (rad) => (rad * 180) / Math.PI
Insert cell
Insert cell
Insert cell
import { seedButton } from "@saneef/seed-button"
Insert cell
import { CSRandom as rnd } from "@saneef/canvas-sketch-util"
Insert cell
import { getNotebookUrlWithParams, params } from "@saneef/notebook-url"
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