Skip to content

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.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
clock();

Parameters ​

A polar() preset (0° at 12 o'clock, clockwise — already polar's defaults) kept as a distinct type tag for bbox sampling and user intent.

OptionTypeDefaultDescription
innerRadiusnumber0Donut hole as a fraction [0,1) of the outer radius.
centralAnglenumber2πTotal angular sweep in radians.
startAnglenumberπ/2Angle (radians) of θ=0.
directionnumber-1+1 counter-clockwise, -1 clockwise (numeric ±1).
center[number, number][0, 0]Screen-space center offset.

clock() is a polar() preset and accepts the same options — innerRadius, centralAngle, startAngle, direction, center — but with clock-face defaults (0° at 12 o'clock, clockwise). See polar's Parameters.

Usage ​

Pass the coordinate transform to chart() via the coord option:

ts
chart(data, { coord: clock() })
  .flow(...)
  .mark(...)
  .render(container, opts);

Coordinate Mapping ​

CartesianClock
xangle (theta), 0° at top, clockwise
yradius from center

Examples ​

ts
// Pie chart
chart(data, { coord: clock() })
  .flow(stack({ by: "category", dir: "x" }))
  .mark(rect({ w: "value", fill: "category" }));

// Donut chart (hollow center via inner radius)
chart(data, { 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: clock() })
  .flow(stack({ by: "month", dir: "x" }))
  .mark(rect({ w: (Math.PI * 2) / 12, emX: true, h: "value" }));

See Also ​

  • polar — Standard polar coordinates with 0° at right