v2026.11.2
All Bundles
Bundle

The SDL2 backend of System.Plot: it draws the same PlotScene the SVG writer does, to a window you can zoom, pan and hover, or to a PNG file. Compile with -lib plot_sdl,plot,sdl2,gen_collect. Saving a PNG needs no window and no display; a window needs one. Not available in the web playground. Design: docs/PLOT_DESIGN.md.

PlotWindow

An interactive window over a Figure: the mouse wheel zooms about the pointer, dragging with the left button pans, hovering reads out the data position, R resets the view, Escape or closing the window ends it. Zoom and pan change the axes' limits and the scene is rebuilt, so ticks and labels stay crisp.

Example

fig := Figure->New(900, 600);
fig->GetAxes()->Scatter("pts", xs, ys);
PlotWindow->New(fig, "pts")->Run();

Operations

Close #

Closes the window and frees what Open made.

method : public : Close() ~ Nil

GetCloseType #

The event type that ends Run when it is pushed (Event->SetUser then Push), so another thread, or a test, can close the window.

method : public : GetCloseType() ~ Int

Return

TypeDescription
Inta user event type

GetNotice #

The last message from a frame that could not be drawn as asked, empty when the last frame was fine.

method : public : GetNotice() ~ String

Return

TypeDescription
Stringthe text

GetReadout #

The last hover readout.

method : public : GetReadout() ~ String

Return

TypeDescription
Stringthe text, empty when the pointer is outside every plot

Handle #

Handles one SDL event: wheel zoom, drag pan, hover, keys, close.

method : public : Handle(event:Event) ~ Nil

Parameters

NameTypeDescription
eventEventthe event just polled

IsRunning #

Whether the loop is running.

method : public : IsRunning() ~ Bool

Return

TypeDescription
Booltrue while Run is looping

New # constructor

Constructor; the window opens in Run.

New(figure:Figure, title:String)

Parameters

NameTypeDescription
figureFigurewhat to show
titleStringthe window title

New # constructor

Constructor

New(figure:Figure, title:String, visible:Bool)

Parameters

NameTypeDescription
figureFigurewhat to show
titleStringthe window title
visibleBoolfalse opens the window hidden, for tests

OnKey #

Handles a key: Escape ends the loop, R resets every axes to the data's range.

method : public : OnKey(scancode:Int) ~ Nil

Parameters

NameTypeDescription
scancodeIntthe key's scancode

OnMotion #

Handles the pointer moving: a drag with the left button down pans, otherwise the data position is read out.

method : public : OnMotion(x:Int, y:Int, dx:Int, dy:Int, left_down:Bool) ~ Nil

Parameters

NameTypeDescription
xIntpixel x
yIntpixel y
dxIntpixels moved right since the last event
dyIntpixels moved down since the last event
left_downBoolwhether the left button is held

OnWheel #

Zooms the axes under a pixel.

method : public : OnWheel(x:Int, y:Int, notches:Int) ~ Nil

Parameters

NameTypeDescription
xIntpixel x
yIntpixel y
notchesIntwheel movement, positive zooms in

Open #

Creates the window and renderer without running the loop.

method : public : Open() ~ Bool

Return

TypeDescription
Booltrue when opened

RenderFrame #

Draws one frame: the scene, then the hover readout.

method : public : RenderFrame() ~ Nil

ResetView #

Returns every axes to the view the figure chose: its own limits where it set some (a ROC plot's -0.02 .. 1.02), the range of the data where it did not.

method : public : ResetView() ~ Nil

Run #

Opens the window and runs until it is closed.

method : public : Run() ~ Bool

Return

TypeDescription
Boolfalse when the window could not be opened (no display, or SDL missing)