Use brewer palettes for choropleth colors

cf https://gka.github.io/chroma.js/#chroma-brewer
This commit is contained in:
Yohan Boniface 2023-06-10 22:21:41 +02:00
parent 5d350a7cc9
commit bf116e8d93

View file

@ -136,9 +136,8 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({
this.datalayer.options.choropleth.mode || 'q', this.datalayer.options.choropleth.mode || 'q',
this.datalayer.options.choropleth.steps || 5 this.datalayer.options.choropleth.steps || 5
) )
const color = this.datalayer.getOption('color')
this.options.colors = chroma this.options.colors = chroma
.scale(['white', color]) .scale(this.datalayer.options.choropleth.brewer || 'Blues')
.colors(this.options.limits.length) .colors(this.options.limits.length)
}, },
@ -173,6 +172,12 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({
}, },
getEditableOptions: function () { 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 [ return [
[ [
'options.choropleth.property', 'options.choropleth.property',
@ -182,6 +187,14 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({
helpText: L._('Choropleth property value'), helpText: L._('Choropleth property value'),
}, },
], ],
[
'options.choropleth.brewer',
{
handler: 'Select',
label: L._('Choropleth color palette'),
selectOptions: brewerPalettes,
},
],
[ [
'options.choropleth.steps', 'options.choropleth.steps',
{ {