Published
Edited
Jul 21, 2018
Insert cell
Insert cell
circle = html`
<style>
div.circle {
border: 3px solid #f00;
border-radius: 50%;
width: 12px;
height: 12px;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-color: #fcc;
}
</style>
<div class="circle">
</div>`
Insert cell
Insert cell
π = Math.PI
Insert cell
τ = 2 * π
Insert cell
rad = 180 / π
Insert cell
Insert cell
Insert cell
radius = 3
Insert cell
lineWidth = 3
Insert cell
lineColor = '#000'
Insert cell
dot = {
const boxSize = 2*(radius + lineWidth);
const canvas = DOM.canvas(boxSize, boxSize);
const context = canvas.getContext('2d');
context.fillStyle = '#333';
context.strokeStyle = lineColor;
context.lineWidth = lineWidth;
context.beginPath();
context.arc(radius + lineWidth/2, radius + lineWidth/2, radius,
0, τ, true); // startAngle, endAngle, counterclockwise
context.stroke();
return canvas;
}
Insert cell
Insert cell
{
download;
return save(dot, 'dot.png');
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more