|
@@ -18,10 +18,25 @@ var get_bounds = function(galaxy) { |
|
|
return [xmin, ymin, xspan, yspan]; |
|
|
return [xmin, ymin, xspan, yspan]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var get_sec_class = function(sec) { |
|
|
|
|
|
return "sec-" + ( |
|
|
|
|
|
sec <= 0.0 ? "null" : |
|
|
|
|
|
Number(Math.max(sec, 0.1)).toFixed(1).replace(".", "_")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var get_faction_class = function(factions, faction) { |
|
|
|
|
|
if (faction < 0) |
|
|
|
|
|
return "neutral"; |
|
|
|
|
|
if (factions[faction] !== undefined) |
|
|
|
|
|
return "faction faction-" + S(factions[faction]["name"]).slugify(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$(function() { |
|
|
$(function() { |
|
|
$("#map .preload").append($("<p>").text("Loading map data...")); |
|
|
$("#map .preload").append($("<p>").text("Loading map data...")); |
|
|
$.getJSON( "map/data.json", data => { |
|
|
$.getJSON( "map/data.json", data => { |
|
|
var galaxy = data["systems"]; |
|
|
var galaxy = data["systems"]; |
|
|
|
|
|
var factions = data["factions"]; |
|
|
|
|
|
|
|
|
var systems = Object.values(galaxy); |
|
|
var systems = Object.values(galaxy); |
|
|
var jumps = [].concat |
|
|
var jumps = [].concat |
|
|
.apply([], Object.keys(galaxy) |
|
|
.apply([], Object.keys(galaxy) |
|
@@ -45,9 +60,9 @@ $(function() { |
|
|
var svg = d3.select("#map").append("svg") |
|
|
var svg = d3.select("#map").append("svg") |
|
|
.attr("viewBox", (-radius) + " " + (-radius) + |
|
|
.attr("viewBox", (-radius) + " " + (-radius) + |
|
|
" " + scale + " " + scale); |
|
|
" " + scale + " " + scale); |
|
|
var stars = svg.append("g"); |
|
|
|
|
|
|
|
|
var field = svg.append("g"); |
|
|
|
|
|
|
|
|
stars.selectAll("line") |
|
|
|
|
|
|
|
|
field.selectAll("line") |
|
|
.data(jumps) |
|
|
.data(jumps) |
|
|
.enter() |
|
|
.enter() |
|
|
.append("line") |
|
|
.append("line") |
|
@@ -58,19 +73,16 @@ $(function() { |
|
|
.attr("class", "jump") |
|
|
.attr("class", "jump") |
|
|
.style("stroke-width", 1); |
|
|
.style("stroke-width", 1); |
|
|
|
|
|
|
|
|
stars.selectAll("circle") |
|
|
|
|
|
|
|
|
field.selectAll("circle") |
|
|
.data(systems) |
|
|
.data(systems) |
|
|
.enter() |
|
|
.enter() |
|
|
.append("circle") |
|
|
.append("circle") |
|
|
.attr("cx", d => projx(d["coords"][0])) |
|
|
.attr("cx", d => projx(d["coords"][0])) |
|
|
.attr("cy", d => projy(d["coords"][2])) |
|
|
.attr("cy", d => projy(d["coords"][2])) |
|
|
.attr("r", 2) |
|
|
|
|
|
.attr("class", d => { |
|
|
|
|
|
var sec = d["security"]; |
|
|
|
|
|
var klass = sec <= 0.0 ? "null" : |
|
|
|
|
|
Number(Math.max(sec, 0.1)).toFixed(1).replace(".", "_"); |
|
|
|
|
|
return "system sec-" + klass; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
.attr("r", 2); |
|
|
|
|
|
|
|
|
|
|
|
var stars = field.selectAll("circle"); |
|
|
|
|
|
var jumps = field.selectAll("line"); |
|
|
|
|
|
|
|
|
var lastk = 1; |
|
|
var lastk = 1; |
|
|
var zoom = d3.zoom() |
|
|
var zoom = d3.zoom() |
|
@@ -81,14 +93,12 @@ $(function() { |
|
|
var clamp = radius * (trans.k - 1); |
|
|
var clamp = radius * (trans.k - 1); |
|
|
trans.x = Math.max(Math.min(trans.x, clamp), -clamp); |
|
|
trans.x = Math.max(Math.min(trans.x, clamp), -clamp); |
|
|
trans.y = Math.max(Math.min(trans.y, clamp), -clamp); |
|
|
trans.y = Math.max(Math.min(trans.y, clamp), -clamp); |
|
|
stars.attr("transform", trans); |
|
|
|
|
|
|
|
|
field.attr("transform", trans); |
|
|
$("#map-scale").val(Math.log2(trans.k + 1)); |
|
|
$("#map-scale").val(Math.log2(trans.k + 1)); |
|
|
|
|
|
|
|
|
if (Math.abs((trans.k - lastk) / lastk) > 0.1) { |
|
|
if (Math.abs((trans.k - lastk) / lastk) > 0.1) { |
|
|
stars.selectAll("circle") |
|
|
|
|
|
.attr("r", 6 / (trans.k + 2)); |
|
|
|
|
|
stars.selectAll("line") |
|
|
|
|
|
.style("stroke-width", 2 / (trans.k + 1)); |
|
|
|
|
|
|
|
|
stars.attr("r", 6 / (trans.k + 2)); |
|
|
|
|
|
jumps.style("stroke-width", 2 / (trans.k + 1)); |
|
|
lastk = trans.k; |
|
|
lastk = trans.k; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
@@ -97,7 +107,20 @@ $(function() { |
|
|
$("#map-scale").on("input", e => { |
|
|
$("#map-scale").on("input", e => { |
|
|
var k = Math.pow(2, e.target.value) - 1; |
|
|
var k = Math.pow(2, e.target.value) - 1; |
|
|
zoom.scaleTo(svg, k); |
|
|
zoom.scaleTo(svg, k); |
|
|
}) |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$('#map .controls input[name="color"]').change(function() { |
|
|
|
|
|
if (this.value == "sec") { |
|
|
|
|
|
stars.attr("class", d => |
|
|
|
|
|
"system " + get_sec_class(d["security"])); |
|
|
|
|
|
} |
|
|
|
|
|
else if (this.value == "faction") { |
|
|
|
|
|
stars.attr("class", d => |
|
|
|
|
|
"system " + get_faction_class(factions, d["faction"])); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$("#map-color-sec").prop("checked", true).change(); |
|
|
|
|
|
|
|
|
$(window).resize(() => { |
|
|
$(window).resize(() => { |
|
|
svg.style("display", "none") |
|
|
svg.style("display", "none") |
|
|