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"}
}); });
@ -53,8 +55,8 @@ function overviewRivers() {
riversFooterNumber.innerHTML = pack.rivers.length; riversFooterNumber.innerHTML = pack.rivers.length;
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,17 +73,23 @@ 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() {
const r = +this.parentNode.dataset.id; const r = +this.parentNode.dataset.id;
const river = rivers.select("#river"+r).node(); const river = rivers.select("#river" + r).node();
highlightElement(river); highlightElement(river);
} }
@ -92,13 +100,15 @@ function overviewRivers() {
} else { } else {
rivers.attr("data-basin", "hightlighted"); rivers.attr("data-basin", "hightlighted");
const basins = [...new Set(pack.rivers.map(r => r.basin))]; const basins = [...new Set(pack.rivers.map(r => r.basin))];
const colors = ["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"]; const colors = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"];
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
rivers.select("#river"+r.i).attr("fill", color); .filter(r => r.basin === b)
}); .forEach(r => {
rivers.select("#river" + r.i).attr("fill", color);
});
}); });
} }
} }
@ -106,9 +116,9 @@ function overviewRivers() {
function downloadRiversData() { function downloadRiversData() {
let data = "Id,River,Type,Discharge,Length,Width,Basin\n"; // headers let data = "Id,River,Type,Discharge,Length,Width,Basin\n"; // headers
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";
@ -119,7 +129,7 @@ function overviewRivers() {
} }
function openRiverEditor() { function openRiverEditor() {
editRiver("river"+this.parentNode.dataset.id); editRiver("river" + this.parentNode.dataset.id);
} }
function triggerRiverRemove() { function triggerRiverRemove() {
@ -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];