From e3aecd765b55df8bb3dbfe315b2997fb29c87a41 Mon Sep 17 00:00:00 2001 From: Jonathan Yong Date: Thu, 2 Nov 2023 16:30:31 +0000 Subject: [PATCH] Un-hardcode 'baseline', use config.referenceScenarioObject instead Closes #63 --- web/src/data/config.ts | 12 +++---- web/src/initialise.ts | 6 ++-- .../create/ModifyOutputAreas.svelte | 32 +++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/web/src/data/config.ts b/web/src/data/config.ts index ae23347..d32ca6a 100644 --- a/web/src/data/config.ts +++ b/web/src/data/config.ts @@ -38,7 +38,7 @@ import scenario7 from "src/data/scenarios/scenario7.json"; // One of the scenarios is used as the 'reference', against which values are // scaled. -const referenceScenarioFile = baseline; +const referenceScenarioObject = baseline; // Range to scale all indicator values between (for the baseline). const scale = { @@ -47,7 +47,7 @@ const scale = { } // List all the other scenarios here. -const otherScenarioFiles = [ +const otherScenarioObjects = [ scenario1, scenario1, scenario2, @@ -157,8 +157,8 @@ interface Config { initialLatitude: number; initialLongitude: number; initialZoom: number; - referenceScenarioFile: ScenarioObject; - otherScenarioFiles: ScenarioObject[]; + referenceScenarioObject: ScenarioObject; + otherScenarioObjects: ScenarioObject[]; signatures: { name: string, color: string }[]; allIndicators: Map; allInputs: Map; @@ -175,8 +175,8 @@ const config: Config = { initialZoom: initialZoom, geography: geography as GeoJSON.FeatureCollection, featureIdentifier: featureIdentifier, - referenceScenarioFile: referenceScenarioFile, - otherScenarioFiles: otherScenarioFiles, + referenceScenarioObject: referenceScenarioObject, + otherScenarioObjects: otherScenarioObjects, signatures: signatures, allIndicators: allIndicators, allInputs: allInputs, diff --git a/web/src/initialise.ts b/web/src/initialise.ts index 90e2f90..277f264 100644 --- a/web/src/initialise.ts +++ b/web/src/initialise.ts @@ -13,7 +13,7 @@ export function setupReferenceScenarioUnscaled(): Scenario { // `null` to avoid scaling. The ScaleFactorMap that we use for // everything else will be returned by this function. Likewise for the // validAreaNames parameter. - return fromScenarioObject(config.referenceScenarioFile, null, null, "reference scenario"); + return fromScenarioObject(config.referenceScenarioObject, null, null, "reference scenario"); } /* This function returns a set of all valid area names, as read from the @@ -51,8 +51,8 @@ export function setupScenarioMap( validAreaNames: Set, ): Map { const allScenarioObjects = [ - config.referenceScenarioFile, - ...config.otherScenarioFiles + config.referenceScenarioObject, + ...config.otherScenarioObjects ]; const scenarioList = allScenarioObjects.map((scenarioObject, i) => { return fromScenarioObject(scenarioObject, scaleFactors, validAreaNames, `scenario #${i}`); diff --git a/web/src/lib/leftSidebar/create/ModifyOutputAreas.svelte b/web/src/lib/leftSidebar/create/ModifyOutputAreas.svelte index 99ee41b..fadb823 100644 --- a/web/src/lib/leftSidebar/create/ModifyOutputAreas.svelte +++ b/web/src/lib/leftSidebar/create/ModifyOutputAreas.svelte @@ -31,9 +31,9 @@ $customScenarioInProgress = false; }); - function getBaselineSig(oaName: string): number { + function getReferenceSig(oaName: string): number { return $allScenarios - .get("baseline") + .get(config.referenceScenarioObject.metadata.name) .values.get(oaName) .get("signature_type"); } @@ -42,7 +42,7 @@ // editable layers function getSingleOAChanges( oaName: string - ): Map { + ): Map { const hasChanges = changes.has(oaName); const thisChanges = changes.get(oaName); return new Map([ @@ -53,7 +53,7 @@ ["job_types", hasChanges ? thisChanges.get("job_types") : null], ["use", hasChanges ? thisChanges.get("use") : null], ["greenspace", hasChanges ? thisChanges.get("greenspace") : null], - ["baseline_sig", getBaselineSig(oaName)], + ["reference_sig", getReferenceSig(oaName)], ]); } @@ -88,7 +88,7 @@ thisOAChanges.set(macroVar, macroVarValue); } }); - thisOAChanges.delete("baseline_sig"); + thisOAChanges.delete("reference_sig"); changes.set(oa.name, thisOAChanges as Map); }); } @@ -137,23 +137,23 @@ useModified = use !== null; green = oaChanges.get("greenspace"); greenModified = green !== null; - baselineSig = oaChanges.get("baseline_sig"); + referenceSig = oaChanges.get("reference_sig"); } else { // More than one OA selected const allSigs: Array = oas.map((oa) => getSingleOAChanges(oa.name).get("signature_type") ); - const allBaselineSigs: Array = oas.map((oa) => - getSingleOAChanges(oa.name).get("baseline_sig") + const allReferenceSigs: Array = oas.map((oa) => + getSingleOAChanges(oa.name).get("reference_sig") ); - // If none of the values were changed, check if the baseline values + // If none of the values were changed, check if the reference values // are all the same. If so, display that if (allSigs.every((s) => s === null)) { sigModified = false; - if (allBaselineSigs.every((s) => s === allBaselineSigs[0])) { - baselineSig = allBaselineSigs[0]; + if (allReferenceSigs.every((s) => s === allReferenceSigs[0])) { + referenceSig = allReferenceSigs[0]; } else { - baselineSig = null; + referenceSig = null; } } // If some of the values were changed, but not all, display an unchecked checkbox @@ -163,7 +163,7 @@ ) { sig = null; sigModified = false; - baselineSig = null; + referenceSig = null; } // If we reached here, then that means that all of the values were // changed to something else. @@ -216,7 +216,7 @@ // Variables for OA modifiers let sig: number | null = null; let sigModified: boolean; - let baselineSig: null | number; + let referenceSig: null | number; let job: number | null = null; let jobModified: boolean; let use: number | null = null; @@ -267,7 +267,7 @@ bind:checked={sigModified} on:change={() => { if (sigModified) { - sig = baselineSig; + sig = referenceSig; } if ($clickedOAs.length > 1 && !sigModified) { sig = null; @@ -288,7 +288,7 @@ {/each} {:else} - {#each [...config.signatures.entries()] as [signatureId, signature]}