Builtin Library
README.md
plot
Plot is a Luau builder over canvas interaction props (onDrag,
onScroll, onPointerMove). Rebuilds the pan/zoom/legend/crosshair
UX from canvas primitives so there is no egui_plot dependency. The
module returns a callable table — Z.plot(id, spec, opts) builds the
widget, while .line / .points / .heatmap / .boxPlot /
.bezierLine are element helpers that tag specs with the right type.
Exports
Plot.line(spec: LineSpec) -> LineSpec— tag a spec withtype = "line".Plot.points(spec: PointsSpec) -> PointsSpec— tag a spec withtype = "points".Plot.heatmap(spec: HeatmapSpec) -> HeatmapSpec— tag a spec withtype = "heatmap".Plot.boxPlot(spec: BoxPlotSpec) -> BoxPlotSpec— tag a spec withtype = "boxPlot".Plot.bezierLine(p0, p1, p2, p3, samples?, opts?) -> LineSpec— sample a cubic bezier into aLineSpec.__call(id, plotSpec, opts) -> any— calling the table builds the plot widget itself.
Types:
Point = { number }(2-element)LineSpec = { type?, id?, name?, color?, points?, y?, width?, gradient?, fillY?, fillColor?, lineStyle? }PointsSpec = { type?, id?, name?, color?, points?, shape?, radius?, filled? }HeatmapSpec = { type?, id?, name?, values?, cols?, palette?, showLabels? }BoxPlotSpec = { type?, id?, name?, boxes?, horizontal? }PlotOptions = { showAxes?, showGrid?, showCrosshair?, invertX?, invertY?, legend?, showCoordinates?, coordinatesCorner?, allowZoom?, allowDrag?, allowScroll?, linkGroup?, linkAxis?, linkCursor?, xTickFormat?, yTickFormat? }PlotSpec = { options?: PlotOptions, elements?: { any } }PlotOpts = { width?, height?, style?, background?, classes?, label?, app? }
Usage
local Plot = require("@builtin::modules.zui.widget.plot")
local widget = Plot("chart-1", {
options = { showGrid = true, legend = { show = true } },
elements = {
Plot.line({ points = { { 0, 0 }, { 1, 0.5 }, { 2, 0.2 } }, name = "A" }),
Plot.points({ points = { { 1, 0.5 } }, radius = 6 }),
},
}, { width = 480, height = 240 })
Notes
- Pan/zoom state lives in
ui.widgetState(id, ...); the sameidacross renders preserves the viewport. linkGroupsyncs pan/zoom across multiple plots — setlinkAxis/linkCursorper axis to opt each plot in.- Shift+Drag triggers boxed-zoom marquee selection; non-shift drag pans.
xTickFormat/yTickFormatacceptfunction(v: number) -> stringto override the default D3 nice-tick labelling.- Heatmap
colsdefines column count — rows are inferred from#values / cols.