remove all rivers - fix

This commit is contained in:
Azgaar 2021-07-20 01:37:13 +03:00
parent 76c787b6e9
commit ae62755a76
2 changed files with 40 additions and 20 deletions

View file

@ -12,7 +12,9 @@ function overviewRivers() {
modules.overviewRivers = true;
$("#riversOverview").dialog({
title: "Rivers Overview", resizable: false, width: fitContent(),
title: "Rivers Overview",
resizable: false,
width: fitContent(),
position: {my: "right top", at: "right-10 top+10", of: "svg", collision: "fit"}
});
@ -54,7 +56,7 @@ function overviewRivers() {
const averageDischarge = rn(d3.mean(pack.rivers.map(r => r.discharge)));
riversFooterDischarge.innerHTML = averageDischarge + " m³/s";
const averageLength = rn(d3.mean(pack.rivers.map(r => r.length)));
riversFooterLength.innerHTML = (averageLength * distanceScaleInput.value) + " " + unit;
riversFooterLength.innerHTML = averageLength * distanceScaleInput.value + " " + unit;
const averageWidth = rn(d3.mean(pack.rivers.map(r => r.width)), 3);
riversFooterWidth.innerHTML = rn(averageWidth * distanceScaleInput.value, 3) + " " + unit;
@ -71,12 +73,18 @@ function overviewRivers() {
function riverHighlightOn(event) {
if (!layerIsOn("toggleRivers")) toggleRivers();
const r = +event.target.dataset.id;
rivers.select("#river"+r).attr("stroke", "red").attr("stroke-width", 1);
rivers
.select("#river" + r)
.attr("stroke", "red")
.attr("stroke-width", 1);
}
function riverHighlightOff(e) {
const r = +e.target.dataset.id;
rivers.select("#river"+r).attr("stroke", null).attr("stroke-width", null);
rivers
.select("#river" + r)
.attr("stroke", null)
.attr("stroke-width", null);
}
function zoomToRiver() {
@ -96,7 +104,9 @@ function overviewRivers() {
basins.forEach((b, i) => {
const color = colors[i % colors.length];
pack.rivers.filter(r => r.basin === b).forEach(r => {
pack.rivers
.filter(r => r.basin === b)
.forEach(r => {
rivers.select("#river" + r.i).attr("fill", color);
});
});
@ -108,7 +118,7 @@ function overviewRivers() {
body.querySelectorAll(":scope > div").forEach(function (el) {
const d = el.dataset;
const discharge = d.discharge + " m³/s"
const discharge = d.discharge + " m³/s";
const length = rn(d.length * distanceScaleInput.value) + " " + distanceUnitInput.value;
const width = rn(d.width * distanceScaleInput.value, 3) + " " + distanceUnitInput.value;
data += [d.id, d.name, d.type, discharge, length, width, d.basin].join(",") + "\n";
@ -127,35 +137,44 @@ function overviewRivers() {
alertMessage.innerHTML = `Are you sure you want to remove the river?
All tributaries will be auto-removed`;
$("#alert").dialog({resizable: false, width: "22em", title: "Remove river",
$("#alert").dialog({
resizable: false,
width: "22em",
title: "Remove river",
buttons: {
Remove: function () {
Rivers.remove(river);
riversOverviewAddLines();
$(this).dialog("close");
},
Cancel: function() {$(this).dialog("close");}
Cancel: function () {
$(this).dialog("close");
}
}
});
}
function triggerAllRiversRemove() {
alertMessage.innerHTML = `Are you sure you want to remove all rivers?`;
$("#alert").dialog({resizable: false, title: "Remove all rivers",
$("#alert").dialog({
resizable: false,
title: "Remove all rivers",
buttons: {
Remove: function () {
$(this).dialog("close");
removeAllRivers();
},
Cancel: function() {$(this).dialog("close");}
Cancel: function () {
$(this).dialog("close");
}
}
});
}
function removeAllRivers() {
pack.rivers = [];
pack.cells.r = new Uint16Array(pack.cells.i.length);
rivers.selectAll("*").remove();
riversOverviewAddLines();
}
}

View file

@ -603,6 +603,7 @@ function addRiverOnClick() {
oldRiverCells.forEach(cell => {
if (h[cell] > h[min]) {
cells.r[cell] = 0;
cells.fl[cell] = grid.cells.prec[cells.g[cell]];
} else {
riverCells.push(cell);
cells.fl[cell] += cells.fl[i];