function Chart(coordinates, {
width = 640,
height = width / 2,
inset = 0,
precision = 0.2,
graticule = d3.geoGraticule10(),
projection = d3.geoEquirectangular().fitExtent([[inset, inset], [width - inset, height - inset]], {type: "Sphere"})
} = {}) {
const path = d3.geoPath(projection);
const line = {type: "LineString", coordinates};
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("overflow", "visible");
const g = svg.append("g")
.attr("fill", "none")
.attr("stroke", "#f00")
.attr("stroke-width", 1.5);
const pathGraticule = g.append("path")
.attr("stroke", "#999")
.attr("stroke-width", 0.5);
const pathLine = g.append("path");
let point = g.append("g")
.selectAll("circle");
return Object.assign(svg.node(), {
rotate(rotate) {
projection.rotate(rotate);
projection.precision(precision);
pathLine.attr("d", path(line));
const context = new BufferContext();
path.context(context)(line);
path.context(null);
point = point
.data(context.buffer())
.join("circle")
.attr("r", 4.5)
.attr("transform", (d) => `translate(${d})`);
projection.precision(0.2);
pathGraticule.attr("d", path(graticule));
return svg.node();
}
});
}