Public
Edited
Jun 11, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function index2coords(index, length) {
const x = index % length;
const y = (index - x) / length;
return [x, y];
}
Insert cell
function getColor(x, y, cols) {
const center = [cols / 2, cols / 2];
const dist = distance(x, y, ...center);
const rUV = math.inverseLerp(0, maxDistance, dist);
const opacity = Math.max(1 - rUV, 0.05);
const hue = math.lerp(260, 80, rUV);
return `hsla(${hue} 80% 40% / ${opacity})`;
}
Insert cell
maxDistance = distance(0, 0, cols / 2, cols / 2)
Insert cell
0 == index2coords(3, 3)?.[0] && 1 == index2coords(3, 3)?.[1]
Insert cell
styles = htl.html`<style>
.viewport {
--border-color: #ddd;
--border-width: 1px;

width: ${viewportSize}px;
height: ${viewportSize}px;
background-color: var(--border-color);
overflow: auto;
border: var(--border-width) solid var(--border-color);
}

.grid {
display: grid;
grid-template-columns: repeat(${cols}, ${cellSize}px);
grid-template-rows: repeat(${cols}, ${cellSize}px);
gap: var(--border-width);
}

.cell {
background-color: white;
}

.cell {
display: grid;
place-items: center;
scroll-snap-align: start end;
}

.cell--dot::before {
content: '';
background-color: var(--dot-fill, red);
border-radius: 50%;
position: sticky;
inset: 0;
width: calc(var(--cell-size) * .333);
aspect-ratio: 1;
}

.main {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}

.main p {
margin-top: 0;
}

</style>`
Insert cell
viewportSize = Math.min(width, 480)

Insert cell
extend = 2
Insert cell
cellSize = viewportSize / visibleCols
Insert cell
cols = visibleCols * 3
Insert cell
import { distance } from "@saneef/helper-functions-geometry"
Insert cell
import { CSMath as math } from "@saneef/canvas-sketch-util"
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