Coord.clock
A polar coordinate system oriented like a clock face. 0° is at 12 o'clock (top) and angles increase clockwise. Ideal for pie charts, donut charts, and radial visualizations.
js
gf.chart(seafood, { coord: gf.Coord.clock() })
.flow(gf.stack({ by: "species", dir: "x" }))
.mark(gf.rect({ w: "count", fill: "species" }))
.render(root, {
w: 400,
h: 300,
transform: { x: 200, y: 150 },
});Signature
ts
Coord.clock(options?: {
innerRadius?: number; // donut hole, fraction [0,1) of outer radius. Default 0
centralAngle?: number; // total sweep in radians. Default 2π
baselineAngle?: number; // angle (radians) where θ's 0 sits, from 3 o'clock. Default π/2 (12 o'clock)
direction?: 1 | -1; // +1 CCW, -1 CW. Default -1 (clockwise)
center?: [number, number]; // screen-space center offset. Default [0, 0]
});Parameters
The polar transform in the clock convention: θ=0 at 12 o'clock, increasing clockwise. It differs from Coord.polar() only in the baselineAngle and direction defaults.
| Option | Type | Default | Description |
|---|---|---|---|
innerRadius | number | 0 | Donut hole as a fraction [0,1) of the outer radius. |
centralAngle | number | 2π | Total angular sweep in radians. |
baselineAngle | number | π/2 | The angle where the angular axis's 0 sits: radians, measured counter-clockwise from 3 o'clock. Data 0 on θ maps here for every θ range and every sweep. |
direction | number | -1 | +1 counter-clockwise, -1 clockwise (numeric ±1). |
center | [number, number] | [0, 0] | Screen-space center offset. |
Coord.clock() is the Coord.polar() transform and accepts the same options — innerRadius, centralAngle, baselineAngle, direction, center. Only the baselineAngle and direction defaults differ: 0° at 12 o'clock, clockwise. See polar's Parameters. As in polar, the number 0 on the angular axis always sits at baselineAngle.
Usage
Pass the coordinate transform to chart() via the coord option:
ts
chart(data, { coord: Coord.clock() })
.flow(...)
.mark(...)
.render(container, opts);Coordinate Mapping
| Cartesian | Clock |
|---|---|
| x | angle (theta), 0° at top, clockwise |
| y | radius from center |
Examples
ts
// Pie chart
chart(data, { coord: Coord.clock() })
.flow(stack({ by: "category", dir: "x" }))
.mark(rect({ w: "value", fill: "category" }));
// Donut chart (hollow center via inner radius)
chart(data, { coord: Coord.clock({ innerRadius: 0.6 }) })
.flow(stack({ by: "category", dir: "x" }))
.mark(rect({ w: "value", fill: "category" }));
// Rose chart (radial bar chart)
chart(data, { coord: Coord.clock() })
.flow(stack({ by: "month", dir: "x" }))
.mark(rect({ w: (Math.PI * 2) / 12, emX: true, h: "value" }));See Also
- polar — The same transform with 0° at right, going counter-clockwise
