WaffleChart

A grid of squares where each part owns as many squares as its share. Use it for a share you want people to feel, such as 65 of every 100 users.

It is plain svg, so it does not need any extra package.

General

The whole grid is the sum of the values, 100 squares by default.

Total and empty squares

With total, the values are measured against it and the squares left over stay empty.

Direction

fillDirection sets the order the squares are given out in.

APIs

WaffleChart.Props

AttributeDescriptionTypeAccepted valuesDefault
datathe parts of the wholeWaffleCell[]WaffleCell-
rowsnumber of rowsnumber-10
columnsnumber of columnsnumber-10
totalwhat the whole grid stands for, the sum of the values when missingnumber--
fillDirectionthe order squares are given out instring'left-to-right', 'right-to-left', 'top-to-bottom', 'bottom-to-top'left-to-right
gapspace between squares, in pixelsnumber-2
cellRadiuscorner radius of a square, in pixelsnumber-2
sizewidth of the grid, in pixelsnumber-220
emptyColorcolor of the squares nobody ownsstring-theme color
withLegendlist the parts below the gridboolean-true
valueFormatterhow a number is written(value: number) => string-thousands separators, en-US
...native props, passed to the rootHTMLAttributes'aria-label', 'className', ...-

WaffleCell

type WaffleCell = {
  name: string
  value: number // squares are given out in proportion to it
  color?: string // any CSS color, a theme color when missing
}

Ref

The ref points at the root div.

Accessibility

With aria-label or aria-labelledby the root is a group. The legend lists every part with its value as text, so the grid itself is hidden from assistive technology. Without the legend, the grid becomes an image named by the parts, such as "Chrome 65, Safari 25, Other 10".

Edit this page on GitHub