From c2ef8e83ec91e81dfc661f187aac8f2f32c6dc2d Mon Sep 17 00:00:00 2001 From: quaelnix <122357328+quaelnix@users.noreply.github.com> Date: Mon, 20 Feb 2023 12:08:39 +0100 Subject: [PATCH] Improve 'route quality cost' color coding (#693) This improves the color coding of the 'route quality cost' overlay by omitting 5% of the largest cost values when calculating min-max values. --- js/plugin/RoutingPathQuality.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/js/plugin/RoutingPathQuality.js b/js/plugin/RoutingPathQuality.js index cdea8d7..4557725 100644 --- a/js/plugin/RoutingPathQuality.js +++ b/js/plugin/RoutingPathQuality.js @@ -221,6 +221,7 @@ BR.RoutingPathQuality = L.Control.extend({ icon: 'fa-usd', provider: new HotLineQualityProvider({ hotlineOptions: { + pct: 0.95, // skip (1 - pct) percent of largest values when calculating maximum outlineColor: 'dimgray', renderer: renderer, }, @@ -392,7 +393,8 @@ var HotLineQualityProvider = L.Class.extend({ if (flatLines.length > 0) { var hotlineOptions = L.extend({}, this.hotlineOptions); if (!hotlineOptions.min && !hotlineOptions.max) { - var minMax = this._calcMinMaxValues(flatLines); + hotlineOptions.pct = hotlineOptions.pct ? hotlineOptions.pct : 1.0; + var minMax = this._calcMinMaxValues(flatLines, hotlineOptions.pct); hotlineOptions.min = minMax.min; hotlineOptions.max = minMax.max; } @@ -429,14 +431,10 @@ var HotLineQualityProvider = L.Class.extend({ return [latLng.lat, latLng.lng, val]; }, - _calcMinMaxValues: function (lines) { - var min = lines[0][2], - max = min; - for (var i = 1; lines && i < lines.length; i++) { - var line = lines[i]; - max = Math.max(max, line[2]); - min = Math.min(min, line[2]); - } + _calcMinMaxValues: function (lines, pct) { + lines.sort(function(a, b){return a[2] - b[2]}); + var min = lines[0][2]; + var max = lines[Math.ceil(pct * lines.length) - 1][2]; if (min === max) { max = min + 1; }