diff --git a/mxgui/level2/Plot/Plot.cpp b/mxgui/level2/Plot/Plot.cpp index c030169c01d4dbe96a4a1e66ce6f7b1d0ff3901f..43676210530c2d9b4a5c8eb7cf379d60f13fbf9b 100644 --- a/mxgui/level2/Plot/Plot.cpp +++ b/mxgui/level2/Plot/Plot.cpp @@ -11,8 +11,7 @@ namespace mxgui { Plot::Plot(Point upperLeft, Point lowerRight) - : upperLeft(upperLeft), lowerRight(lowerRight), - buffer(lowerRight.x() - upperLeft.x()) + : upperLeft(upperLeft), lowerRight(lowerRight) { // ... } @@ -23,7 +22,17 @@ void Plot::setYScale(float min, float max) yMax = max; } -void Plot::addDataPoint(float y) { buffer.put(y); } +void Plot::addDataPoint(float y, int index, Color color) +{ + if (buffers.count(index) == 0) + { + buffers.emplace(index, new Boardcore::ResizableCircularBuffer<float>{ + lowerRight.x() - upperLeft.x()}); + } + + buffers[index]->put(y); + colors[index] = color; +} void Plot::draw(DrawingContext& dc) { @@ -63,18 +72,22 @@ void Plot::draw(DrawingContext& dc) } // Draw data points - for (size_t i = 1; i < buffer.count(); i++) + for (auto buffer : buffers) { - short int x1 = - upperLeft.x() + buffer.getSize() - buffer.count() + i - 1; - short int y1 = (buffer.get(i - 1) - yMin) / (yMax - yMin) * - (lowerRight.y() - upperLeft.y()); - - short int x2 = upperLeft.x() + buffer.getSize() - buffer.count() + i; - short int y2 = (buffer.get(i) - yMin) / (yMax - yMin) * - (lowerRight.y() - upperLeft.y()); - - dc.line({x1, y1}, {x2, y2}, white); + for (size_t i = 1; i < buffer.second->count(); i++) + { + short int x1 = upperLeft.x() + buffer.second->getSize() - + buffer.second->count() + i - 1; + short int y1 = (buffer.second->get(i - 1) - yMin) / (yMax - yMin) * + (lowerRight.y() - upperLeft.y()); + + short int x2 = upperLeft.x() + buffer.second->getSize() - + buffer.second->count() + i; + short int y2 = (buffer.second->get(i) - yMin) / (yMax - yMin) * + (lowerRight.y() - upperLeft.y()); + + dc.line({x1, y1}, {x2, y2}, colors[buffer.first]); + } } } diff --git a/mxgui/level2/Plot/Plot.h b/mxgui/level2/Plot/Plot.h index 56ca7dad1e8f92e23c7fe5908ddc8361f600f6ec..2d8bb858c63a7e67e55ccfd7ca255b2ab9493998 100644 --- a/mxgui/level2/Plot/Plot.h +++ b/mxgui/level2/Plot/Plot.h @@ -3,6 +3,7 @@ #include <display.h> #include <utils/collections/ResizableCircularBuffer.h> +#include <map> #include <string> #include <vector> @@ -16,7 +17,7 @@ public: void setYScale(float min, float max); - void addDataPoint(float y); + void addDataPoint(float y, int index, Color color); void draw(DrawingContext& dc); @@ -30,8 +31,9 @@ private: float yMin = 0; float yMax = 1; - // Data buffer - Boardcore::ResizableCircularBuffer<float> buffer; + // Data buffers + std::map<int, Boardcore::ResizableCircularBuffer<float>*> buffers; + std::map<int, Color> colors; bool first = true; };