function drawMap(svg, geoData, options = {}) {
options = optionsDefault(options);
const completeMap = getCompleteGeoJSONMap(geoData);
const geojsonData = convertTopoJSONToGeoJSON(geoData);
const projection = options.projection.fitExtent(
[
[options.padding, options.padding],
[options.width - options.padding, options.height - options.padding]
],
completeMap
);
const funcGetPathD = d3.geoPath(projection);
const isSimulation = options.nSimulationTicks > 0;
const initXY = d => projection(d3.geoCentroid(d));
if (isSimulation) {
const simulation = d3
.forceSimulation(geojsonData)
.force("x", d3.forceX(d => initXY(d)[0]))
.force("y", d3.forceY(d => initXY(d)[1]))
.force("collide", d3.forceCollide(d => 0.5 + options.funcDataToRadius(d)))
.stop();
for (let i = 0; i < options.nSimulationTicks; i++) {
simulation.tick();
}
}
geojsonData.forEach(function(geojsonDatum, i) {
svg
.append("path")
.attr("fill", options.funcDataToColor(geojsonDatum))
.attr('fill-opacity', options.pathFillOpacity)
.attr('stroke', options.stroke)
.attr('stroke-width', options.strokeWidth)
.attr("d", funcGetPathD(geojsonDatum));
});
geojsonData.forEach(function(geojsonDatum, i) {
const [x, y] = isSimulation
? [geojsonDatum.x, geojsonDatum.y]
: initXY(geojsonDatum);
options.funcDrawLabel(geojsonDatum, svg, [x, y], options);
});
}