v. 0.59.13b

This commit is contained in:
Azgaar 2018-09-06 01:06:56 +03:00
parent b1309eae71
commit 2f66891ecf
3 changed files with 49 additions and 20 deletions

View file

@ -4774,9 +4774,11 @@ function fantasyMap() {
if (overlay.selectAll("*").size() === 0) {
var type = styleOverlayType.value;
var size = +styleOverlaySize.value;
if (type === "hex") {
var hexbin = d3.hexbin().radius(size).size([svgWidth, svgHeight]);
overlay.append("path").attr("d", round(hexbin.mesh(), 0));
if (type === "pointyHex" || type === "flatHex") {
let points = getHexGridPoints(size, type);
let hex = "m" + getHex(size, type).slice(0, 4).join("l");
let d = points.map(function(p) {return "M" + p + hex;}).join("");
overlay.append("path").attr("d", d);
} else if (type === "square") {
var x = d3.range(size, svgWidth, size);
var y = d3.range(size, svgHeight, size);
@ -4799,6 +4801,35 @@ function fantasyMap() {
}
}
function getHex(radius, type) {
let x0 = 0, y0 = 0;
let s = type === "pointyHex" ? 0 : Math.PI / -6;
let thirdPi = Math.PI / 3;
let angles = [s, s + thirdPi, s + 2 * thirdPi, s + 3 * thirdPi, s + 4 * thirdPi, s + 5 * thirdPi];
return angles.map(function(angle) {
var x1 = Math.sin(angle) * radius,
y1 = -Math.cos(angle) * radius,
dx = x1 - x0,
dy = y1 - y0;
x0 = x1, y0 = y1;
return [dx, dy];
});
}
function getHexGridPoints(size, type) {
let points = [];
const rt3 = Math.sqrt(3);
const off = type === "pointyHex" ? rt3 * size / 2 : size * 3 / 2;
const ySpace = type === "pointyHex" ? size * 3 / 2 : rt3 * size / 2;
const xSpace = type === "pointyHex" ? rt3 * size : size * 3;
for (let y = 0, l = 0; y < graphHeight; y += ySpace, l++) {
for (let x = l % 2 ? 0 : off; x < graphWidth; x += xSpace) {
points.push([x, y]);
}
}
return points;
}
// clean data to get rid of redundand info
function cleanData() {
console.time("cleanData");
@ -9071,7 +9102,7 @@ function fantasyMap() {
if (!$("#toggleOverlay").hasClass("buttonoff")) toggleOverlay();
});
$("#styleOverlaySize").on("input", function() {
$("#styleOverlaySize").on("change", function() {
styleOverlaySizeOutput.value = this.value;
overlay.selectAll("*").remove();
if (!$("#toggleOverlay").hasClass("buttonoff")) toggleOverlay();