Skip to content

Commit 5bf81b5

Browse files
committed
Adapting position chart to plot multiple areas
1 parent 4ab571d commit 5bf81b5

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
promoteProperty = "LSOA21CD",
117117
clickedArea = $bindable([]),
118118
areaToColorLookup,
119+
hoveredArea = $bindable(),
119120
}: {
120121
data?: object[];
121122
countries?: string[];
@@ -196,6 +197,7 @@
196197
promoteProperty?: string;
197198
clickedArea?: [];
198199
areaToColorLookup?: object;
200+
hoveredArea?: string;
199201
} = $props();
200202
201203
// ISO-3166/ONS-style prefixes for area codes
@@ -406,13 +408,10 @@
406408
geoSource === "file" ? joinData(filteredGeoJsonData, dataWithColor) : null,
407409
);
408410
409-
let hoveredArea = $state();
410411
let hoveredAreaArray = $derived(hoveredArea ? [hoveredArea] : []);
411412
let hoveredAreaData = $state();
412413
let currentMousePosition = $state();
413414
414-
$inspect(clickedArea, hoveredAreaArray);
415-
416415
function convertToLngLatBounds(coords: LngLatBoundsLike): LngLatBoundsLike {
417416
const bounds = new LngLatBounds(coords[0], coords[0]);
418417
@@ -489,7 +488,7 @@
489488
map?.setMaxBounds(undefined);
490489
}
491490
});
492-
$inspect(clickedArea);
491+
493492
let paintObject = $derived(
494493
clickedArea?.length > 0
495494
? {

src/lib/components/data-vis/position-chart/PositionChart.svelte

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
1616
const range = Array.from({ length: 10 }, (_, i) => i);
1717
18+
$inspect(value, "what is it");
19+
1820
// the 'chart' is the bar and the marker - its height is a prop and its width is binded to clientWidth
1921
2022
// the 'marker' is the circle
@@ -67,12 +69,26 @@
6769
fill={colorScale[number]}
6870
></rect></g
6971
>{/each}
70-
<g
71-
transform="translate({xFunction(value) + markerRadius},{chartHeight /
72-
2})"
73-
><circle r={markerRadius} cx="0" cy="0" fill="#CA357C" stroke="white"
74-
></circle></g
75-
>
72+
{console.log(value, typeof value)}
73+
{#if typeof value === "number"}
74+
<g
75+
transform="translate({xFunction(value) + markerRadius},{chartHeight /
76+
2})"
77+
>
78+
<circle r={markerRadius} cx="0" cy="0" fill="#CA357C" stroke="white"
79+
></circle></g
80+
>
81+
{:else}
82+
{#each value as rowValue, i}
83+
<g
84+
transform="translate({xFunction(rowValue) +
85+
markerRadius},{chartHeight / 2})"
86+
>
87+
<circle r={markerRadius} cx="0" cy="0" fill="#CA357C" stroke="white"
88+
></circle>
89+
</g>
90+
{/each}
91+
{/if}
7692
</svg>
7793
</div>
7894

0 commit comments

Comments
 (0)