Skip to main content

Overview

The ClimateChartView component displays historical temperature data for the current date across multiple decades, visualizing local climate trends. It uses iOS Charts framework to render a bar chart showing how temperatures have changed over time, with color-coded bars indicating warming or cooling trends.

Visual Display

The chart presents:
  • Header with trend icon and description
  • Temperature unit toggle (Celsius/Fahrenheit)
  • Change summary showing temperature difference from baseline year
  • Bar chart with data points for each decade
  • Color-coded bars (blue for cooling, gray for neutral, orange/red for warming)
  • Value labels above each bar

Component Definition

Props / Parameters

[ClimateDataPoint]
required
Array of historical temperature data points. Each ClimateDataPoint contains:
  • year: The year (e.g., 1980, 1990, 2000)
  • temperature: Temperature in Celsius for that year
Binding<Bool>
required
Binding to control whether temperatures are displayed in Fahrenheit or Celsius. User can toggle this with the built-in switch.
(Double) -> String
required
Closure that formats temperature values for display. Should handle both Celsius and Fahrenheit formatting.
(Double) -> String
required
Closure that formats temperature differences (e.g., “+2.1°F”). Used for the change summary.

Key Features

Temperature Unit Toggle

iOS-style toggle switch for Celsius/Fahrenheit:

Change Summary

Displays temperature change from baseline year:

Bar Chart (iOS 16+)

Uses Swift Charts framework for modern visualization:

Color Coding Logic

Bars are colored based on temperature change from baseline:
  • Red: +2°C or more warming
  • Orange: +0.5°C to +2°C warming
  • Gray: -0.5°C to +0.5°C (neutral)
  • Blue: More than -0.5°C cooling

Fallback for iOS 15 and Earlier

Manual bar chart rendering for older iOS versions:

Temperature Conversion

Automatic conversion based on unit preference:

Usage in App

Data Context

The chart visualizes how temperatures on the current calendar date (e.g., March 4th) have changed across different decades, helping users understand local climate trends at a glance.

Requirements

  • iOS 16.0+ for Swift Charts support
  • Falls back to custom rendering on iOS 15 and earlier

Source Location

BreezeApp/Views/Environmental/ClimateChartView.swift:4