Get StartedComponentsStylingThemingMath & Science
MCP

Science

Graph 2D

An interactive Cartesian plane drawn with SVG. Plot any number of functions and points; drag to pan, scroll to zoom and hover to read values.

Pair it with compileFn from @indoku/science to plot expressions typed by the user. Discontinuities such as tan(x) are split automatically.

Markdown

Import

tsx
import { Graph2D } from "@indoku/ui"import { compileFn } from "@indoku/science"

Examples

Basic usage

Functions are plain JavaScript callbacks.

-10-8-6-4-2246810-6-4-2246
sin x
cos x

Points and viewport

Label key points and choose the initial area.

-2-1123456-4-2246810rootrootvertex
x² − 2x − 3

Expression input

compileFn parses text without eval.

-10-8-6-4-2246810-6-4-2246
f(x) = sin(x) / x

Static

Turn off interaction and grid for a figure.

123456-1.5-1-0.50.511.5

Props

Graph2D

PropTypeDefaultDescription
functionsGraphFunction[]–
pointsGraphPoint[]–
viewportGraphViewport-10..10 on both axesInitial visible area.
aspectnumber–Width / height. Default 16/10.
interactiveboolean–Drag to pan, scroll to zoom, hover to read values. Default true.
gridboolean–

* required. Style props and HTML attributes are accepted as well.

Accessibility

  • Provide the same data as a table or equation in text for screen readers.

Notes

  • CartesianCanvas is an alias of Graph2D.

Created by @indokudev