Wilang Documentation1.0.0+4

Plotting#

Choose a plot type#

Type Input Example
Cartesian curve An expression in x plot(sin(x))
Parametric curve A pair of expressions in t plot([cos(t),sin(t)])
Polar curve A radius expression in theta plot(1+cos(theta))
Scatter Paired arrays or [x,y] points plot([[0,1],[1,3],[2,2]])
Indexed data One numeric array plot([2,4,3])
Moving point point(x,y) inside a plot plot(point(1,2))
Polygon or polyline A point list with styles plot([[0,0],[2,0],[1,2]],{connectPoints:true,closed:true,fill:true})
Bar chart Numeric heights, with optional x values barChart([2,4,3])
Histogram Numeric samples, with an optional bin count histogram([1,2,2,3,4],3)

These are the plot forms the app exposes. There is no built-in pie chart, 3D surface, or heatmap function. point is a series form inside plot, not a general math function you can call on its own.

Example
a = 2
plot(sin(a * x))

How the curve variable is chosen#

A Cartesian curve is swept over one variable. The app reads the expression and uses a conventional coordinate first (theta, then t, then x): plot(sin(t)) sweeps t, plot(sin(x)) stays on x, and a constant like plot(2) draws a flat line on x. When the expression has no coordinate, the single unbound name is swept instead, so plot(u^2) draws against u. Names that already have a value — document variables, sliders, and animation parameters — are parameters, never the sweep: with a slider T, plot(sin(T)) still draws on x while T animates the shape.

When several names are unbound and none is a coordinate (for example plot(u+v)), the app does not guess: it keeps the x sweep and reports which names were ambiguous, so bind all but one to pick a curve deliberately. Changing bindings re-resolves the sweep; the legend and the expression list always show the same labels, preferring an explicit label and falling back to the expression.

Multiple series and styles#

Pass series and their optional style objects in order. Put each style immediately after the series it belongs to.

Example
plot(sin(x),{color:"blue",label:"sine"},cos(x),{color:"red",label:"cosine"})
Style Meaning
color, lineWidth, dashPattern, opacity, label Line appearance and legend name
pointShape, pointRadius, showPoints Point appearance
connectPoints, closed, fill, fillColor, fillOpacity Data outline and polygon fill
showInterestPoints Mark supported notable points
tMin, tMax, thetaMin, thetaMax Parametric and polar parameter domain
min, max Legacy aliases for the parametric and polar domain
rotation, scale, scaleX, scaleY Shape transform
translateX, translateY, originX, originY Translation and transform origin
yAxis Left or right axis assignment where supported

A numeric style field can reference a slider or animation parameter. Transforms apply scale, then rotation, then translation. Viewport limits belong to @config, not to per-curve parameter bounds.

Parametric, polar, and data examples#

Example
plot([cos(t),sin(t)],{tMin:0,tMax:2*pi})
plot(1+cos(theta),{thetaMin:0,thetaMax:2*pi})
plot([0,1,2],[1,3,2])
barChart([1,2,3],[4,2,5],0.6)
histogram([1,2,2,3,4],3)

Paired data arrays need matching lengths. A bar width is in plot coordinates. A histogram groups data into bins, so it is not an exact point plot.

Geometry primitives#

A plot can also draw geometric primitives. They are written inside plot(...) like any other series, and each one is a single series with its own label, color, and style.

Constructor Meaning
circle(center, radius) A circle with a center and a radius
ellipse(center, radiusX, radiusY) An axis-aligned ellipse
rectangle(center, width, height) A centered, axis-aligned rectangle
polygon([[x1,y1], [x2,y2], ...]) A polygon through the authored vertices
regularPolygon(center, sides, radius) A regular polygon on a circumcircle
segment(a, b) A finite segment between two points
line(a, b) An infinite line through two distinct points
ray(a, b) A half-line starting at the first point
polyline([[x1,y1], [x2,y2], ...]) An open path through the authored vertices
triangle(a, b, c) A triangle through three points
square(center, side) A centered square
pentagon(center, radius) A centered regular pentagon
hexagon(center, radius) A centered regular hexagon
Example
plot(circle([0, 0], 3), {color: "indigo", fill: true, fillColor: "skyblue", fillOpacity: 0.3})
plot(ellipse([0, 0], 4, 2), {color: "crimson", lineWidth: 2})
plot(rectangle([0, 0], 4, 2), {color: "seagreen", dashPattern: [6, 4]})
plot(polygon([[0, 0], [4, 0], [3, 2], [0, 3]]), {color: "#4F46E5", fill: true, fillColor: "#38BDF8", fillOpacity: 0.3, label: "Region A"})
plot(regularPolygon([0, 0], 5, 2), {color: "darkorange"})
plot(segment([-3, 0], [3, 0]), {color: "crimson", lineWidth: 3})
plot(line([0, 0], [0, 4]), {color: "crimson", dashPattern: [2, 4]})
plot(ray([-3, 0], [3, 0]), {color: "teal"})
plot(polyline([[0, 0], [1, 2], [3, 0]]), {color: "slateblue"})
plot(triangle([-2, -1], [2, -1], [0, 2]), {fill: true, fillOpacity: 0.2})
plot(square([0, 0], 2), {color: "olivedrab"})
plot(pentagon([0, 0], 2), {color: "goldenrod"})
plot(hexagon([0, 0], 2), {color: "mediumseagreen"})

A center, an endpoint, or a vertex is a two-element array: [cx, cy]. The members are ordinary expressions, so [a + 1, sin(T)] is a valid center and follows a slider or an animation parameter. A vertex list is an array of those pairs. A whole coordinate or vertex list held in a variable is not supported yet.

radius always means the circumradius — the distance from the center to a vertex — never the side length and never the apothem. A regular polygon starts with a vertex at center + [radius, 0] and runs counter-clockwise; use the rotation style to change the orientation, and scaleX / scaleY to change the shape.

triangle, square, pentagon, and hexagon are convenience spellings. They draw exactly what polygon([a, b, c]), rectangle(center, side, side), and regularPolygon(center, 5, radius) draw.

square is also an ordinary arithmetic function. plot(square(x)) still squares x; only the two-argument form square([cx, cy], side) is geometry. If you define your own function with one of these names, yours wins — the constructor is only used when no function of that name is in scope.

Styling a primitive#

The style object after a primitive behaves like any other series style:

Style Meaning
color The outline color
lineWidth The outline width in logical pixels; 0 hides the outline
dashPattern Alternating draw and gap lengths, for example [6, 4]
fill Fills the interior of a closed shape (default false)
fillColor The interior color; defaults to the outline color
fillOpacity The interior opacity, between 0 and 1 (default 0.2)
opacity The opacity of the whole series, between 0 and 1
label The legend label
rotation, scale, scaleX, scaleY, translateX, translateY, originX, originY The data-space transform
yAxis Left or right axis assignment

The outline color and the fill color are independent. The outline is drawn at the outline color's opacity times the series opacity; the interior is drawn at the fill color's opacity times fillOpacity times the series opacity.

Filling never changes the shape: a closed polygon stays closed when fill is false. Only closed shapes have an interior — a segment, a line, a ray, and a polyline ignore fill and report it as a warning.

A self-intersecting polygon uses the even-odd rule, so a bow-tie fills its two lobes. A polygon with fewer than three vertices, a line or ray whose two points coincide, a negative radius, and a coordinate that is not a number are all reported as warnings; the rest of the plot keeps drawing.

Configure the plot#

Use @config for axes, grids, viewport, legend, interaction, render mode, and evaluator. The complete option reference lists the types and allowed values.

For a second Y axis, assign series[0].yAxis=right and set rightYAxis.min and rightYAxis.max as needed.

Domains and errors#

Singularities, gaps, and non-real values can leave breaks in a curve. Choose a useful domain, and inspect the errors and warnings before you interpret the graph.

Auto-fit needs finite sample data, so lock the viewport when an animation should not change the axes. A logarithmic scale needs a suitable positive domain.

Plot settings and interaction · Animating plots · Editable plot reference