From 418d3642596b6d79881d6e85d9f2f832e925fde0 Mon Sep 17 00:00:00 2001 From: Evolvedexperiment Date: Sun, 10 May 2020 19:35:15 +0000 Subject: [PATCH] Added colour and biomes to elevation profile --- modules/ui/elevation-profile.js | 67 ++++++++++++++++++++++++++------- modules/ui/rivers-editor.js | 4 +- modules/ui/routes-editor.js | 4 +- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/modules/ui/elevation-profile.js b/modules/ui/elevation-profile.js index 073bf25a..daa9080e 100644 --- a/modules/ui/elevation-profile.js +++ b/modules/ui/elevation-profile.js @@ -1,4 +1,5 @@ "use strict"; + function showEPForRoute(node) { const points = []; debug.select("#controlPoints").selectAll("circle").each(function() { @@ -21,7 +22,8 @@ function showEPForRiver(node) { showElevationProfile(points, riverLen, true); } -function resizeElevationProfile() { +function closeElevationProfile() { + modules.elevation = false; } function showElevationProfile(data, routeLen, isRiver) { @@ -30,6 +32,7 @@ function showElevationProfile(data, routeLen, isRiver) { $("#elevationProfile").dialog({ title: "Elevation profile", resizable: false, width: window.width, + close: closeElevationProfile, position: {my: "left top", at: "left+20 bottom-240", of: window, collision: "fit"} }); @@ -43,14 +46,17 @@ function showElevationProfile(data, routeLen, isRiver) { } } + // points is a chart (x going right, y going up) as opposed to the screen (x going right, y going down) const points = []; - var prevB=0, prevH=-1, i=0, j=0, cell=0, b=0, ma=0, mi=100, h=0; + var prevB=0, prevH=-1, i=0, j=0, cell=0, b=0, biome, ma=0, mi=100, h=0; for (var i=0; i d.x * w / points.length + xOffset).y(d => h-d.y + yOffset); - chart.append("path").attr("d", lineFunc(points)).attr("stroke", "purple").attr("fill", "none").attr("id", "elevationLine"); + const skyGradient = d3.scaleSequential(d3.interpolateBlues); + const skydef = chart.select("defs").append("linearGradient").attr("id", "skydef").attr("x1", "0%").attr("y1", "0%").attr("x2", "0%").attr("y2", "100%"); + skydef.append("stop").attr("offset", "0%").attr("style", "stop-color:"+skyGradient(0.90)+";stop-opacity:1"); + skydef.append("stop").attr("offset", "100%").attr("style", "stop-color:"+skyGradient(0.25)+";stop-opacity:1"); + const sky = chart.append("g").append("rect").attr("y", yOffset).attr("x", xOffset).attr("width", w).attr("height", h).attr("fill", "url(#skydef)"); + + // biome colors + for (var k=0; k= 0; i -= increment, c += increment) { const p1 = node.getPointAtLength(i / 1e5); @@ -183,7 +183,7 @@ function editRiver(id) { function showElevationProfile() { modules.elevation = true; - showEPForRiver(node); + showEPForRiver(elSelected.node()); } function showRiverWidth() { diff --git a/modules/ui/routes-editor.js b/modules/ui/routes-editor.js index 98974f29..b34732e2 100644 --- a/modules/ui/routes-editor.js +++ b/modules/ui/routes-editor.js @@ -47,7 +47,7 @@ function editRoute(onClick) { function drawControlPoints(node) { const l = node.getTotalLength(); - const increment = l / Math.ceil(l / 8); + const increment = l / Math.ceil(l / 4); for (let i=0; i <= l; i += increment) {addControlPoint(node.getPointAtLength(i));} routeLength.innerHTML = rn(l * distanceScaleInput.value) + " " + distanceUnitInput.value; } @@ -110,7 +110,7 @@ function editRoute(onClick) { function showElevationProfile() { modules.elevation = true; - showEPForRoute(node); + showEPForRoute(elSelected.node()); } function showGroupSection() {