AGP & Rendering
Build an AGP-style percentile-band series and optional SVG renderers.
The AGP series
buildAGPProfile pools readings by minute-of-day (time-zone aware) across all
days and reduces each bin to an AGP-style percentile-band series. It supplies
chart data rather than a complete standardized AGP report.
import { buildAGPProfile, type GlucoseReading } from '@glucoseiq/core'
const readings: GlucoseReading[] = [
{ value: 104, unit: 'mg/dL', timestamp: '2026-07-01T08:00:00Z' },
{ value: 121, unit: 'mg/dL', timestamp: '2026-07-02T08:00:00Z' },
]
const profile = buildAGPProfile(readings, {
timeZone: 'America/New_York', // local clock, DST-correct
binMinutes: 5, // 288 bins/day
percentiles: [5, 25, 50, 75, 95],
})
const populatedBin = profile.bins.find((bin) => bin.n > 0)
if (!populatedBin) throw new Error('Expected one populated time-of-day bin')
populatedBin
// { minuteOfDay: 240, percentiles: { 5: 104, 25: 104, 50: 104, 75: 121, 95: 121 }, n: 2 }Draw it with any chart library as two shaded areas (5–95, 25–75) plus a median line, or use the SVG renderer:
AGP-in-a-tag
import { agpChartToSVG, type GlucoseReading } from '@glucoseiq/core'
const readings: GlucoseReading[] = [
{ value: 104, unit: 'mg/dL', timestamp: '2026-07-01T08:00:00Z' },
{ value: 121, unit: 'mg/dL', timestamp: '2026-07-02T08:00:00Z' },
]
const svg = agpChartToSVG(readings, { theme: 'dark', title: 'Last 14 days' })
// A self-contained <svg> string. No DOM, canvas, or framework required.The renderer returns an SVG string. A browser can embed it as trusted markup;
email, PDF, README, and native hosts need host-specific embedding, conversion,
or application integration. Companions are tirBarToSVG (the five-zone
stacked bar) and trendTileToSVG (the glanceable current-value tile).
Reproducibility
Nearest-rank percentiles are the default, matching glucosePercentiles and
keeping cited results reproducible. Set method: 'linear' to use interpolated
type-7 percentiles.
The percentile-band conventions follow the international consensus report: Battelino et al., 2019.