Coordinates

Coordinates overlay a grid of lines on top of the Mafs canvas to give a sense of scale. Axes are pretty configurable—the spacing between lines, number of subdivisions, and the labels themselves can be altered.

Cartesian coordinates

import { Mafs, CartesianCoordinates } from "mafs" function CartesianCoordinatesExample() { return ( <Mafs> <CartesianCoordinates /> </Mafs> ) }

Props

<CartesianCoordinates ... />
NameDescriptionDefault
xAxis
false | Partial<AxisOptions>
yAxis
false | Partial<AxisOptions>
subdivisions
number | false
false

Axis options

Each axis—xAxis and yAxis—can be configured with the following options:

  • axis: Whether to draw the axis line.
  • lines: The spacing between each primary line orthogonal to the axis, or false to draw none.
  • subdivisions: How many subdivisions to draw per line, or false to draw none.
  • labels: A function that returns a label for each line.

The entire axis can also be set to falseto disable it entirely.

Mafs also exports a helper function, labelPi, which can be passed to labels to render in terms of π.

import { Mafs, CartesianCoordinates, labelPi } from "mafs" function CartesianCoordinatesExample() { return ( <Mafs viewBox={{ x: [-8, 8], y: [-Math.PI * 2, Math.PI * 2], padding: Math.PI / 2, }} preserveAspectRatio={false} > <CartesianCoordinates xAxis={{ lines: 1, labels: (n) => (isOdd(n) ? n : ""), }} yAxis={{ lines: Math.PI, subdivisions: 4, labels: labelPi, }} /> </Mafs> ) } function isOdd(n: number) { return ((n % 2) + 2) % 2 === 0 }

Polar coordinates

Polar coordinates are not yet implemented in Mafs. There is an open issue for this.