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; modules.overviewRivers = true;
$("#riversOverview").dialog({ $("#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"} 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))); const averageDischarge = rn(d3.mean(pack.rivers.map(r => r.discharge)));
riversFooterDischarge.innerHTML = averageDischarge + " m³/s"; riversFooterDischarge.innerHTML = averageDischarge + " m³/s";
const averageLength = rn(d3.mean(pack.rivers.map(r => r.length))); 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); const averageWidth = rn(d3.mean(pack.rivers.map(r => r.width)), 3);
riversFooterWidth.innerHTML = rn(averageWidth * distanceScaleInput.value, 3) + " " + unit; riversFooterWidth.innerHTML = rn(averageWidth * distanceScaleInput.value, 3) + " " + unit;
@ -71,12 +73,18 @@ function overviewRivers() {
function riverHighlightOn(event) { function riverHighlightOn(event) {
if (!layerIsOn("toggleRivers")) toggleRivers(); if (!layerIsOn("toggleRivers")) toggleRivers();
const r = +event.target.dataset.id; 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) { function riverHighlightOff(e) {
const r = +e.target.dataset.id; 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() { function zoomToRiver() {
@ -96,7 +104,9 @@ function overviewRivers() {
basins.forEach((b, i) => { basins.forEach((b, i) => {
const color = colors[i % colors.length]; 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); rivers.select("#river" + r.i).attr("fill", color);
}); });
}); });
@ -108,7 +118,7 @@ function overviewRivers() {
body.querySelectorAll(":scope > div").forEach(function (el) { body.querySelectorAll(":scope > div").forEach(function (el) {
const d = el.dataset; 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 length = rn(d.length * distanceScaleInput.value) + " " + distanceUnitInput.value;
const width = rn(d.width * distanceScaleInput.value, 3) + " " + 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"; 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? alertMessage.innerHTML = `Are you sure you want to remove the river?
All tributaries will be auto-removed`; 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: { buttons: {
Remove: function () { Remove: function () {
Rivers.remove(river); Rivers.remove(river);
riversOverviewAddLines(); riversOverviewAddLines();
$(this).dialog("close"); $(this).dialog("close");
}, },
Cancel: function() {$(this).dialog("close");} Cancel: function () {
$(this).dialog("close");
}
} }
}); });
} }
function triggerAllRiversRemove() { function triggerAllRiversRemove() {
alertMessage.innerHTML = `Are you sure you want to remove all rivers?`; 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: { buttons: {
Remove: function () { Remove: function () {
$(this).dialog("close"); $(this).dialog("close");
removeAllRivers(); removeAllRivers();
}, },
Cancel: function() {$(this).dialog("close");} Cancel: function () {
$(this).dialog("close");
}
} }
}); });
} }
function removeAllRivers() { function removeAllRivers() {
pack.rivers = []; pack.rivers = [];
pack.cells.r = new Uint16Array(pack.cells.i.length);
rivers.selectAll("*").remove(); rivers.selectAll("*").remove();
riversOverviewAddLines(); riversOverviewAddLines();
} }
} }

View file

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