class mrpt::imgui::CImGuiPlotPanel
Overview
A 2D plot (ImPlot) with named data series, for live or static data.
Series can be appended to point by point (addPoint(), e.g. a live signal, optionally shown over a rolling time window), or replaced as a whole (setSeries()). Series may carry a shaded band (e.g. a confidence interval). Long series are decimated for drawing, preserving their extremes. A toolbar offers pause (to inspect), autoscale, and exporting the data to CSV.
mrpt::imgui::CImGuiPlotPanel plot; plot.rollingSpan = 10.0; // show the last 10 s plot.addPoint("speed", t, v); // In a window: plot.render("Speed");
#include <mrpt/imgui/CImGuiPlotPanel.h> class CImGuiPlotPanel { public: // enums enum Style; // structs struct Series; // fields size_t maxPoints = 200000; double rollingSpan = 0; std::string xLabel; std::string yLabel; bool showLegend = true; bool autoscale = true; bool paused = false; bool equalAxes = false; bool showToolbar = true; std::function<void()> onPlotOverlay; // construction CImGuiPlotPanel(); // methods void addPoint(const std::string& series, double x, double y); void setSeries(const std::string& series, std::vector<double> x, std::vector<double> y); void setBand( const std::string& series, std::vector<double> x, std::vector<double> low, std::vector<double> high ); Series* series(const std::string& name); const Series* series(const std::string& name) const; Series& seriesOrCreate(const std::string& name); const std::vector<Series>& allSeries() const; void clear(); void clearData(); void removeSeries(const std::string& name); void render(const char* title, float height = 0); std::string toCSV() const; static std::vector<size_t> decimateMinMax( const std::vector<double>& x, const std::vector<double>& y, double xMin, double xMax, size_t buckets ); };
Fields
size_t maxPoints = 200000
Maximum points kept per series appended with addPoint().
double rollingSpan = 0
If > 0, the x axis follows the last rollingSpan units of data.
bool paused = false
Freezes the view (data keeps being appended).
bool equalAxes = false
Same scale in both axes (e.g.
for 2D maps).
std::function<void()> onPlotOverlay
Called inside the plot (between ImPlot::BeginPlot()/EndPlot()) to draw extra items, e.g.
ellipses or annotations.
Methods
void addPoint(const std::string& series, double x, double y)
Appends a point to a series (created if needed).
Old points are dropped beyond maxPoints, and beyond twice rollingSpan, if set.
void setSeries( const std::string& series, std::vector<double> x, std::vector<double> y )
Replaces the data of a series (created if needed).
void setBand( const std::string& series, std::vector<double> x, std::vector<double> low, std::vector<double> high )
Sets a shaded band [low, high] along a series (created if needed).
If x is given, it also replaces the series x values.
Series* series(const std::string& name)
The series with that name, or nullptr.
Series& seriesOrCreate(const std::string& name)
The series with that name, created (empty) if it does not exist.
void render(const char* title, float height = 0)
Draws the toolbar and the plot in the current window.
A height <= 0 uses the available height.
std::string toCSV() const
Data as CSV: one x,y column pair per series, with a header row.
static std::vector<size_t> decimateMinMax( const std::vector<double>& x, const std::vector<double>& y, double xMin, double xMax, size_t buckets )
Indices of the points of (x,y) (x sorted ascending) to draw, at most about 2*buckets: for each of buckets equal x intervals within [xMin, xMax], its minimum and maximum y; plus the points just outside the interval, so lines reach the plot edges.
All indices, if few enough.