{"size": 796, "ext": "js", "max_stars_repo_path": "src/scalebar.js", "max_stars_repo_name": "Fil/bertin", "max_stars_repo_stars_event_min_datetime": "2022-01-15T17:29:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-15T17:29:46.000Z", "max_issues_repo_path": "src/scalebar.js", "max_issues_repo_name": "rbhttchr/mapbertin", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/scalebar.js", "max_forks_repo_name": "rbhttchr/mapbertin", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.6774193548, "max_line_length": 81, "alphanum_fraction": 0.6306532663}
import * as d3selection from "d3-selection";
import * as geoScaleBar from "d3-geo-scale-bar"
const d3 = Object.assign({}, d3selection, geoScaleBar);


export function addscalebar(selection, projection, width, height, options = {}) {
  let x = options.x ? options.x : 20;
  let y = options.y ? options.y : height - 30;
  let units = options.units ? options.units : "kilometers";

  x = x / width;
  y = y / height;

  const scaleBar = d3
    .geoScaleBar()
    .projection(projection)
    .size([width, height])
    .left(x)
    .top(y)
    .units(units == "miles" ? d3.geoScaleMiles : d3.geoScaleKilometers)
    .orient(d3.geoScaleBottom)
    .tickPadding(5)
    .tickSize(0);

  selection
    .append("g")
    .attr("transform", `translate(${x}, ${y})`)
    .append("g")
    .call(scaleBar);
 }
