SPB Git

Repository Public MIT

glass-chart.md 4.3 KB 92 lines markdown

1# GlassChart23| | |4|---|---|5| Identifier | `glass-chart` |6| Module | `SPGlassData` |7| Kind | `content-component` — Swift Charts on an opaque surface; glass only for the optional floating control |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Frameworks | Charts |10| Example | `Examples/Gallery/Data/GlassChartExample.swift` |1112## Minimal usage1314```swift15GlassChart("Monthly revenue", points: [16    GlassChartPoint(label: "Jan", value: 42),17    GlassChartPoint(label: "Feb", value: 48),18    GlassChartPoint(label: "Mar", value: 55),19])20```2122## Variants2324| Variant | Use |25|---|---|26| `kind: .line` | Evolution of a value. Series are told apart by colour, by symbol and by the legend. |27| `kind: .bar` | Comparison between categories. |28| `kind: .area` | Volume over time; several series are stacked by Swift Charts. |29| Category axis | Points created with `label:`. |30| Time axis | Used when every point is created with `date:`. |31| Several series | Points with a `series` name; a legend appears. |32| Overlay control | A trailing closure with a small control (series or range picker), drawn on a glass capsule over the top trailing corner of the plot. |3334## Parameters3536| Parameter | Type | Default | Meaning |37|---|---|---|---|38| `title` | `LocalizedStringKey` | — | Heading and accessibility label of the chart. |39| `points` | `[GlassChartPoint]` | — | Typed values. Non-finite values are skipped. |40| `kind` | `GlassChartKind` | `.line` | Mark type. |41| `xAxisTitle` | `String?` | `nil` | Title of the horizontal axis, already localised. |42| `yAxisTitle` | `String?` | `nil` | Title of the vertical axis, already localised. |43| `unit` | `String?` | `nil` | Unit, appended to the vertical axis title ("Energy (MWh)") and to spoken values. |44| `showsSummary` | `Bool` | `true` | Shows the generated description under the plot. |45| `overlay` | `@ViewBuilder` | none | Control floating on glass. |4647`GlassChartPoint(id:label:value:series:)` and `GlassChartPoint(id:date:value:series:)`; without an `id`, one is derived from the series and the position.4849## States5051- **Empty** (no finite value): the title and a `ContentUnavailableView` reading "No data".52- **Populated**: the plot, the optional overlay control and the summary sentence.53- Loading and failure are the host's responsibility (wrap the chart, or show a `GlassMetricCard`-style state around it).5455## Advanced example5657```swift58@State private var series = "All"5960var visible: [GlassChartPoint] {61    series == "All" ? production : production.filter { $0.series == series }62}6364GlassChart("Energy produced", points: visible, kind: .area, xAxisTitle: "Month", yAxisTitle: "Energy", unit: "MWh") {65    Picker("Series", selection: $series) {66        Text("All").tag("All")67        ForEach(GlassChartLogic.seriesNames(production), id: \.self) { Text(verbatim: $0).tag($0) }68    }69    .pickerStyle(.menu)70}7172// The description is a pure function, usable outside the view:73let text = GlassChartLogic.description(of: production, unit: "MWh")74// "North: 6 values from Jan to Jun. Minimum 42 MWh, maximum 70 MWh. Trend: Up. South: …"75```7677## Accessibility7879- Every mark has an accessibility label (series and position) and value (formatted number and unit), so the chart can be explored element by element and with the system's audio graph.80- A sentence per series states the number of values, the first and last positions, the minimum, the maximum and the trend. It is visible under the plot, or kept as an accessibility-only element when `showsSummary` is `false`.81- Series never rely on colour alone: the legend names them and line charts add a distinct symbol per series.82- Numbers and dates are formatted with `FormatStyle` in the environment's locale and time zone.8384## Limits8586- The trend compares the last value with the first one; it is flat when they differ by at most 1 % of the series' scale. It is a description, not a regression.87- The overlay control covers the top trailing corner of the plot; keep it small.88- Series colours come from Swift Charts' default palette; a single series uses the theme's `primary` colour. Per-series theme colours are not exposed.89- No selection, zooming or scrolling of the plot: use Swift Charts directly for interactive charts.90- A chart mixing dated and labelled points uses a category axis, with dates shown as abbreviated text.91- Rendering was compiled for macOS and iOS; the visual result was not checked on a device in this phase.92
Files main
Menu

Theme