Public
Edited
Dec 6, 2022
Fork of Swiss Clock
1 fork
Insert cell
Insert cell
html`${clock(now, local_coords)}`
Insert cell
Insert cell
Insert cell
html`${clock(now, local_coords, {size, color_day, color_night, color_day_ticks, color_night_ticks, color_border, color_hand_hours, color_hand_minutes, color_hand_seconds})}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
/*html`${
example_coords.map(coords => `<div style="display: inline-block;">${clock(now, coords, {size: 200})}<div style="text-align: center; font-family: sans-serif; font-weight: bold;">${coords.label}</div></div>`).join('')
}`*/
Insert cell
Insert cell
example_coords = [
{label: 'Helsinki', latitude: 60.192059, longitude: 24.945831},
{label: 'Rome', latitude: 41.902782, longitude: 12.496366},
{label: 'Lima', latitude: -12.046374, longitude: -77.042793},
{label: 'Tokyo', latitude: 35.652832, longitude: 139.839478},
{label: 'Sydney', latitude: -33.865143, longitude: 151.209900}
]
Insert cell
Insert cell
function clock(datetime, coords, options) {
options = options || {}
let size = options.size || 640
let color_day = options.color_day || 'white'
let color_night = options.color_night || 'black'
let color_day_ticks = options.color_day_ticks || 'black'
let color_night_ticks = options.color_night_ticks || 'white'
let color_border = options.color_border || '#CCC'
let color_hand_hours = options.color_hand_hours || '#888'
let color_hand_minutes = options.color_hand_minutes || '#333'
let color_hand_seconds = options.color_hand_seconds || 'red'

let sun = suncalc.getTimes(datetime, coords.latitude, coords.longitude)
let sunrise_angle = (new Date(sun.sunrise) - d3.timeDay(datetime)) / 864e5 * 2 * Math.PI
let sunset_angle = (new Date(sun.sunset) - d3.timeDay(datetime)) / 864e5 * 2 * Math.PI

let clip_uid = DOM.uid("clip")
return `<svg width="${size}" height="${size}" viewBox="50 50 500 500" style="display: inline-block;">
<defs>
<clipPath id="${clip_uid.id}">
<path d="${(d3.arc().innerRadius(0).outerRadius(225).startAngle(sunrise_angle).endAngle(sunset_angle))()}"/>
</clipPath>
</defs>
<g transform="translate(300,300)">
<g>
<circle r="225" fill="${color_night}"/>
${ticks(color_night_ticks)}
</g>
<g clip-path="${clip_uid}">
<circle r="225" fill="${color_day}"/>
${ticks(color_day_ticks)}
</g>
<circle r="230" stroke-width="18" fill="none" stroke="${color_border}"/>
<g transform="rotate(${(datetime - d3.timeDay(datetime)) / 864e5 * 360})">
<path d="M-13,47h26l-3,-186h-17z" fill="${color_hand_hours}"/>
</g>
<g transform="rotate(${(datetime - d3.timeHour(datetime)) / 36e5 * 360})">
<path d="M-9,40h18l-3,-220h-12z" fill="${color_hand_minutes}"/>
</g>
<g transform="rotate(${(datetime - d3.timeMinute(datetime)) / 6e4 * 360})">
<line y1="50" y2="-200" stroke="${color_hand_seconds}" stroke-width="4" />
<circle r="7" fill="${color_hand_seconds}" />
</g>
</g>
</svg>`
}
Insert cell
suncalc.getTimes(now, local_coords.latitude, local_coords.longitude)
Insert cell
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