refactor: drawPrecipitation

This commit is contained in:
Azgaar 2024-09-04 22:53:14 +02:00
parent b3dc8da683
commit 7d461aa8f1
7 changed files with 18 additions and 14 deletions

View file

@ -646,11 +646,11 @@
Ice Ice
</li> </li>
<li <li
id="togglePrec" id="togglePrecipitation"
data-tip="Precipitation map: click to toggle, drag to raise or lower the layer. Ctrl + click to edit layer style" data-tip="Precipitation map: click to toggle, drag to raise or lower the layer. Ctrl + click to edit layer style"
data-shortcut="A" data-shortcut="A"
class="buttonoff" class="buttonoff"
onclick="togglePrec(event)" onclick="togglePrecipitation(event)"
> >
Precipit<u>a</u>tion Precipit<u>a</u>tion
</li> </li>

View file

@ -440,7 +440,7 @@ async function parseLoadedData(data, mapVersion) {
if (hasChildren(temperature)) turnOn("toggleTemperature"); if (hasChildren(temperature)) turnOn("toggleTemperature");
if (hasChild(population, "line")) turnOn("togglePopulation"); if (hasChild(population, "line")) turnOn("togglePopulation");
if (hasChildren(ice)) turnOn("toggleIce"); if (hasChildren(ice)) turnOn("toggleIce");
if (hasChild(prec, "circle")) turnOn("togglePrec"); if (hasChild(prec, "circle")) turnOn("togglePrecipitation");
if (isVisible(emblems) && hasChild(emblems, "use")) turnOn("toggleEmblems"); if (isVisible(emblems) && hasChild(emblems, "use")) turnOn("toggleEmblems");
if (isVisible(labels)) turnOn("toggleLabels"); if (isVisible(labels)) turnOn("toggleLabels");
if (isVisible(icons)) turnOn("toggleIcons"); if (isVisible(icons)) turnOn("toggleIcons");

View file

@ -211,7 +211,7 @@ function showMapTooltip(point, e, i, g) {
if (group === "ice") return tip("Click to edit the Ice"); if (group === "ice") return tip("Click to edit the Ice");
// covering elements // covering elements
if (layerIsOn("togglePrec") && land) tip("Annual Precipitation: " + getFriendlyPrecipitation(i)); if (layerIsOn("togglePrecipitation") && land) tip("Annual Precipitation: " + getFriendlyPrecipitation(i));
else if (layerIsOn("togglePopulation")) tip(getPopulationTip(i)); else if (layerIsOn("togglePopulation")) tip(getPopulationTip(i));
else if (layerIsOn("toggleTemperature")) tip("Temperature: " + convertTemperature(grid.cells.temp[g])); else if (layerIsOn("toggleTemperature")) tip("Temperature: " + convertTemperature(grid.cells.temp[g]));
else if (layerIsOn("toggleBiomes") && pack.cells.biome[i]) { else if (layerIsOn("toggleBiomes") && pack.cells.biome[i]) {

View file

@ -78,7 +78,7 @@ function handleKeyup(event) {
else if (code === "KeyT") toggleTemperature(); else if (code === "KeyT") toggleTemperature();
else if (code === "KeyN") togglePopulation(); else if (code === "KeyN") togglePopulation();
else if (code === "KeyJ") toggleIce(); else if (code === "KeyJ") toggleIce();
else if (code === "KeyA") togglePrec(); else if (code === "KeyA") togglePrecipitation();
else if (code === "KeyY") toggleEmblems(); else if (code === "KeyY") toggleEmblems();
else if (code === "KeyL") toggleLabels(); else if (code === "KeyL") toggleLabels();
else if (code === "KeyI") toggleIcons(); else if (code === "KeyI") toggleIcons();

View file

@ -171,7 +171,7 @@ function restoreLayers() {
if (layerIsOn("toggleCompass")) compass.style("display", "block"); if (layerIsOn("toggleCompass")) compass.style("display", "block");
if (layerIsOn("toggleRoutes")) drawRoutes(); if (layerIsOn("toggleRoutes")) drawRoutes();
if (layerIsOn("toggleTemperature")) drawTemperature(); if (layerIsOn("toggleTemperature")) drawTemperature();
if (layerIsOn("togglePrec")) drawPrec(); if (layerIsOn("togglePrecipitation")) drawPrecipitation();
if (layerIsOn("togglePopulation")) drawPopulation(); if (layerIsOn("togglePopulation")) drawPopulation();
if (layerIsOn("toggleBiomes")) drawBiomes(); if (layerIsOn("toggleBiomes")) drawBiomes();
if (layerIsOn("toggleRelief")) ReliefIcons.draw(); if (layerIsOn("toggleRelief")) ReliefIcons.draw();
@ -242,14 +242,14 @@ function drawBiomes() {
TIME && console.timeEnd("drawBiomes"); TIME && console.timeEnd("drawBiomes");
} }
function togglePrec(event) { function togglePrecipitation(event) {
if (!prec.selectAll("circle").size()) { if (!prec.selectAll("circle").size()) {
turnButtonOn("togglePrec"); turnButtonOn("togglePrecipitation");
drawPrec(); drawPrecipitation();
if (event && isCtrlClick(event)) editStyle("prec"); if (event && isCtrlClick(event)) editStyle("prec");
} else { } else {
if (event && isCtrlClick(event)) return editStyle("prec"); if (event && isCtrlClick(event)) return editStyle("prec");
turnButtonOff("togglePrec"); turnButtonOff("togglePrecipitation");
const hide = d3.transition().duration(1000).ease(d3.easeSinIn); const hide = d3.transition().duration(1000).ease(d3.easeSinIn);
prec.selectAll("text").attr("opacity", 1).transition(hide).attr("opacity", 0); prec.selectAll("text").attr("opacity", 1).transition(hide).attr("opacity", 0);
prec.selectAll("circle").transition(hide).attr("r", 0).remove(); prec.selectAll("circle").transition(hide).attr("r", 0).remove();
@ -257,7 +257,9 @@ function togglePrec(event) {
} }
} }
function drawPrec() { function drawPrecipitation() {
TIME && console.time("drawPrecipitation");
prec.selectAll("circle").remove(); prec.selectAll("circle").remove();
const {cells, points} = grid; const {cells, points} = grid;
@ -279,6 +281,8 @@ function drawPrec() {
.attr("r", 0) .attr("r", 0)
.transition(show) .transition(show)
.attr("r", d => getRadius(cells.prec[d])); .attr("r", d => getRadius(cells.prec[d]));
TIME && console.timeEnd("drawPrecipitation");
} }
function togglePopulation(event) { function togglePopulation(event) {
@ -1259,7 +1263,7 @@ function getLayer(id) {
if (id === "toggleBorders") return $("#borders"); if (id === "toggleBorders") return $("#borders");
if (id === "toggleRoutes") return $("#routes"); if (id === "toggleRoutes") return $("#routes");
if (id === "toggleTemperature") return $("#temperature"); if (id === "toggleTemperature") return $("#temperature");
if (id === "togglePrec") return $("#prec"); if (id === "togglePrecipitation") return $("#prec");
if (id === "togglePopulation") return $("#population"); if (id === "togglePopulation") return $("#population");
if (id === "toggleIce") return $("#ice"); if (id === "toggleIce") return $("#ice");
if (id === "toggleTexture") return $("#texture"); if (id === "toggleTexture") return $("#texture");

View file

@ -92,7 +92,7 @@ function editWorld() {
Biomes.define(); Biomes.define();
if (layerIsOn("toggleTemperature")) drawTemperature(); if (layerIsOn("toggleTemperature")) drawTemperature();
if (layerIsOn("togglePrec")) drawPrec(); if (layerIsOn("togglePrecipitation")) drawPrecipitation();
if (layerIsOn("toggleBiomes")) drawBiomes(); if (layerIsOn("toggleBiomes")) drawBiomes();
if (layerIsOn("toggleCoordinates")) drawCoordinates(); if (layerIsOn("toggleCoordinates")) drawCoordinates();
if (layerIsOn("toggleRivers")) drawRivers(); if (layerIsOn("toggleRivers")) drawRivers();

View file

@ -12,7 +12,7 @@
* *
* Example: 1.102.0 -> Major version 1, Minor version 102, Patch version 0 * Example: 1.102.0 -> Major version 1, Minor version 102, Patch version 0
*/ */
const VERSION = "1.103.00"; const VERSION = "1.104.00";
{ {
document.title += " v" + VERSION; document.title += " v" + VERSION;