A beautiful 3D heatmap visualization app built with SwiftUI and Metal, designed to display GitHub-style contribution data in an interactive 3D environment.
- 3D Interactive Visualization: Navigate through your data with intuitive gesture controls
- Trackball Rotation: Smooth rotation with inertia physics for natural interaction
- Pinch-to-Zoom: Scale the visualization to focus on specific areas
- Month Labels: Clear temporal indicators for better data understanding
- High Performance: Leverages Metal for smooth 60fps rendering
- Modern UI: Clean SwiftUI interface with gesture control toggles
- Metal Rendering: Custom Metal shaders for high-performance 3D graphics
- Trackball Algorithm: Intuitive 3D rotation mapping from 2D touch gestures
- Inertia Physics: Natural momentum-based rotation with configurable decay
- Texture-based Labels: Efficient text rendering using Metal textures
- Multi-sampling: 4x MSAA for smooth anti-aliased graphics
- iOS 14.0+
- Xcode 12.0+
- Swift 5.0+
- Metal-compatible device
- Clone the repository:
git clone https://github.com/linghugoogle/ThreeDHeatmap.git- Open
ThreeDHeatmap.xcodeprojin Xcode - Build and run the project on your device or simulator
- Drag: Rotate the 3D heatmap around its center
- Pinch: Zoom in/out to scale the visualization
- Toggle: Use the gesture control switch to enable/disable interactions
The heatmap displays a 52×7 grid representing:
- Weeks: 52 weeks of the year (X-axis)
- Days: 7 days of the week (Y-axis)
- Intensity: Height and color represent data values (Z-axis)
- MetalRenderer: Main rendering engine handling 3D graphics
- HeatmapView: SwiftUI wrapper for Metal view with gesture handling
- Shaders.metal: Custom Metal shaders for vertex and fragment processing
- ContentView: Main UI with controls and layout
- Trackball Mapping: Converts 2D screen coordinates to 3D rotation vectors
- Matrix Transformations: Model-View-Projection pipeline for 3D rendering
- Inertia System: Physics-based momentum for natural interaction feel
Edit the generateHeatmapData() method in MetalRenderer.swift:
private func generateHeatmapData() {
// Customize your data generation logic here
for week in 0..<52 {
var weekData: [Float] = []
for day in 0..<7 {
let intensity = Float.random(in: 0...1)
weekData.append(intensity)
}
heatmapData.append(weekData)
}
}Modify the colorForIntensity() method to change the color scheme:
private func colorForIntensity(_ intensity: Float) -> simd_float4 {
// Customize your color mapping here
return simd_float4(intensity, 0.5, 1.0 - intensity, 1.0)
}- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by GitHub's contribution graph
- Built with Apple's Metal framework
- Uses SwiftUI for modern iOS development
- GitHub: @linghugoogle
- Email: [email protected]
Note: This project demonstrates advanced iOS development techniques including Metal rendering, 3D mathematics, and gesture handling. It's perfect for learning about high-performance graphics programming on iOS.
