Skip to content

Commit

Permalink
added mexico to map, attemped path drawings, and have rough line grap…
Browse files Browse the repository at this point in the history
…h animation
  • Loading branch information
zoexelbert committed Feb 3, 2025
1 parent 151b8be commit 536a0b1
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 1,385 deletions.
1 change: 1 addition & 0 deletions eg_geojsons/EG_Spring_Avgs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"march_avg":{"2004":null,"2005":161.0,"2006":null,"2007":1.0,"2008":null,"2009":1.0,"2010":null,"2011":4.0,"2012":4.0,"2013":1.75,"2014":1.25,"2015":null,"2016":3.3666666667,"2017":6.3571428571,"2018":4.8666666667,"2019":7.1764705882,"2020":4.7777777778,"2021":2.8,"2022":2.3333333333,"2023":null},"april_avg":{"2004":null,"2005":1871.5,"2006":304.0,"2007":13.6666666667,"2008":56.5,"2009":5.5,"2010":59.25,"2011":83.2083333333,"2012":1138.0,"2013":296.4,"2014":26.625,"2015":622.3333333333,"2016":13.1264880952,"2017":39.8333333333,"2018":39.9595238095,"2019":19.8005952381,"2020":32.0045787546,"2021":25.8654040404,"2022":16.806272509,"2023":null},"may_avg":{"2004":null,"2005":null,"2006":738.0,"2007":21.875,"2008":3.0,"2009":3.75,"2010":11.6666666667,"2011":22.95,"2012":108.2,"2013":212.25,"2014":24.5,"2015":218.8041666667,"2016":2.25,"2017":7.0773809524,"2018":3.7,"2019":2.95,"2020":3.25,"2021":18.1291666667,"2022":28.2743006993,"2023":null}}
111 changes: 68 additions & 43 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://d3js.org/topojson.v3.min.js"></script>
<script src="https://d3js.org/d3.v7.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="https://unpkg.com/d3-simple-slider"></script>
<script src="src/eg_linegraph.js"></script>
<!-- <link rel="stylesheet" href="/node_modules/reveal.js/dist/reveal.css"> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GSLBirdVis</title>
Expand Down Expand Up @@ -102,25 +106,22 @@
<div class = "opening_storyline"
style=
"opacity: 0;
width: 60%;
background-color: white;
padding: 10px;
transition: transform 1s ease, opacity 1s ease;
margin-top: 10px;
margin-left: 200px;
display: flex;
position: relative;
align-items: center;">
display: flex;
flex-direction: column;
position: relative;
align-items: center;
justify-content: center;
margin-top: 8px;">
<div class="main-text"
style=
"font-family: 'Times New Roman', serif;
color: black;
font-size: 1.2vw;
white-space: normal;
margin-top: 8px;
margin-left: 100px;
line-height: 1.7;
flex-grow: 1;">
width: 700px;
line-height: 1.7;">
<p> <span style="font-size: 2.6vw; line-height: 1;"> T</span>he Great Salt Lake is a prominent stopping point for over 10 million birds year-round. Situated
on the Pacific Flyway Route, the Great Salt Lake is a top attraction to over 338 species who utilize the lake's resources for breeding, feeding, and temporary
habitats during seasonal migration periods. </p>
Expand All @@ -131,7 +132,7 @@
to worsen, both of these species are in danger. </p>
<p>Here we will investigate the climate effects these birds are vulnerable to as we fly along with them over the years, answering the question, is flying to the Great Salt lake still the flight of least resistance?</p>
</div>
<div style="position: fixed; top: 0; display: flex; align-items: flex-start; margin-top: 390px; margin-left: 200px;">
<div style="justify-content: center;">
<button class="button-55" id="grebe-button" role="button">
FLY AS A GREBE
</button>
Expand All @@ -141,35 +142,61 @@
</div>
</div>

<div class="row" style="margin-top: 10px; margin-left: 70px;">
<!-- Left Column (Text Content) -->
<div class="column" style="margin-top: 70px;">
<div class="grebe-content" style="opacity: 0; transition: transform 1s ease, opacity 1.5s ease;">
<p class = "text-style">
<span style="font-size: 2.6vw; line-height: 1; font-family: 'Times New Roman', serif;color: black;">T</span>he Eared Grebe, the most abundant grebe species in the world,
begins their flight South from the Pacific Northwest towards the Great Salt Lake around September. During the Fall, Grebes come to stock up on food before heading to
Mexico for the winter. In the Spring, the Grebes will come back to breed and nest at the GSL, but the success of this is highly dependent on the Fall and Spring climate
of the Great Salt Lake, as well as the winter climate along the Mexican shorelines.
</p>
<button class="button-55" id="grebe-button" role="button" style="padding: 10px 20px; margin-left: 130px;">
VISUALIZE MIGRATION
</button>
<p class="text-style">
** Put more about migration and EG information **
</p>
<p class="text-style">

</p>
</div>
<div class = "EG_opening"
style=
"display: flex;
flex-direction: row;
position: relative;
margin-top: 8px;
width: 100%;
overflow: hidden;
justify-content: center;">">
<div class="grebe-content"
style=
"opacity: 0;
transition: transform 1s ease,
opacity 1.5s ease;
overflow-wrap: break-word;
word-wrap: break-word;
margin-top: 8vh;
font-family: 'Times New Roman', serif;
color: black;
font-size: 1.2vw;
width: 40%">
<p class = "text-style">
<span style="font-size: 2.6vw; line-height: 1; font-family: 'Times New Roman', serif;color: black;">T</span>he Eared Grebe, the most abundant grebe species in the world,
begins their flight South from the Pacific Northwest towards the Great Salt Lake around September. </p>
<p class="text-style">
During this time in the Fall, Grebes come to stock up on food before heading to Mexico for the winter. Then, in the Spring, the Grebes will come back to breed and nest at the
GSL.
</p>
<button class="button-55" id="grebe-button" role="button" style="justify-content: center; margin-left: 5vw;">
VISUALIZE MIGRATION
</button>
<!-- <p>
but the success of this is highly dependent on the Fall and Spring climate of the Great Salt Lake, as well as the winter climate along the Mexican shorelines.
</p> -->
</div>
<!-- Right Column (Map Content) -->
<div class="column" style="margin-top: 50px;">
<div class="grebe-map" id="grebe-map">
<svg id="grebe-map-svg" style="width: 2000px; height: 2000px;"></svg>
</div>
<div class="grebe-map" id="grebe-map">
<svg id="grebe-map-svg"
style=
"width: 870px;
height: 870px;
margin-top: 5vh;">
</svg>
</div>
</div>

<div class="EG_linegraph">
<svg id="grebe_linegraph"
style=
"width:700px;
height: 700px;" >
</svg>

</div>



<div class="pelican-content"
style="visibility: hidden;
Expand Down Expand Up @@ -205,22 +232,20 @@
line-height: 1.7;
font-family: 'Times New Roman',
serif;color: black;
align-items: center;"
}

.column {
/* .column {
float: left;
width: 50%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}
} */

/* Clear floats after the columns */
.row:after {
/* .row:after {
content: "";
display: table;
clear: both;
}
} */

.opening.hidden {
opacity: 0;
Expand Down
110 changes: 110 additions & 0 deletions src/eg_linegraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
function createEGLinegraph() {
// Select the correct SVG element and set width/height
const svgWidth = 700, svgHeight = 700;
const margin = { top: 50, right: 80, bottom: 50, left: 50 };
const width = svgWidth - margin.left - margin.right;
const height = svgHeight - margin.top - margin.bottom;

const svg = d3.select("#grebe_linegraph")
.attr("width", svgWidth)
.attr("height", svgHeight)
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);

// Load JSON data
d3.json("birds/eg_geojsons/EG_Spring_Avgs.json")
.then(data => {
console.log("Loaded JSON Data:", data);

const years = Object.keys(data.march_avg).filter(y => y !== "null"); // Extract available years
let currentYearIndex = 0; // Start from the first year

// Set up scales
const xScale = d3.scaleBand()
.domain(["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"])
.range([0, width])
.padding(0.1);

const yScale = d3.scaleLinear().range([height, 0]);

// Define the line generator
const line = d3.line()
.x(d => xScale(d.month) + xScale.bandwidth() / 2)
.y(d => d.value !== null ? yScale(d.value) : null)
.defined(d => d.value !== null); // Ignore null values

// Add X Axis
svg.append("g")
.attr("class", "x-axis")
.attr("transform", `translate(0, ${height})`)
.call(d3.axisBottom(xScale))
.selectAll("text")
.attr("transform", "rotate(-45)")
.style("text-anchor", "end");

// Add Y Axis
const yAxis = svg.append("g").attr("class", "y-axis");

// Add line path
const path = svg.append("path")
.attr("fill", "none")
.attr("stroke", "blue")
.attr("stroke-width", 2);

// 🔹 **Fix: Move the Year Label outside the transformed group**
const yearText = d3.select("#grebe_linegraph")
.append("text")
.attr("id", "year-label")
.attr("x", svgWidth - 100) // Adjusted for better visibility
.attr("y", 100) // Position near the top
.attr("text-anchor", "middle")
.style("font-size", "24px")
.style("font-weight", "bold")
.style("fill", "black");

// Function to update graph for a specific year
function updateGraph(year) {
const dataset = [
{ month: "January", value: null },
{ month: "February", value: null },
{ month: "March", value: data.march_avg[year] || 0 },
{ month: "April", value: data.april_avg[year] || 0 },
{ month: "May", value: data.may_avg[year] || 0 },
{ month: "June", value: null },
{ month: "July", value: null },
{ month: "August", value: null },
{ month: "September", value: null },
{ month: "October", value: null },
{ month: "November", value: null },
{ month: "December", value: null }
];

// Update Y scale domain dynamically
const validValues = dataset.filter(d => d.value !== null);
yScale.domain([0, d3.max(validValues, d => d.value)]).nice();

// Update Y Axis
yAxis.transition().duration(1000).call(d3.axisLeft(yScale));

// Update Line
path.datum(dataset)
.transition()
.duration(1000)
.attr("d", line);

// 🔹 **Fix: Update Year Label Correctly**
yearText.text(`Year: ${year}`);
}

// Cycle through years every 2 seconds
function animateYears() {
updateGraph(years[currentYearIndex]);
currentYearIndex = (currentYearIndex + 1) % years.length;
setTimeout(animateYears, 2000);
}

animateYears(); // Start animation
})
.catch(error => console.error("Error loading JSON:", error));
}
Loading

0 comments on commit 536a0b1

Please sign in to comment.