Skip to content

Commit 3887215

Browse files
fix: Ensure categorical values are derived on attribute change. (#348)
1 parent 30e4521 commit 3887215

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/lib/components/data/AttributeSelect.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
id="attribute-select"
7979
title="Attribute"
8080
on:change={onChange}
81+
class="w-[80%] truncate"
8182
/>
8283
<button
8384
bind:this={trigger}

src/lib/components/legends/QuantitativeChoroplethLegend.svelte

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import type { Feature } from 'geojson';
33
4-
import { deriveExtent, deriveThresholds } from '$lib/interaction/scales';
4+
import { deriveExtent } from '$lib/interaction/scales';
55
import type { ConstantStroke, QuantitativeFill } from '$lib/types';
66
77
export let fill: QuantitativeFill;
@@ -10,13 +10,6 @@
1010
1111
$: colors = fill.scheme[fill.count] as string[];
1212
$: [min, max] = deriveExtent(fill.attribute, features);
13-
$: stops = deriveThresholds({
14-
method: fill.method,
15-
attribute: fill.attribute,
16-
features: features,
17-
range: colors,
18-
thresholds: fill.thresholds
19-
});
2013
</script>
2114

2215
<div class="stack stack-xs ml-8 text-white">
@@ -42,7 +35,7 @@
4235
{/each}
4336
</ul>
4437
<ul class="stack stack-xs">
45-
{#each [min, ...stops, max] as stop}
38+
{#each [min, ...fill.thresholds, max] as stop}
4639
<li class="stack-h stack-h-xs h-4 font-mono text-3xs">
4740
<span class="text-slate-400"> → </span>
4841
<span>{stop.toFixed(2)}</span>

src/lib/interaction/update.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,27 @@ export function dispatchLayerUpdate({
278278
(map.getSource(layerId) as GeoJSONSource).setData(features);
279279
break;
280280
}
281-
case 'Choropleth':
281+
case 'Choropleth': {
282282
lyr.style.fill.attribute = payload.attribute;
283+
284+
if (lyr.style.fill.type === 'Quantitative') {
285+
lyr.style.fill.thresholds = deriveThresholds({
286+
method: lyr.style.fill.method,
287+
attribute: payload.attribute,
288+
features: lyr.data.geojson.features,
289+
range: lyr.style.fill.scheme[lyr.style.fill.count] as string[],
290+
thresholds: lyr.style.fill.thresholds
291+
});
292+
} else {
293+
lyr.style.fill.categories = enumerateAttributeCategories(
294+
lyr.data.geojson.features,
295+
payload.attribute
296+
);
297+
}
298+
283299
map.setPaintProperty(lyr.id, 'fill-color', deriveColorScale(lyr));
284300
break;
301+
}
285302
}
286303

287304
return ir;

0 commit comments

Comments
 (0)