chart = {
const cx = width / 2;
const cy = height / 2;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("text-anchor", "middle")
.attr("fill", "currentColor")
.style("margin", "0 -14px")
.style("display", "block");
const defs = svg.append("g").append("defs")
defs.append("clipPath")
.attr("id", "horizonClip")
.append("path")
.attr("d", path(outline));
svg.append("path")
.attr("d", path(graticule))
.attr("fill", "none")
.attr("stroke", "currentColor")
.attr("stroke-opacity", 0.2)
.attr("clip-path", "url(#horizonClip)");
svg.append("path")
.attr("d", path(outline))
.attr("fill", "none")
.attr("stroke", "currentColor");
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
const sunPath_background = svg.append("g")
.attr("fill", "none")
.attr("stroke", "#333333")
.attr("stroke-dasharray", 3)
.attr("stroke-width", 1)
.attr("clip-path", "url(#horizonClip)");
const analemma_background = svg.append("g")
.attr("stroke", "#333333")
.attr("stroke-dasharray", 3)
.attr("fill", "none")
.attr("stroke-width", 1)
.attr("clip-path", "url(#horizonClip)");
const sunPath_foreground = svg.append("g")
.attr("fill", "none")
.attr("stroke", "#333333")
.attr("stroke-width", 2)
.attr("clip-path", "url(#horizonClip)");
const analemma_foreground = svg.append("g")
.attr("stroke", "#333333")
.attr("fill", "none")
.attr("stroke-width", 2)
.attr("clip-path", "url(#horizonClip)");
function update(solar) {
const ms = new Date(2014, -1, 1);
const mm = new Date(2014, 5, 1);
const me = new Date(2014, 11, 1);
const sunPaths = (s, e) => {
return d3.utcMonths(s, e).map(d => {
let start = d3.utcHour.offset(solar.noon(d), -12);
let end = d3.utcHour.offset(start, 24);
return {
type: "LineString",
coordinates: d3.utcMinutes(start, end).map(solar.position)
}
});
}
const analemmas = (s, e) => {
let start = d3.utcMonth.offset(s, 1);
let end = d3.utcMonth.offset(e, 1);
return d3.range(24).map(h => {
return {
type: "LineString",
coordinates: d3.utcDays(start, end).map(d => solar.position(d3.utcHour.offset(d, h)))
}
});
}
sunPath_foreground.selectAll("path")
.data(sunPaths(ms, mm))
// .join(
// enter => enter.append("path")
// .attr("d", d => path(d)),
// update => update
// .call(update => update.transition(t)
// .attr("d", d => path(d))),
// exit => exit
// .call(exit => exit.remove()));
.join("path")
.attr("d", d => path(d));
sunPath_background.selectAll("path")
.data(sunPaths(mm, me))
.join("path")
.attr("d", d => path(d));
analemma_foreground.selectAll("path")
.data(analemmas(ms, mm))
.join("path")
.attr("d", d => path(d));
analemma_background.selectAll("path")
.data(analemmas(mm, me))
.join("path")
.attr("d", d => path(d));
// const formatHour = d => d.toLocaleString("en", {hour: "numeric", timeZone: "America/Los_Angeles"})
// const formatMonth = d => d.toLocaleString("en", {month: "long", timeZone: "America/Los_Angeles"})
// hour.data(d3.utcHours(start, end));
// hour.attr("transform", d => `translate(${projection(solar.position(d))})`);
// hour.select("text:first-of-type").text(formatHour);
// hour.select("text:last-of-type").text(formatHour);
}
return Object.assign(svg.node(), {update});
}