Creating a data visualization dashboard with Swift Charts
At a glance
| Item | Summary |
|---|---|
| Purpose | Visualize an entire data collection efficiently by instantiating a single vectorized plot in Swift Charts. |
| App architecture | A Swift sample with the source-visible chain SwiftChartsWWDC24App → ContentView → Model → Charts APIs. |
| Main patterns | SwiftUI environment injection |
| Project style | 30 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── SwiftChartsWWDC24/
├── SwiftChartsWWDC24App.swift
├── Charts/
│ ├── ScatterplotPanel.swift
│ ├── TimeSeriesPanel.swift
│ ├── DecisionBoundaryPlot.swift
│ ├── Heatmap.swift
│ ├── TimeSeriesBars.swift
│ └── BreakdownHistogram.swift
├── ContentView.swift
├── Data/
│ ├── Model.swift
│ └── QuadraticRegression.swift
├── DashboardWindows.swift
└── BreakdownPanel.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 5 project/configuration file(s) and 46 source declaration(s).
Overall architecture
flowchart LR
N1["SwiftChartsWWDC24App"]
N2["ContentView"]
N3["Model"]
N4["Charts APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
SwiftChartsWWDC24/SwiftChartsWWDC24App.swift:10 — architecture anchor
@main
struct SwiftChartsWWDC24App: App {
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Swift Charts.
Ownership and state
classDiagram
ScatterplotPanel *-- GeographicalCoordinateKind : scatterplotKind
ScatterplotPanel o-- LocalizedStringKey : title
HeatmapBinKey *-- String : xLongitude
HeatmapBinKey *-- String : yLatitude
Ownership evidence
SwiftChartsWWDC24/Charts/ScatterplotPanel.swift:19 — stored dependency or nearest verified ownership anchor
struct ScatterplotPanel: View {
@State private var scatterplotKind: GeographicalCoordinateKind = .longitude
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ScatterplotPanel |
GeographicalCoordinateKind (scatterplotKind) |
owns wrapper-managed state | Owning lexical scope |
ScatterplotPanel |
LocalizedStringKey (title) |
stores or receives | App/module collaborators |
HeatmapBinKey |
String (xLongitude) |
owns value state | Initialized by the owner; the binding is immutable |
HeatmapBinKey |
String (yLatitude) |
owns value state | Initialized by the owner; the binding is immutable |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Class and protocol design
SwiftChartsWWDC24/SwiftChartsWWDC24App.swift:11 — representative type boundary
struct SwiftChartsWWDC24App: App {
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
SwiftChartsWWDC24App |
Application entry and top-level composition | App |
ContentView |
User-interface presentation and input forwarding | View |
Model |
Feature data or observable state | Concrete collaborators/imported frameworks |
GeographicalCoordinateKind |
Defines a closed set of feature states or choices | String, CaseIterable, Identifiable |
ScatterplotPanel |
Represents a feature value or composable behavior | View |
HeatmapBinKey |
Represents a feature value or composable behavior | Hashable |
HeatmapBinValue |
Represents feature data | Hashable |
Scatterplot |
Represents a feature value or composable behavior | View |
TimeSeriesKind |
Defines a closed set of feature states or choices | String, CaseIterable, Identifiable |
TimeSeriesPanel |
Represents a feature value or composable behavior | View |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
model (SwiftChartsWWDC24/BreakdownPanel.swift:12) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
model (SwiftChartsWWDC24/Charts/BreakdownHistogram.swift:12) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
dataKeyPath (SwiftChartsWWDC24/Charts/BreakdownHistogram.swift:33) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
model (SwiftChartsWWDC24/Charts/CapacityDensityDistribution.swift:13) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
SwiftChartsWWDC24/BreakdownPanel.swift:12 — representative boundary
@Environment(Model.self) private var model: ModelSwift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | SwiftChartsWWDC24App |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | Model |
The source’s Model suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| SwiftUI environment injection | SwiftChartsWWDC24/BreakdownPanel.swift:12 |
The environment supplies state or a capability without threading it through every initializer. |
Naming conventions
- Types: App: SwiftChartsWWDC24App; Model: Model; View: ContentView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
sortDataByBreakdown,loadSampleData. - Files:
SwiftChartsWWDC24/SwiftChartsWWDC24App.swift,SwiftChartsWWDC24/Charts/ScatterplotPanel.swift,SwiftChartsWWDC24/Charts/TimeSeriesPanel.swift,SwiftChartsWWDC24/ContentView.swift,SwiftChartsWWDC24/Data/Model.swift,SwiftChartsWWDC24/Charts/DecisionBoundaryPlot.swift.
Architecture takeaways
SwiftChartsWWDC24Appis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, Charts, Accelerate, TabularData through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
SwiftChartsWWDC24/SwiftChartsWWDC24App.swift |
SwiftChartsWWDC24App |
SwiftChartsWWDC24/Charts/ScatterplotPanel.swift |
GeographicalCoordinateKind, ScatterplotPanel, HeatmapBinKey, HeatmapBinValue, Scatterplot |
SwiftChartsWWDC24/Charts/TimeSeriesPanel.swift |
TimeSeriesKind, TimeSeriesPanel, HeatmapBinKey, HeatmapBinValue, TimeSeries |
SwiftChartsWWDC24/ContentView.swift |
Tabs, ContentView |
SwiftChartsWWDC24/Data/Model.swift |
Model |
SwiftChartsWWDC24/Charts/DecisionBoundaryPlot.swift |
DecisionBoundaryPlot, Category, Element |
SwiftChartsWWDC24/Charts/Heatmap.swift |
Heatmap, HeatmapBinKey, HeatmapBin |
SwiftChartsWWDC24/Charts/TimeSeriesBars.swift |
TimeHoverHighlight, TimeSeriesBars, SubBarKey |
SwiftChartsWWDC24/DashboardWindows.swift |
DashboardWindow, DashboardWindows |
SwiftChartsWWDC24/Data/QuadraticRegression.swift |
QuadraticRegression, ConfidenceInterval |