Skip to content

Commit 40034ce

Browse files
committed
added custom breaks and descriptions
1 parent b9972af commit 40034ce

File tree

3 files changed

+76
-38
lines changed

3 files changed

+76
-38
lines changed

src/lib/components/data-vis/map/Map.svelte

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
let {
3636
data,
3737
customPallet,
38+
setCustomPallet,
3839
cooperativeGestures = true,
3940
standardControls = true,
4041
navigationControl,
@@ -56,6 +57,7 @@
5657
year,
5758
metric,
5859
breaksType = "quantile",
60+
customBreaks,
5961
numberOfBreaks = 5,
6062
fillOpacity = 0.5,
6163
changeOpacityOnHover = true,
@@ -66,6 +68,7 @@
6668
maxZoom,
6769
maxBounds,
6870
hash = false,
71+
interactive,
6972
updateHash = (u) => {
7073
replaceState(u, page.state);
7174
},
@@ -110,8 +113,10 @@
110113
updateHash?: (URL) => void;
111114
useInitialHash?: boolean;
112115
mapHeight?: number;
116+
setCustomPallet?: boolean;
117+
customBreaks?: number[];
118+
interative?: boolean;
113119
} = $props();
114-
$inspect(maxBounds);
115120
let styleLookup = {
116121
"Carto-light":
117122
"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",
@@ -137,7 +142,7 @@
137142
let filteredGeoJsonData = $derived(filterGeo(geojsonData, year));
138143
139144
let fillColors: string[] = $derived(
140-
customPallet !== undefined
145+
setCustomPallet == true
141146
? customPallet
142147
: colorbrewer[colorPalette][numberOfBreaks],
143148
);
@@ -200,7 +205,9 @@
200205
let breaks = $derived(
201206
breaksType == "jenks"
202207
? jenksBreaks(vals, numberOfBreaks)
203-
: quantileBreaks(vals, numberOfBreaks),
208+
: breaksType == "quantile"
209+
? quantileBreaks(vals, numberOfBreaks)
210+
: customBreaks,
204211
);
205212
206213
let dataWithColor = $derived(
@@ -233,6 +240,7 @@
233240
if (setMaxBounds) {
234241
let boundary = convertToLngLatBounds(maxBounds);
235242
}
243+
236244
function zoomToArea(e) {
237245
if (clickToZoom) {
238246
let coordArray =
@@ -279,44 +287,46 @@
279287
bind:map
280288
bind:loaded
281289
{style}
282-
{standardControls}
283290
{center}
291+
{interactive}
284292
{zoom}
285293
{maxZoom}
286294
{minZoom}
287295
{...setMaxBounds ? { maxBounds: boundary } : {}}
296+
{standardControls}
288297
{hash}
289298
{updateHash}
290299
class="map"
291300
>
292-
{#if !standardControls}
293-
<NonStandardControls
294-
{navigationControl}
295-
{navigationControlPosition}
296-
{geolocateControl}
297-
{geolocateControlPosition}
298-
{fullscreenControl}
299-
{fullscreenControlPosition}
300-
{scaleControl}
301-
{scaleControlPosition}
302-
{scaleControlUnit}
303-
/>
301+
{#if interactive}
302+
{#if !standardControls}
303+
<NonStandardControls
304+
{navigationControl}
305+
{navigationControlPosition}
306+
{geolocateControl}
307+
{geolocateControlPosition}
308+
{fullscreenControl}
309+
{fullscreenControlPosition}
310+
{scaleControl}
311+
{scaleControlPosition}
312+
{scaleControlUnit}
313+
/>
314+
<Control>
315+
<ControlGroup>
316+
<button
317+
class="reset-button"
318+
onclick={() => {
319+
map.flyTo({
320+
center: center,
321+
zoom: zoom,
322+
});
323+
}}>Reset view</button
324+
></ControlGroup
325+
>
326+
</Control>
327+
{/if}
304328
{/if}
305329

306-
<Control>
307-
<ControlGroup>
308-
<button
309-
class="reset-button"
310-
onclick={() => {
311-
map.flyTo({
312-
center: center,
313-
zoom: zoom,
314-
});
315-
}}>Reset view</button
316-
></ControlGroup
317-
>
318-
</Control>
319-
320330
<GeoJSON id="areas" data={merged} promoteId="areanm">
321331
<FillLayer
322332
paint={{

src/lib/components/data-vis/map/mapUtils.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ export function quantileBreaks(data: number[], numBreaks: number): number[] {
106106
let len = data.length;
107107

108108
let breaks: number[] = [
109-
// data[0]
110-
// data[Math.floor(len * 0.2)],
111-
// data[Math.floor(len * 0.4)],
112-
// data[Math.floor(len * 0.6)],
113-
// data[Math.floor(len * 0.8)],
114-
// data[len - 1],
115109
];
116110
for (let i = 0; i < numBreaks; i++) {
117111
breaks.push(data[Math.floor(len * (i * (1 / numBreaks)))]);
@@ -120,3 +114,5 @@ export function quantileBreaks(data: number[], numBreaks: number): number[] {
120114

121115
return breaks;
122116
}
117+
118+

src/wrappers/components/data-vis/map/MapWrapper.svelte

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@
155155
*/
156156
let parametersSourceArray = $derived(
157157
addIndexAndInitalValue([
158+
{
159+
name: "Interactive",
160+
category: "UI",
161+
value: false,
162+
description: "Turn on/off the interactvity funtion for the maps",
163+
},
158164
{
159165
name: "cooperativeGestures",
160166
isProp: true,
@@ -287,6 +293,7 @@
287293
category: "Styling",
288294
isProp: true,
289295
value: 400,
296+
description: "Set height of map",
290297
},
291298
{
292299
name: "styleSheet",
@@ -351,11 +358,21 @@
351358
value: "YlGnBu",
352359
category: "Styling",
353360
},
361+
{
362+
name: "setCustomPallet",
363+
isProp: true,
364+
category: "Styling",
365+
value: false,
366+
description: " Set wheather a custom palllet will be used",
367+
},
354368
{
355369
name: "customPallet",
356370
isProp: true,
357371
category: "Styling",
358372
value: [[]],
373+
visable: { name: "setCustomPallet", value: true },
374+
description:
375+
"Pass in an array of colours you want to be used in a custom pallet. Write in a hex format",
359376
},
360377
{
361378
name: "showBorder",
@@ -436,9 +453,17 @@
436453
name: "breaksType",
437454
isProp: true,
438455
category: "Data",
439-
options: ["quantile", "jenks"],
456+
options: ["quantile", "jenks", "custom"],
440457
description: "The method for splitting your data into groups",
441458
},
459+
{
460+
name: "customBreaks",
461+
isProp: true,
462+
value: [20, 40, 60, 80, 100],
463+
category: "Data",
464+
description:
465+
"Split the data into you own groups. Breaks must equal or be less the numberOfBreaks",
466+
},
442467
{
443468
name: "numberOfBreaks",
444469
isProp: true,
@@ -509,7 +534,14 @@
509534
description: "The initial centre of the map, in [lng, lat] form",
510535
},
511536
512-
{ name: "setMaxBounds", isProp: true, value: false, category: "View" },
537+
{
538+
name: "setMaxBounds",
539+
isProp: true,
540+
value: false,
541+
category: "View",
542+
description:
543+
"Binds the viewpory to a the area between an NW point and SE point. Write max bounds as [[number,number], [number number]]",
544+
},
513545
514546
{
515547
name: "maxBounds",

0 commit comments

Comments
 (0)