function Legend() {
var cutoff = 0;
while (fills_legend[cutoff + 1].d < 201) ++cutoff;
var fills1 = fills_legend.slice(cutoff);
var right_margin = 25;
var w = Math.min(width - right_margin, 500);
var h = 30;
var log_d = fills1.map(f => Math.log10(f.d));
log_d[0] = Math.log10(200);
var log_end = log_d[log_d.length - 1] + 0.1;
log_d.push(log_end);
var log_scale = (w) / (log_end - log_d[0]);
var x0 = log_d[0];
log_d = log_d.map(x => Math.round((x - x0) * log_scale) );
var patterns = fills1.map(x => x.p && x.p.with({scale: 1, id: x.p.id + "-l"}));
var patterndefs = patterns.map(p => p ? p.svg() : "").join("");
var boxes = fills1.map(
function (f, i)
{
var box_w = (log_d[i+1] - log_d[i]);
var f = patterns[i] ? patterns[i].url() : f.fill;
return`<rect x="${log_d[i]}" y="1" width="${box_w}" height="${h-1}" fill="${f}" />`;
}).join("");
var tick_d = [500, 1000, 3000, 10000, 30000, 1e5, 2e5];
var ticks = tick_d.map(
function (d, i)
{
var x = 0.5 + Math.floor((Math.log10(d) - x0) * log_scale);
var tx = x + 10 * (d == 2e5);
return `<line x1="${x}" y1="${h+3.5}" x2="${x}" y2="${h+8}" stroke="black" stroke-width="1"/>\n`+
`<text x="${tx}" y="${h+18}" style="font-family: sans-serif; font-size: 12px;" text-anchor="middle">${d}</text>`;
}).join("");
var tick_minor_d = [2000, 4000, 5000, 20e3, 40e3, 50e3];
ticks += tick_minor_d.map(
function (d, i)
{
var x = 0.5 + Math.floor((Math.log10(d) - x0) * log_scale);
var tx = x + 10 * (d == 2e5);
return `<line x1="${x}" y1="${h+3.5}" x2="${x}" y2="${h+5}" stroke="black" stroke-width="1"/>`;
}).join("");
var svg1 = svg`<svg viewbox="0 0 ${w+right_margin} ${h+20}" width="${w+right_margin}" height="${h+20}">
<defs>${patterndefs}</defs>
${boxes}
<rect x="0.5" y="0.5" width="${w}" height="${h}" fill="none" stroke="#aaa" stroke-width="1"/>
<line x1="0" y1="${h+3.5}" x2="${w+1}" y2="${h+3.5}" stroke="#888" stroke-width="1"/>
${ticks}
</svg>`;
return html`<div>People per km²<br>${svg1}</div>`
}