Skip to content

Built-in shapes

ShapeFactory automatically registers a collection of built-in shapes that can be used directly with build() without explicit registration.

js
const shape = factory.build({
  shape: 'flag',
  color: 'red'
})

All built-in shapes support the common build parameters documented in ShapeFactory.build(). And Some shapes accept additional parameters or have specific behavior, as described below.

Available shapes

The following shapes are registered by default:

ShapeDescription
circleCircle
compassCompass marker
crossCross
xDiagonal cross
diamondDiamond
donutDonut chart composed of slices
piePie chart composed of slices
flagFlag marker
heartHeart
marker-pinMap marker pin anchored at the bottom center
square-pinSquare map pin anchored at the bottom center
pentagonRegular-style pentagon
hexagonRegular-style hexagon
octagonRegular-style octagon
polygonGeneric polygon
polylinePolyline symbol
rectRectangle
rounded-rectRectangle with rounded corners
star-4Four-branch star
star-5Five-branch star
star-6Six-branch star
starAlias for star-5
targetTarget symbol
triangleUpward-pointing triangle
triangle-downDownward-pointing triangle
triangle-leftLeft-pointing triangle
triangle-rightRight-pointing triangle
wind-barbMeteorological wind barb

TIP

The complete collection can also be browsed and previewed in the Shape Studio.

Parameterized shapes

donut

Creates a donut chart from a collection of slices.

Additional parameters

NameTypeRequiredDescription
slicesobject[]yesSlices composing the donut
slices[].valuenumberyesValue of the slice. Slice angles are computed relative to the sum of all values
slices[].colorstringnoFill color of the slice
slices[].opacitynumbernoOpacity of the slice
innerRadiusnumbernoRadius of the inner hole in the normalized 0..100 shape coordinate system. Defaults to 20
centerobjectnoCenter properties
center.colorstringnoColor used to fill the center of the donut. If omitted or transparent, the center remains transparent

The stroke defined on the shape is applied to each slice.

The sum of the slice values must be greater than zero.

Example

js
const shape = factory.build({
  shape: 'donut',
  slices: [
    { value: 30, color: 'red' },
    { value: 70, color: 'blue' }
  ],
  innerRadius: 25,
  stroke: {
    color: 'white',
    width: 1
  }
})

pie

Creates a pie chart from a collection of slices.

pie accepts the same parameters as donut, except that the inner radius is forced to 0.

Example

js
const shape = factory.build({
  shape: 'pie',
  slices: [
    { value: 25, color: 'red' },
    { value: 50, color: 'green' },
    { value: 25, color: 'blue' }
  ]
})

wind-barb

Creates a meteorological wind barb representing wind speed.

Additional parameters

NameTypeRequiredDescription
speednumbernoWind speed in knots. Defaults to 0
directionnumbernoWind direction in degrees, indicating the direction from which the wind is coming. Defaults to 0
anchorRadiusnumbernoRadius of the anchor circle when showAnchor is enabled. Defaults to 5. If set to 0 the anchor is ignored.

The speed is clamped to zero for negative values and rounded to the nearest multiple of 5 knots.

Wind speed is represented according to the usual wind-barb convention:

RepresentationSpeed
Calm circle0 kt
Half barb5 kt
Full barb10 kt
Pennant50 kt

These elements are combined to represent higher speeds. For example, 65 kt is represented by one pennant, one full barb, and one half barb.

The generic transform parameter can be used to orient the wind barb.

Examples

js
const shape = factory.build({
  shape: 'wind-barb',
  speed: 25,
  stroke: {
    color: 'black',
    width: 1
  }
})

A wind barb can be rotated using the standard shape transform:

js
const shape = factory.build({
  shape: 'wind-barb',
  speed: 25,
  transform: {
    rotate: [225, 50, 50]
  },
  stroke: {
    color: 'black',
    width: 1
  }
})