Skip to content

Draw the Glucose Graph complication in the widget at its slot's size - #2

Merged
jeremybarnum merged 1 commit into
jeremybarnum:complications/stock-widgetkitfrom
LoopKit:complications/widget-renders-graph
Nov 1, 2026
Merged

jeremybarnum merged 1 commit into
jeremybarnum:complications/stock-widgetkitfrom
LoopKit:complications/widget-renders-graph

Conversation

@ps2

@ps2 ps2 commented Nov 1, 2026 •

Copy link
Copy Markdown

The Glucose Graph complication only fills about three quarters of its slot's width on a 45 mm watch. The watch app renders the chart as a 171×54 image, the old ClockKit graphic rectangular size, and the widget shows it aspect-fit under the header line. The space under the header is shorter than 54 pt, so the image is scaled down and leaves a gap on the right.

This moves the drawing into the widget:

  • The app publishes the graph's data in ComplicationSnapshot instead of a PNG. That's plain numbers in the display unit: target ranges, the active override, readings, the prediction, and the axis bounds and labels. It's a few KB of JSON, and the extension still links nothing of Loop's.
  • The widget draws it with a SwiftUI Canvas in whatever space the slot leaves under the header, so it fills the slot on every watch size.
  • The drawing follows ComplicationChartManager: 4 h centered on now, the same bands, dots, dashed prediction and labels.
  • Each timeline entry is drawn at its own date, so the graph stays aligned with the stale and freshness moments the timeline already carries. The app keeps an extra hour of data ahead for those entries.
  • The ClockKit complications still use ComplicationChartManager. The PNG in the app group is no longer written.

Testing:

  • ComplicationSnapshotTests pass, with a new round trip of a snapshot carrying a graph.
  • The full workspace build succeeds, for the watch simulator and for a device.
  • It hasn't run on a watch yet. The same commit applies cleanly on the Sport Mode line.

The watch app rendered the chart as a 171x54 image (the ClockKit graphic
rectangular size) and the widget showed it aspect-fit under its header line,
so on 45 mm and larger watches the graph filled only about three quarters of
the slot's width.

The app now publishes the graph's data in the snapshot as plain numbers in
the display unit (target ranges, the active override, readings, prediction,
axis bounds and labels), and the widget draws it with a Canvas at the space
the slot leaves, positioned for each timeline entry's date. The drawing
follows ComplicationChartManager, which the ClockKit complications still use.
The PNG in the app group is no longer written.
@ps2
ps2 marked this pull request as ready for review November 1, 2026 19:26
@jeremybarnum
jeremybarnum merged commit 8b7725b into jeremybarnum:complications/stock-widgetkit Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants