Public
Edited
Nov 20, 2023
Insert cell
Insert cell
svg = DOM.svg(300, 200);


const rectGroup = DOM.g();

// Add rectangles to the group
const rect1 = DOM.rect(20, 20).attr('fill', 'blue');
const rect2 = DOM.rect(20, 20).attr('fill', 'red');
rectGroup.appendChild(rect1);
rectGroup.appendChild(rect2);

// Append the group to the SVG container
svg.appendChild(rectGroup);

// Define an Observable slider
slider = html`<input type="range" min="1" max="5" value="1" />`;

// Update the rectangle sizes based on the slider value
mutable resizeRectangles = {
const scaleFactor = +slider.value;
rect1.attr('width', 20 * scaleFactor).attr('height', 20 * scaleFactor);
rect2.attr('width', 20 * scaleFactor).attr('height', 20 * scaleFactor);
};
Insert cell
html`${svg}${slider}${resizeRectangles}`
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