Function Graph Element

A Function Graph element renders mathematical function curves with configurable axes, fill, and styling. The expression is evaluated in a sandboxed environment.

Function Graph elements share the common fields from Basic Element and View Element.

Function Graph Properties

PropTypeRequiredExampleValue RangeDescription
typestringtrue-Function GraphThe type of the element. For Function Graph elements, this is always "Function Graph".
expressionstringtrueMath.sin(x)-The mathematical expression to plot. Uses JavaScript Math syntax with x as the variable.
rangearrayfalse[-10, 10]-The x-axis range as a two-element array [min, max].
samplesnumberfalse-> 0The number of sample points used to plot the curve. Higher values produce smoother curves.
thicknessnumberfalse-> 0The line thickness of the function curve, in pixels.
colorstringfalse--The color of the function curve, in hex format.
backgroundColorstringfalse--The background color of the graph area, in hex format.
backgroundOpacitynumberfalse-0 - 1The opacity of the background.
thresholdnumberfalse--Maximum y-value threshold for clipping. Points beyond this value are not rendered.
flipYbooleanfalse--Whether to flip the Y-axis direction.
fillColorstringfalse--The fill color under the curve, in hex format.
fillOpacitynumberfalse-0 - 1The opacity of the area fill under the curve. Set to 0 to disable fill.

Axis Properties

PropTypeRequiredExampleValue RangeDescription
showAxisbooleanfalse--Whether to display the coordinate axes.
axisColorstringfalse--The color of the axis lines, in hex format.
axisOpacitynumberfalse-0 - 1The opacity of the axis lines.
axisTickCountnumberfalse--The number of tick marks on each axis.
axisThicknessnumberfalse--The thickness of the axis lines, in pixels.
showAxisArrowbooleanfalse--Whether to show arrowheads at the ends of the axes.
axisArrowSizenumberfalse--The size of the axis arrowheads, in pixels.

Example

Sine Wave

functionGraphElement.json
1 2{ 3 "id": "graph-001", 4 "type": "Function Graph", 5 "start": 0, 6 "duration": 5, 7 "trackIndex": 0, 8 "x": 200, 9 "y": 200, 10 "width": 400, 11 "height": 200, 12 "anchorX": 200, 13 "anchorY": 100, 14 "rotation": 0, 15 "scaleX": 1, 16 "scaleY": 1, 17 "alpha": 1, 18 "expression": "Math.sin(x)", 19 "range": [-10, 10], 20 "samples": 200, 21 "thickness": 2, 22 "color": "#C55F73", 23 "backgroundColor": "#000000", 24 "backgroundOpacity": 1, 25 "showAxis": true, 26 "axisColor": "#ffffff", 27 "axisTickCount": 10 28} 29

Filled Quadratic Function

functionGraphFilled.json
1 2{ 3 "id": "graph-002", 4 "type": "Function Graph", 5 "start": 0, 6 "duration": 8, 7 "trackIndex": 0, 8 "x": 300, 9 "y": 250, 10 "width": 500, 11 "height": 300, 12 "anchorX": 250, 13 "anchorY": 150, 14 "rotation": 0, 15 "scaleX": 1, 16 "scaleY": 1, 17 "alpha": 1, 18 "expression": "x * x - 4", 19 "range": [-5, 5], 20 "samples": 300, 21 "thickness": 3, 22 "color": "#4A90E2", 23 "fillColor": "#4A90E2", 24 "fillOpacity": 0.3, 25 "backgroundColor": "#1a1a2e", 26 "backgroundOpacity": 0.9, 27 "showAxis": true, 28 "axisColor": "#cccccc", 29 "axisThickness": 2, 30 "showAxisArrow": true, 31 "axisArrowSize": 10 32} 33

Notes

  • The expression is evaluated in a sandboxed environment with access to the JavaScript Math object. Use Math.sin(x), Math.pow(x, 2), Math.exp(x), etc.
  • The variable x iterates over the specified range with the given number of samples.
  • Set fillOpacity greater than 0 to fill the area between the curve and the x-axis.
  • Use threshold to clip extreme y-values for functions with asymptotes (e.g., 1/x).