Sunburst diagram is a library written with SwiftUI to easily render diagrams given a tree of objects. Similar to ring chart, sunburst chart, multilevel pie chart.
This library targets modern SwiftUI on iOS, macOS, tvOS, and watchOS and requires Swift 6.2+ and Xcode 17+ (some public API features are still TODO; see below).
- iOS 26.0+ / macOS 26.0+ / tvOS 26.0+ / watchOS 26.0+
- Xcode 17+
- Swift 6.2+
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is integrated in Xcode.
Once you have your Swift package set up, adding SunburstDiagram as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [
.package(url: "https://github.com/lludo/SwiftSunburstDiagram.git", from: "1.5.1")
]CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SunburstDiagram into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'SunburstDiagram', '~> 1.5.1'If you prefer not to use the Swift Package Manager, you can integrate SunburstDiagram into your project manually.
- Configure with a tree of node objects
- Nodes have an optional label displayed (image & text)
- Reactive UI with animated updates
- Optionally configure nodes with a value (4 different rendering modes)
- Infinite number of layers (circles) support
- Option to configure margin, size, sort and initial positions of arcs
- Option to collapse arcs beyond a certain layer (to show more layers with less data)
- Ability to select a node and focus on a node to see more details or disable selection
- Option for maximum number of rings to display (like a window moving as you focus on nodes)
// Create your configuration model
let configuration = SunburstConfiguration(nodes: [
Node(name: "Walking", value: 10.0, backgroundColor: .system(.blue)),
Node(name: "Restaurant", value: 30.0, backgroundColor: .system(.red), children: [
Node(name: "Dessert", image: .asset(name: "croissant"), value: 6.0),
Node(name: "Dinner", image: .asset(name: "poultry"), value: 10.0),
]),
Node(name: "Transport", value: 10.0, backgroundColor: .system(.purple)),
Node(name: "Home", value: 50.0, backgroundColor: .system(.teal)),
])
// Use directly in SwiftUI
struct ContentView: View {
@StateObject private var configuration = SunburstConfiguration(nodes: sampleNodes())
var body: some View {
SunburstView(configuration: configuration)
}
}To embed in UIKit, wrap SunburstView in a UIHostingController.
Node uses lightweight references instead of platform types:
ImageRef.asset(name:)orImageRef.systemSymbol(name:)ColorRef.system(_),ColorRef.asset(name:),ColorRef.rgba(...), orColorRef.dynamic(light:dark:)
If you found a bug or want to discuss a new feature do not hesitate to message me. If you want to contribute, all pull requests are always welcome. Thank you!
The demo app in this repo is written with SwiftUI and includes:
SunburstDiagramDemomulti-platform target (iOS, macOS, tvOS, visionOS)SunburstDiagramDemoWatchstandalone watchOS app target (with watch extension)
The iOS showcase app is also available on the App Store for free.
- Implement option for min arc percentage (if less, show data grouped in "other")
- Compute arc colors if no color is provided by nodes
- Add option to show unassigned if total of arcs is less than 100%
- Add rounded corners option for arcs with margins
- Switch
BundleRef.modulefrom.mainto a real SPM resource bundle when package resources are added - Revisit any remaining sendability/concurrency warnings with an explicit ownership/actor isolation plan
- Replace placeholder app icons for demo targets (watchOS
AppIconstill has unassigned sizes) - Resolve duplicate asset warnings between
Assets.xcassetsandAssets-Shared.xcassets(croissant,eating,house,poultry,sailing,walking) - Decide whether tvOS settings remain read-only or move to custom focusable editable controls
This project has been inspired by the DaisyDisk UI and the Apple SwiftUI Building Custom Views with SwiftUI WWDC2019 session.




