Skip to content

Commit

Permalink
Organize scheme-related components properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Oct 2, 2024
1 parent ad2c0d7 commit 58f0fea
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/lib/browse/LayerControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import Stats19LayerControl from "./layers/points/Stats19.svelte";
import VehicleCountsLayerControl from "./layers/points/VehicleCounts.svelte";
import ProblemsLayerControl from "./layers/points/Problems.svelte";
import SchemesLayer from "./SchemesLayer.svelte";
import SchemesLayer from "./schemes/SchemesLayer.svelte";
import { interactiveMapLayersEnabled, controls } from "./stores";
import { getRoadLayerNames } from "lib/maplibre";
import { get } from "svelte/store";
Expand Down
66 changes: 1 addition & 65 deletions src/lib/browse/colors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { constructMatchExpression } from "lib/maplibre";
import { type DataDrivenPropertyValueSpecification } from "maplibre-gl";
import { fundingProgrammesForColouringAndFiltering } from "./data";
import type { DataDrivenPropertyValueSpecification } from "maplibre-gl";

// These are specific to the browse page
export const colors = {
Expand Down Expand Up @@ -89,65 +87,3 @@ export const denseLineWidth: DataDrivenPropertyValueSpecification<number> = [
18,
20.0,
];

export function styleByFundingProgramme(): [
DataDrivenPropertyValueSpecification<string>,
[string, string][],
] {
let [colorMapping, legendRows] = getColorMappingAndLegend(
fundingProgrammesForColouringAndFiltering,
colors.funding_programmes,
);

let color = constructMatchExpression(
["get", "funding_programme"],
colorMapping,
"grey",
);
return [color, legendRows];
}

export function styleByCurrentMilestone(): [
DataDrivenPropertyValueSpecification<string>,
[string, string][],
] {
let stageGates = [
"removed",
"no data",
"not progressed",
"superseded",
"preliminary design completed",
"feasability design completed",
"detailed design completed",
"consruction started",
"construction completed",
];

let [colorMapping, legendRows] = getColorMappingAndLegend(
stageGates,
colors.current_milestone,
);

let color = constructMatchExpression(
["get", "current_milestone"],
colorMapping,
"grey",
);
return [color, legendRows];
}

function getColorMappingAndLegend(
keys: string[],
colorList: string[],
): [{ [key: string]: string }, [string, string][]] {
let legendRows: [string, string][] = [];
let colorMapping: { [key: string]: string } = {};
let i = 0;
for (let x of keys) {
let color = colorList[i++ % colorList.length];
colorMapping[x] = color;
legendRows.push([x, color]);
}

return [colorMapping, legendRows];
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
66 changes: 66 additions & 0 deletions src/lib/browse/schemes/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { constructMatchExpression } from "lib/maplibre";
import type { DataDrivenPropertyValueSpecification } from "maplibre-gl";
import { fundingProgrammesForColouringAndFiltering } from "./data";
import { colors } from "../colors";

export function styleByFundingProgramme(): [
DataDrivenPropertyValueSpecification<string>,
[string, string][],
] {
let [colorMapping, legendRows] = getColorMappingAndLegend(
fundingProgrammesForColouringAndFiltering,
colors.funding_programmes,
);

let color = constructMatchExpression(
["get", "funding_programme"],
colorMapping,
"grey",
);
return [color, legendRows];
}

export function styleByCurrentMilestone(): [
DataDrivenPropertyValueSpecification<string>,
[string, string][],
] {
let stageGates = [
"removed",
"no data",
"not progressed",
"superseded",
"preliminary design completed",
"feasability design completed",
"detailed design completed",
"consruction started",
"construction completed",
];

let [colorMapping, legendRows] = getColorMappingAndLegend(
stageGates,
colors.current_milestone,
);

let color = constructMatchExpression(
["get", "current_milestone"],
colorMapping,
"grey",
);
return [color, legendRows];
}

function getColorMappingAndLegend(
keys: string[],
colorList: string[],
): [{ [key: string]: string }, [string, string][]] {
let legendRows: [string, string][] = [];
let colorMapping: { [key: string]: string } = {};
let i = 0;
for (let x of keys) {
let color = colorList[i++ % colorList.length];
colorMapping[x] = color;
legendRows.push([x, color]);
}

return [colorMapping, legendRows];
}
File renamed without changes.
25 changes: 25 additions & 0 deletions src/lib/browse/schemes/stores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { writable, type Writable } from "svelte/store";
import type { Schemes, SchemeData } from "types";

// TODO Bundle this into one type, so it's easier to plumb around
export const atfSchemesGj: Writable<Schemes> = writable({
type: "FeatureCollection",
features: [],
schemes: {},
});
export const atfSchemes: Writable<Map<string, SchemeData>> = writable(
new Map(),
);
export const filterAtfInterventionText: Writable<string> = writable("");
export const filterAtfSchemeText: Writable<string> = writable("");

export const lcwipSchemesGj: Writable<Schemes> = writable({
type: "FeatureCollection",
features: [],
schemes: {},
});
export const lcwipSchemes: Writable<Map<string, SchemeData>> = writable(
new Map(),
);
export const filterLcwipInterventionText: Writable<string> = writable("");
export const filterLcwipSchemeText: Writable<string> = writable("");
24 changes: 0 additions & 24 deletions src/lib/browse/stores.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
import { writable, type Writable } from "svelte/store";
import type { Schemes, SchemeData } from "types";

// TODO Bundle this into one type, so it's easier to plumb around
export const atfSchemesGj: Writable<Schemes> = writable({
type: "FeatureCollection",
features: [],
schemes: {},
});
export const atfSchemes: Writable<Map<string, SchemeData>> = writable(
new Map(),
);
export const filterAtfInterventionText: Writable<string> = writable("");
export const filterAtfSchemeText: Writable<string> = writable("");

export const lcwipSchemesGj: Writable<Schemes> = writable({
type: "FeatureCollection",
features: [],
schemes: {},
});
export const lcwipSchemes: Writable<Map<string, SchemeData>> = writable(
new Map(),
);
export const filterLcwipInterventionText: Writable<string> = writable("");
export const filterLcwipSchemeText: Writable<string> = writable("");

export const interactiveMapLayersEnabled: Writable<boolean> = writable(true);
export let controls: Writable<HTMLDivElement | null> = writable(null);
3 changes: 2 additions & 1 deletion src/pages/BrowseSchemes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { initAll } from "govuk-frontend";
import LayerControls from "lib/browse/LayerControls.svelte";
import "../style/main.css";
import { atfSchemesGj, controls } from "lib/browse/stores";
import { controls } from "lib/browse/stores";
import { atfSchemesGj } from "lib/browse/schemes/stores";
import {
appVersion,
Geocoder,
Expand Down

0 comments on commit 58f0fea

Please sign in to comment.