Skip to content

Commit b1a871b

Browse files
committed
feat: add more warming scenarios
1 parent acef42e commit b1a871b

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

assets/css/pf-maps.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
transition: background 0.3s ease, transform 0.2s;
3333
}
3434

35-
.change-scenario-button:hover {
35+
.change-scenario-button:hover, .selected-scenario {
3636
background-color: #cc1717;
3737
transform: scale(1.05);
3838
}
@@ -45,3 +45,11 @@
4545
#map-code-editor {
4646
margin-top: 10px;
4747
}
48+
49+
.pf-warming-scenario-button-wrapper {
50+
display: flex;
51+
justify-content: start;
52+
gap: 10px;
53+
margin-top: 10px;
54+
row-gap: 15px;
55+
}

assets/js/pf-maps.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ editor.session.setMode("ace/mode/javascript");
55
const editableCode = `
66
async function initializeMap() {
77
const htmlTemplate = await ProbableFuturesMapsHTMLGenerator.generateEmbedMap({
8-
datasetId: 40101,
8+
datasetId: 40104,
99
viewState: { zoom: 4 },
1010
scenario: 2,
1111
});
@@ -32,8 +32,25 @@ function saveAndRunCode() {
3232
document.getElementById("map-container").innerHTML = "";
3333

3434
try {
35+
const scenarioMatch = newCode.match(/scenario:\s*([\d.]+)/);
36+
let scenarioValue = scenarioMatch ? parseFloat(scenarioMatch[1]) : null;
37+
3538
eval(newCode);
3639
initializeMap();
40+
41+
document.querySelectorAll(".change-scenario-button").forEach(button => {
42+
button.classList.remove("selected-scenario");
43+
});
44+
45+
// Find and add "active" class to the button with the matching scenario value
46+
if (scenarioValue !== null) {
47+
const matchingButton = [...document.querySelectorAll(".change-scenario-button")]
48+
.find(button => button.textContent.includes(`${scenarioValue}°C`));
49+
50+
if (matchingButton) {
51+
matchingButton.classList.add("selected-scenario");
52+
}
53+
}
3754
} catch (error) {
3855
console.error("Error executing the new code:", error);
3956
}
@@ -46,7 +63,7 @@ window.onload = async function () {
4663
}
4764

4865
const htmlTemplate = await ProbableFuturesMapsHTMLGenerator.generateEmbedMap({
49-
datasetId: 40101,
66+
datasetId: 40104,
5067
viewState: { zoom: 4 },
5168
scenario: 2,
5269
});
@@ -65,8 +82,15 @@ window.onload = async function () {
6582
iframeDoc.close();
6683
};
6784

68-
function changeScenario(degree) {
85+
function changeScenario(event, degree) {
6986
const iframe = document.querySelector("#map-container iframe");
87+
88+
document.querySelectorAll(".change-scenario-button").forEach(button => {
89+
button.classList.remove("selected-scenario");
90+
});
91+
92+
event.target.classList.add("selected-scenario");
93+
7094
if (iframe) {
7195
iframe.contentWindow.postMessage(
7296
{ action: "onDegreeChanged", degree },

map-api.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,13 @@ Learn more about this package and find installation instruction in [the npm regi
5959
<button class="generate-maps-button" onclick="saveAndRunCode()">Save and Run Code</button>
6060

6161
<div id="map-container"></div>
62-
<button class="change-scenario-button" onclick="changeScenario(3)">Change Scenario to 3°C</button>
62+
63+
<div class="pf-warming-scenario-button-wrapper">
64+
<div>Warming scenarios:</div>
65+
<button class="change-scenario-button" onclick="changeScenario(event, 0.5)">0.5°C</button>
66+
<button class="change-scenario-button" onclick="changeScenario(event, 1)">1°C</button>
67+
<button class="change-scenario-button" onclick="changeScenario(event, 1.5)">1.5°C</button>
68+
<button class="change-scenario-button selected-scenario" onclick="changeScenario(event, 2)">2°C</button>
69+
<button class="change-scenario-button" onclick="changeScenario(event, 2.5)">2.5°C</button>
70+
<button class="change-scenario-button" onclick="changeScenario(event, 3)">3°C</button>
71+
</div>

0 commit comments

Comments
 (0)