From bf116e8d93d3e57815f2c9697ca59c31e283ee66 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 10 Jun 2023 22:21:41 +0200 Subject: [PATCH] Use brewer palettes for choropleth colors cf https://gka.github.io/chroma.js/#chroma-brewer --- umap/static/umap/js/umap.layer.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 418dccfd..24e005c2 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -136,9 +136,8 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({ this.datalayer.options.choropleth.mode || 'q', this.datalayer.options.choropleth.steps || 5 ) - const color = this.datalayer.getOption('color') this.options.colors = chroma - .scale(['white', color]) + .scale(this.datalayer.options.choropleth.brewer || 'Blues') .colors(this.options.limits.length) }, @@ -173,6 +172,12 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({ }, getEditableOptions: function () { + // chroma expose each palette both in title mode and in lowercase + // TODO: PR to chroma to get a accessor to the palettes names list + const brewerPalettes = Object.keys(chroma.brewer) + .filter((s) => s[0] == s[0].toUpperCase()) + .sort() + .map((k) => [k, k]) return [ [ 'options.choropleth.property', @@ -182,6 +187,14 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({ helpText: L._('Choropleth property value'), }, ], + [ + 'options.choropleth.brewer', + { + handler: 'Select', + label: L._('Choropleth color palette'), + selectOptions: brewerPalettes, + }, + ], [ 'options.choropleth.steps', {