From bdb6d75f83334053d8612d5b6a527f6ddd468822 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 10 Dec 2020 22:22:08 +0100 Subject: [PATCH] better sorting for the legend --- htdocs/map.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/map.js b/htdocs/map.js index 69be2ca..708e665 100644 --- a/htdocs/map.js +++ b/htdocs/map.js @@ -44,7 +44,12 @@ if (!colorKeys[id]) { var keys = Object.keys(colorKeys); keys.push(id); - keys.sort(); + keys.sort(function(a, b) { + var pa = parseFloat(a); + var pb = parseFloat(b); + if (isNaN(pa) || isNaN(pb)) return a.localeCompare(b); + return pa - pb; + }); var colors = colorScale.colors(keys.length); colorKeys = {}; keys.forEach(function(key, index) {