Skip to content

Plotting Functions

-6-5-4-3-2-10123456210-1-2

Props

NameDescriptionTypeDefault
functionThe function to plot.(x: number, time?: number) => numbernone
colorThe color of the plot.string#000
line-widthThe width of the plot's line.number1.5
animatedWhether the plot should be animated.booleanfalse
domainThe domain in which the function should be plotted.PossibleVector2The parent <Graph>'s domain-x

Animating Plots

The FunctionPlot component can be animated by setting the animated prop. This will cause the plot to be redrawn every frame using requestAnimationFrame. In this case, the time parameter of the function will be set to the current timestamp on each frame.

This can be used to plot functions that change over time, such as the following:

Code
vue
<template>
  <Graph :domain-y="[-2, 2]" :domain-x="[-2, 2]" :units="false">
    <FunctionPlot
      :function="(x, time) => Math.cos(x + time / 500)"
      :line-width="2"
      animated
    />
  </Graph>
</template>

Examples

Basic Function Plot

-6-5-4-3-2-10123456210-1-2
Code
vue
<template>
  <Graph :domain-y="[-2, 2]" :domain-x="[-6, 6]">
    <FunctionPlot :function="(x) => Math.cos(x)" :line-width="2" />
  </Graph>
</template>