A corporation manager and dashboard for EVE Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var get_bounds = function(data) {
  2. var xmin = Infinity, xmax = -Infinity,
  3. ymin = Infinity, ymax = -Infinity;
  4. for (var sid in data["galaxy"]) {
  5. var system = data["galaxy"][sid];
  6. var x = system["coords"][0];
  7. var y = system["coords"][2];
  8. if (x < xmin) xmin = x;
  9. if (x > xmax) xmax = x;
  10. if (y < ymin) ymin = y;
  11. if (y > ymax) ymax = y;
  12. }
  13. var xspan = xmax - xmin;
  14. var yspan = ymax - ymin;
  15. return [xmin, ymin, xspan, yspan];
  16. }
  17. $(function() {
  18. $("#map").append($("<p>").text("Loading map data..."));
  19. $.getJSON( "map/data.json", data => {
  20. var [xmin, ymin, xspan, yspan] = get_bounds(data);
  21. var scale = 1000;
  22. $("#container > div").addClass("map-1");
  23. $("main").addClass("map-2");
  24. $("#map").empty().addClass("map-3");
  25. var svg = d3.select("#map").append("svg")
  26. .attr("viewBox", (-0.5 * scale) + " " + (-0.5 * scale) +
  27. " " + scale + " " + scale);
  28. var stars = svg.append("g");
  29. stars.selectAll("circle")
  30. .data(Object.values(data["galaxy"]))
  31. .enter()
  32. .append("circle")
  33. .attr("cx", d => {
  34. var x = d["coords"][0];
  35. return ((x - xmin) / xspan - 0.5) * scale;
  36. })
  37. .attr("cy", d => {
  38. var y = d["coords"][2];
  39. return ((y - ymin) / yspan - 0.5) * scale;
  40. })
  41. .attr("r", 2)
  42. .attr("class", d => {
  43. var sec = d["security"];
  44. var klass = sec < 0.05 ? "null" :
  45. Number(sec).toFixed(1).replace(".", "_");
  46. return "system sec-" + klass;
  47. });
  48. var lastk = 1;
  49. var zoom = d3.zoom()
  50. .scaleExtent([1, 50])
  51. .on("zoom", () => {
  52. var trans = d3.event.transform;
  53. var clamp = (scale / 2) * (trans.k - 1);
  54. trans.x = Math.max(Math.min(trans.x, clamp), -clamp);
  55. trans.y = Math.max(Math.min(trans.y, clamp), -clamp);
  56. stars.attr("transform", trans);
  57. if (trans.k != lastk) {
  58. stars.selectAll("circle").attr("r", 6 / (trans.k + 2));
  59. lastk = trans.k;
  60. }
  61. })
  62. svg.call(zoom);
  63. $(window).resize(() => {
  64. svg.style("display", "none")
  65. .attr("width", $("#map").width())
  66. .attr("height", $("#map").height() - 5)
  67. .style("display", "");
  68. });
  69. $(window).resize();
  70. });
  71. });