Skip to main content

Overview

The Climate Data feature visualizes long-term temperature trends for the user’s location, showing how temperatures on the current day have changed across multiple decades. This helps users understand local climate change impacts through historical data comparison.

Implementation

ClimateChartView Component

The climate chart uses SwiftUI Charts (iOS 16+) to display temperature data:
ClimateChartView.swift

Visual Design

The chart includes several key visual elements:

Header Section

  • Chart icon and title “Local Climate Trend”
  • Subtitle explaining the data
  • Temperature unit toggle (°C/°F)

Summary Bar

  • “Change since [baseline year]” label
  • Large, color-coded temperature difference
  • Red for warming, blue for cooling

Bar Chart

  • One bar per decade (typically 1980, 1990, 2000, 2010, 2020, current year)
  • Bars colored based on temperature deviation from baseline
  • Temperature values annotated above each bar
  • Y-axis with temperature scale

Color Coding

Bars are color-coded based on deviation from the baseline (first year):
ClimateChartView.swift
The color thresholds are based on climate science:
  • 0.5°C: Noticeable climate shift
  • 2°C: Significant warming threshold (Paris Agreement target)

Temperature Unit Conversion

The chart supports both Celsius and Fahrenheit:
ClimateChartView.swift
Formatting is handled by the ViewModel:
DashboardViewModel.swift

Data Model

Climate data points are simple year-temperature pairs:
ClimateData.swift

Data Source

Historical temperature data is fetched from Open-Meteo’s Archive API via ClimateService.swift:
ClimateService.swift
The API response structure:
ClimateData.swift

Fallback for Older iOS

For devices running iOS versions before 16.0 (which don’t support SwiftUI Charts), a custom bar chart implementation is provided:
ClimateChartView.swift

Custom Bar Height Calculation

ClimateChartView.swift

Integration with Dashboard

The climate chart is conditionally displayed when data is available:
DashboardView.swift
Data is fetched asynchronously:
DashboardViewModel.swift

User Preferences

The temperature unit preference is stored in the ViewModel:
DashboardViewModel.swift
Changing the toggle immediately updates all displayed temperatures through SwiftUI’s reactive binding system.

Educational Value

The climate chart helps users:
  • Understand local climate change impacts
  • See tangible evidence of warming trends
  • Compare current conditions to historical baselines
  • Visualize temperature changes over their lifetime
The chart shows temperature for the same calendar day (e.g., March 4) across different years, eliminating seasonal variation and highlighting long-term trends.

File Locations

  • Component: BreezeApp/Views/Environmental/ClimateChartView.swift
  • Model: BreezeApp/Models/ClimateData.swift
  • Service: BreezeApp/Services/ClimateService.swift
  • ViewModel: BreezeApp/ViewModels/DashboardViewModel.swift