From 4371b711a5f40c9f2da6f0acfbbefa732e97ffbe Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Thu, 3 Apr 2025 11:38:34 +0200 Subject: [PATCH] b plot fix plot --- UI/UI_plot.cpp | 6 ++++++ UI/UI_plot.hpp | 1 + client/simulator_base.cpp | 21 +++++++++++++++++---- server/simulators/test_sim.cpp | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/UI/UI_plot.cpp b/UI/UI_plot.cpp index 47f67a4..c5568f7 100644 --- a/UI/UI_plot.cpp +++ b/UI/UI_plot.cpp @@ -35,6 +35,12 @@ std::string UI_plot::y_label() const return m_y_label; } +void UI_plot::add_value(double y) +{ + m_x_vals.push_back((double)m_x_vals.size()); + m_y_vals.push_back(y); +} + void UI_plot::add_value(double x, double y) { m_x_vals.push_back(x); diff --git a/UI/UI_plot.hpp b/UI/UI_plot.hpp index a0795b9..edec685 100644 --- a/UI/UI_plot.hpp +++ b/UI/UI_plot.hpp @@ -20,6 +20,7 @@ class UI_plot : public UI_item bool x_label_enabled() const; void set_y_label_enabled(bool enabled); bool y_label_enabled() const; + void add_value(double y); void add_value(double x, double y); void clean_vals(); diff --git a/client/simulator_base.cpp b/client/simulator_base.cpp index 7cd67cb..8f52514 100644 --- a/client/simulator_base.cpp +++ b/client/simulator_base.cpp @@ -535,10 +535,13 @@ void Simulator_base::process_ui_plot(json &uiItem) } QString text = QString::fromStdString(uiItem["text"]); + QColor bg_color = QColor(QString::fromStdString(uiItem["bg_color"])); + QColor color = QColor(QString::fromStdString(uiItem["fg_color"])); QString x_label = QString::fromStdString(uiItem["x_label"]); QString y_label = QString::fromStdString(uiItem["y_label"]); + std::vector x_vals = (std::vector)uiItem.at("x_vals"); - std::vector y_vals = (std::vector)uiItem.at("x_vals"); + std::vector y_vals = (std::vector)uiItem.at("y_vals"); if (text != plot->title().text()) { @@ -555,9 +558,19 @@ void Simulator_base::process_ui_plot(json &uiItem) plot->setAxisTitle(QwtAxis::YLeft, y_label); } - plot->curve()->setRawSamples(x_vals.data(), y_vals.data(), x_vals.capacity()); - plot->setAxisScale(QwtAxis::XBottom, x_vals[x_vals.capacity() - 1], x_vals[0]); - // plot_time[0], plot_time[api.get_plot_size() - 1] ); + if (color != plot->curve()->pen().color()) + { + plot->curve()->setPen(QPen(color)); + } + + if (color == QColor(0x83, 0x91, 0x92)) + { + plot->curve()->setPen(QPen(Qt::red)); + } + + plot->curve()->setSamples(x_vals.data(), y_vals.data(), x_vals.size()); + if (x_vals.size() > 0) + plot->setAxisScale(QwtAxis::XBottom, x_vals[0], x_vals[x_vals.size() - 1]); plot->replot(); } diff --git a/server/simulators/test_sim.cpp b/server/simulators/test_sim.cpp index f8a4278..0b12500 100644 --- a/server/simulators/test_sim.cpp +++ b/server/simulators/test_sim.cpp @@ -68,7 +68,7 @@ void Test_Sim::slider_changed(UI_slider *id, double value) this->m_label.set_text(std::to_string(value)); this->m_dial.set_value(value); this->m_thermo.set_value(value); - this->m_plot.add_value(value, value); + this->m_plot.add_value(value); return; } }