Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

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 with type = "line".
  • Plot.points(spec: PointsSpec) -> PointsSpec — tag a spec with type = "points".
  • Plot.heatmap(spec: HeatmapSpec) -> HeatmapSpec — tag a spec with type = "heatmap".
  • Plot.boxPlot(spec: BoxPlotSpec) -> BoxPlotSpec — tag a spec with type = "boxPlot".
  • Plot.bezierLine(p0, p1, p2, p3, samples?, opts?) -> LineSpec — sample a cubic bezier into a LineSpec.
  • __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 same id across renders preserves the viewport.
  • linkGroup syncs pan/zoom across multiple plots — set linkAxis / linkCursor per axis to opt each plot in.
  • Shift+Drag triggers boxed-zoom marquee selection; non-shift drag pans.
  • xTickFormat / yTickFormat accept function(v: number) -> string to override the default D3 nice-tick labelling.
  • Heatmap cols defines column count — rows are inferred from #values / cols.