Skip to content

Commit 0e3da55

Browse files
committed
add similar areas list to area indicators pages
1 parent a7ae24a commit 0e3da55

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

src/routes/(app)/app/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
analyticsEvent(eventData);
3838
});
3939
40-
console.log($page.data);
40+
// console.log($page.data);
4141
</script>
4242

4343
<svelte:head>

src/routes/(app)/app/areas/[code]/indicators/+page.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import {
55
Hero,
66
Grid,
7-
Section,
7+
Details,
88
NavSections,
99
NavSection,
10+
Dropdown
1011
} from "@onsvisual/svelte-components";
12+
import { formatName } from "@onsvisual/robo-utils";
1113
import BigNumber from "./BigNumber.svelte";
1214
import AreasModal from "$lib/components/modals/AreasModal.svelte";
1315
import OptionsModal from "$lib/components/modals/OptionsModal.svelte";
@@ -24,6 +26,7 @@
2426
data.periods[0],
2527
data.periods[data.periods.length - 1],
2628
],
29+
selectedCluster: data.related.similar[0],
2730
showConfidenceIntervals: false,
2831
});
2932
setContext("pageState", pageState);
@@ -78,9 +81,22 @@
7881
</NavSection>
7982
{/each}
8083
<NavSection title="Select an indicator" />
84+
{#if data.related.similar[0]}
85+
<NavSection title="Similar areas">
86+
<p>See which areas are similar to {formatName(data.area.properties.areanm, "the")} based on specific groups of indicators. These clusters of areas are based on an analysis carried out by the ONS.</p>
87+
<Dropdown label="Select a group of indicators" options={data.related.similar} bind:value={pageState.selectedCluster}/>
88+
<Details title="Show the 20 most similar areas to {formatName(data.area.properties.areanm, "the")}">
89+
<ol>
90+
{#each pageState.selectedCluster.similar as area}
91+
<li>{area.areanm}</li>
92+
{/each}
93+
</ol>
94+
</Details>
95+
</NavSection>
96+
{/if}
8197
<NavSection title="Get the data">
8298
<p>
83-
Download all datasets that include {data.area.properties.areanm} in a
99+
Download all datasets that include {formatName(data.area.properties.areanm, "the")} in a
84100
<a
85101
href={resolve(`/api/v1/data.csv?hasGeo=${data.area.properties.areacd}&time=all&excludeMultivariate=true`)}
86102
download="data.csv">CSV</a

src/routes/(app)/app/areas/[code]/indicators/+page.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,18 @@ export const load: PageLoad = async ({ params, parent, fetch }) => {
3030
a.areanm.localeCompare(b.areanm)
3131
);
3232
const related = await (await fetch(relatedPath)).json();
33-
const geoGroups = [
34-
{ id: "level", label: `All ${pluralise(geoLevel.label)}`, geoLevel: geoLevel.key },
35-
{
36-
id: "siblings",
37-
label: `All ${pluralise(geoLevel.label)} ${formatName(related.siblings.parent.areanm, "in")}`,
38-
geoLevel: geoLevel.key,
39-
geoExtent: related.siblings.parent.areacd,
40-
},
41-
{
42-
id: "cluster",
43-
label: `Similar demographics to ${formatName(area.properties.areanm, "the")}`,
44-
geoCluster: `demographic_${related.similar[2].cluster.key}`,
45-
},
46-
];
33+
const geoGroups = [{ id: "level", label: `All ${pluralise(geoLevel.label)}`, geoLevel: geoLevel.key }];
34+
if (geoLevel && related?.siblings?.parent) geoGroups.push({
35+
id: "siblings",
36+
label: `All ${pluralise(geoLevel.label)} ${formatName(related.siblings.parent.areanm, "in")}`,
37+
geoLevel: geoLevel.key,
38+
geoExtent: related.siblings.parent.areacd,
39+
});
40+
if (related.similar?.[2]?.cluster) geoGroups.push({
41+
id: "cluster",
42+
label: `Similar demographics to ${formatName(area.properties.areanm, "the")}`,
43+
geoCluster: `demographic_${related.similar[2].cluster.key}`,
44+
});
4745

4846
return {
4947
taxonomy: taxonomy.data,
@@ -54,7 +52,8 @@ export const load: PageLoad = async ({ params, parent, fetch }) => {
5452
geoGroups,
5553
periods: summaryData.years,
5654
};
57-
} catch {
55+
} catch(err) {
56+
console.log(err);
5857
error(404, { message: "Could not retrieve metadata" });
5958
}
6059
};

0 commit comments

Comments
 (0)