From 09f835c21043852af28e48a68cc7e993c951210e Mon Sep 17 00:00:00 2001 From: Azgaar Date: Fri, 1 Mar 2024 11:46:07 +0100 Subject: [PATCH] fix: elevation profile color scheme --- modules/io/export.js | 2 +- modules/ui/elevation-profile.js | 41 +++++++++++++++++++++++++++++---- utils/graphUtils.js | 7 +++--- versioning.js | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/modules/io/export.js b/modules/io/export.js index 527705e5..27ecf202 100644 --- a/modules/io/export.js +++ b/modules/io/export.js @@ -364,7 +364,7 @@ function removeUnusedElements(clone) { function updateMeshCells(clone) { const data = renderOcean.checked ? grid.cells.i : grid.cells.i.filter(i => grid.cells.h[i] >= 20); - const scheme = getColorScheme(terrs.attr("scheme")); + const scheme = getColorScheme(terrs.select("#landHeights").attr("scheme")); clone.select("#heights").attr("filter", "url(#blur1)"); clone .select("#heights") diff --git a/modules/ui/elevation-profile.js b/modules/ui/elevation-profile.js index 20e381a6..7c180d37 100644 --- a/modules/ui/elevation-profile.js +++ b/modules/ui/elevation-profile.js @@ -193,8 +193,15 @@ function showElevationProfile(data, routeLen, isRiver) { .attr("d", "M0,0 V4 L2,2 Z") .attr("fill", "darkgray"); - let colors = getColorScheme(terrs.attr("scheme")); - const landdef = chart.select("defs").append("linearGradient").attr("id", "landdef").attr("x1", "0%").attr("y1", "0%").attr("x2", "0%").attr("y2", "100%"); + const colors = getColorScheme("natural"); + const landdef = chart + .select("defs") + .append("linearGradient") + .attr("id", "landdef") + .attr("x1", "0%") + .attr("y1", "0%") + .attr("x2", "0%") + .attr("y2", "100%"); if (chartData.mah == chartData.mih) { landdef @@ -247,7 +254,14 @@ function showElevationProfile(data, routeLen, isRiver) { path += " L" + parseInt(xscale(extra.length) + +xOffset) + "," + parseInt(yscale(0) + +yOffset); path += " L" + parseInt(xscale(0) + +xOffset) + "," + parseInt(yscale(0) + +yOffset); path += "Z"; - chart.append("g").attr("id", "epland").append("path").attr("d", path).attr("stroke", "purple").attr("stroke-width", "0").attr("fill", "url(#landdef)"); + chart + .append("g") + .attr("id", "epland") + .append("path") + .attr("d", path) + .attr("stroke", "purple") + .attr("stroke-width", "0") + .attr("fill", "url(#landdef)"); // biome / heights let g = chart.append("g").attr("id", "epbiomes"); @@ -289,7 +303,14 @@ function showElevationProfile(data, routeLen, isRiver) { chartData.cell[k] + ")"; - g.append("rect").attr("stroke", c).attr("fill", c).attr("x", x).attr("y", y).attr("width", xscale(1)).attr("height", 15).attr("data-tip", dataTip); + g.append("rect") + .attr("stroke", c) + .attr("fill", c) + .attr("x", x) + .attr("y", y) + .attr("width", xscale(1)) + .attr("height", 15) + .attr("data-tip", dataTip); } const xAxis = d3 @@ -371,7 +392,17 @@ function showElevationProfile(data, routeLen, isRiver) { // arrow from burg name to graph line g.append("path") .attr("id", "eparrow" + b) - .attr("d", "M" + x1.toString() + "," + (y1 + 3).toString() + "L" + x1.toString() + "," + parseInt(chartData.points[k][1] - 3).toString()) + .attr( + "d", + "M" + + x1.toString() + + "," + + (y1 + 3).toString() + + "L" + + x1.toString() + + "," + + parseInt(chartData.points[k][1] - 3).toString() + ) .attr("stroke", "darkgray") .attr("fill", "lightgray") .attr("stroke-width", "1") diff --git a/utils/graphUtils.js b/utils/graphUtils.js index 99d3b52b..ec6fb59a 100644 --- a/utils/graphUtils.js +++ b/utils/graphUtils.js @@ -327,9 +327,10 @@ function drawCellsValue(data) { // helper function non-used for the main generation function drawPolygons(data) { - const max = d3.max(data), - min = d3.min(data), - scheme = getColorScheme(terrs.select("#landHeights").attr("scheme")); + const max = d3.max(data); + const min = d3.min(data); + const scheme = getColorScheme(terrs.select("#landHeights").attr("scheme")); + data = data.map(d => 1 - normalize(d, min, max)); debug.selectAll("polygon").remove(); diff --git a/versioning.js b/versioning.js index e2cd1b6e..bdaaca35 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.96.01"; // generator version, update each time +const version = "1.96.02"; // generator version, update each time { document.title += " v" + version;