Public
Edited
Apr 14, 2023
1 star
Insert cell
Insert cell
Insert cell
viewof mies = {
const value = [0, 0, 0, 0, 0]

const color = (c) => d3.schemeCategory10[c % d3.schemeCategory10.length];

const createButton = (v, i) => {

const x = i * 50, y = 0;
const text = svg`<text dy=5 style="text-anchor:middle; fill:white; font-family:monospace; font-weight:999;">${v}</text>`;
const button = svg`<g transform="translate(${x} ${y})" style="opacity:.3;"><circle r="20"/>${text}</g>`;

button.onmouseenter = () => {
button.style.fill = color(v);
button.style.opacity = 1;
value[i] = ++v;
text.textContent = v;
view.dispatchEvent(new CustomEvent("input"));
};

button.onmouseleave = () => {
button.style.opacity = .3;
};

return button;
};

const view = svg`<svg width="${width}" height="${width/16*2}" viewBox="-20 -10 600 50">${value.map(createButton)}</svg>`;

view.value = value;
return view;
}
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