Robowflex  v0.1
Making MoveIt Easy
robowflex::darts::LinePlotElement Class Reference

Line plot element. Displays an updated line graph of data. More...

#include <gui.h>

+ Inheritance diagram for robowflex::darts::LinePlotElement:

Public Member Functions

void addPoint (float x)
 Add a point to the plot data. More...
 
void render () const override
 Render method. Renders IMGUI contents. More...
 

Public Attributes

std::string id {"##" + generateUUID()}
 Unique ID. More...
 
std::string label {""}
 Plot Label. More...
 
std::string units {""}
 Plot Units. More...
 
bool show_min {false}
 Display minimum value under plot. More...
 
bool show_max {false}
 Display maximum value under plot. More...
 
bool show_avg {false}
 Display average value under plot. More...
 
bool recent {true}
 Display most recent value on plot. More...
 
std::size_t max_size {100}
 Maximum size of plot data. More...
 
Eigen::Vector3d color {1., 1., 1.}
 Color of plot. More...
 

Private Member Functions

float average () const
 Compute the average over the data. More...
 
float minimum () const
 Compute the minimum over the data. More...
 
float maximum () const
 Compute the maximum over the data. More...
 

Private Attributes

std::size_t index {0}
 Index in data. More...
 
std::size_t total_elements {0}
 Total elements inserted in data. More...
 
std::vector< float > elements
 All data points. More...
 
float latest
 Last input data point. More...
 

Detailed Description

Line plot element. Displays an updated line graph of data.

Definition at line 325 of file gui.h.

Member Function Documentation

◆ addPoint()

void LinePlotElement::addPoint ( float  x)

Add a point to the plot data.

Parameters
[in]xPoint to add.

Definition at line 323 of file gui.cpp.

324 {
326  if (index >= max_size)
327  index = 0;
328 
329  if (total_elements > max_size)
331 
332  latest = elements[index++] = x;
333  index = index % max_size;
334 
335  if (total_elements < max_size)
336  total_elements++;
337 }
std::vector< float > elements
All data points.
Definition: gui.h:347
std::size_t index
Index in data.
Definition: gui.h:345
float latest
Last input data point.
Definition: gui.h:348
std::size_t total_elements
Total elements inserted in data.
Definition: gui.h:346
std::size_t max_size
Maximum size of plot data.
Definition: gui.h:335
T resize(T... args)

◆ average()

float LinePlotElement::average ( ) const
private

Compute the average over the data.

Returns
The average.

Definition at line 298 of file gui.cpp.

299 {
300  float avg = 0.;
301  for (std::size_t i = 0; i < total_elements; ++i)
302  avg += elements[i];
303  avg /= (float)max_size;
304  return avg;
305 }

◆ maximum()

float LinePlotElement::maximum ( ) const
private

Compute the maximum over the data.

Returns
The maximum.

Definition at line 315 of file gui.cpp.

316 {
317  float max = 0.;
318  for (std::size_t i = 0; i < total_elements; ++i)
319  max = (max < elements[i]) ? elements[i] : max;
320  return max;
321 }
T max(T... args)

◆ minimum()

float LinePlotElement::minimum ( ) const
private

Compute the minimum over the data.

Returns
The minimum.

Definition at line 307 of file gui.cpp.

308 {
310  for (std::size_t i = 0; i < total_elements; ++i)
311  min = (min > elements[i]) ? elements[i] : min;
312  return min;
313 }
T min(T... args)

◆ render()

void LinePlotElement::render ( ) const
overridevirtual

Render method. Renders IMGUI contents.

Implements robowflex::darts::ImGuiElement.

Definition at line 339 of file gui.cpp.

340 {
341  ImGui::PushID(id.c_str());
342  ImGui::PushStyleColor(ImGuiCol_PlotLines,
343  (ImVec4)ImColor((float)color[0], (float)color[1], (float)color[2]));
344 
345  char overlay[64] = "N/A";
346  if (total_elements)
347  sprintf(overlay, "%.3f %s", latest, units.c_str());
348 
349  ImGui::PlotLines(label.c_str(), elements.data(), total_elements, index, overlay);
350 
351  ImGui::PopStyleColor(1);
352  ImGui::PopID();
353 
354  if (show_min)
355  ImGui::Text("min: %.3f %s", minimum(), units.c_str());
356  if (show_avg)
357  ImGui::Text("avg: %.3f %s", average(), units.c_str());
358  if (show_max)
359  ImGui::Text("max: %.3f %s", maximum(), units.c_str());
360 }
T c_str(T... args)
float minimum() const
Compute the minimum over the data.
Definition: gui.cpp:307
bool show_avg
Display average value under plot.
Definition: gui.h:333
std::string units
Plot Units.
Definition: gui.h:330
Eigen::Vector3d color
Color of plot.
Definition: gui.h:336
float average() const
Compute the average over the data.
Definition: gui.cpp:298
float maximum() const
Compute the maximum over the data.
Definition: gui.cpp:315
bool show_min
Display minimum value under plot.
Definition: gui.h:331
std::string label
Plot Label.
Definition: gui.h:329
bool show_max
Display maximum value under plot.
Definition: gui.h:332
T data(T... args)
T sprintf(T... args)

Member Data Documentation

◆ color

Eigen::Vector3d robowflex::darts::LinePlotElement::color {1., 1., 1.}

Color of plot.

Definition at line 336 of file gui.h.

◆ elements

std::vector<float> robowflex::darts::LinePlotElement::elements
private

All data points.

Definition at line 347 of file gui.h.

◆ id

std::string robowflex::darts::LinePlotElement::id {"##" + generateUUID()}

Unique ID.

Definition at line 328 of file gui.h.

◆ index

std::size_t robowflex::darts::LinePlotElement::index {0}
private

Index in data.

Definition at line 345 of file gui.h.

◆ label

std::string robowflex::darts::LinePlotElement::label {""}

Plot Label.

Definition at line 329 of file gui.h.

◆ latest

float robowflex::darts::LinePlotElement::latest
private

Last input data point.

Definition at line 348 of file gui.h.

◆ max_size

std::size_t robowflex::darts::LinePlotElement::max_size {100}

Maximum size of plot data.

Definition at line 335 of file gui.h.

◆ recent

bool robowflex::darts::LinePlotElement::recent {true}

Display most recent value on plot.

Definition at line 334 of file gui.h.

◆ show_avg

bool robowflex::darts::LinePlotElement::show_avg {false}

Display average value under plot.

Definition at line 333 of file gui.h.

◆ show_max

bool robowflex::darts::LinePlotElement::show_max {false}

Display maximum value under plot.

Definition at line 332 of file gui.h.

◆ show_min

bool robowflex::darts::LinePlotElement::show_min {false}

Display minimum value under plot.

Definition at line 331 of file gui.h.

◆ total_elements

std::size_t robowflex::darts::LinePlotElement::total_elements {0}
private

Total elements inserted in data.

Definition at line 346 of file gui.h.

◆ units

std::string robowflex::darts::LinePlotElement::units {""}

Plot Units.

Definition at line 330 of file gui.h.


The documentation for this class was generated from the following files: