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
- New
- Close
- GetCloseType
- GetNotice
- GetReadout
- Handle
- IsRunning
- OnKey
- OnMotion
- OnWheel
- Open
- RenderFrame
- ResetView
- Run
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() ~ IntReturn
| Type | Description |
|---|---|
| Int | a 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() ~ StringReturn
| Type | Description |
|---|---|
| String | the text |
GetReadout #
The last hover readout.
method : public : GetReadout() ~ StringReturn
| Type | Description |
|---|---|
| String | the 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) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| event | Event | the event just polled |
IsRunning #
Whether the loop is running.
method : public : IsRunning() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true while Run is looping |
New # constructor
Constructor; the window opens in Run.
New(figure:Figure, title:String)Parameters
| Name | Type | Description |
|---|---|---|
| figure | Figure | what to show |
| title | String | the window title |
New # constructor
Constructor
New(figure:Figure, title:String, visible:Bool)Parameters
| Name | Type | Description |
|---|---|---|
| figure | Figure | what to show |
| title | String | the window title |
| visible | Bool | false 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) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| scancode | Int | the 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) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| x | Int | pixel x |
| y | Int | pixel y |
| dx | Int | pixels moved right since the last event |
| dy | Int | pixels moved down since the last event |
| left_down | Bool | whether the left button is held |
OnWheel #
Zooms the axes under a pixel.
method : public : OnWheel(x:Int, y:Int, notches:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| x | Int | pixel x |
| y | Int | pixel y |
| notches | Int | wheel movement, positive zooms in |
Open #
Creates the window and renderer without running the loop.
method : public : Open() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true when opened |
RenderFrame #
Draws one frame: the scene, then the hover readout.
method : public : RenderFrame() ~ NilResetView #
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