From 8066b700554d83bbff969e87fd1e9dcff4b78854 Mon Sep 17 00:00:00 2001 From: Manuel Valch Date: Sat, 15 Jun 2024 22:57:12 +0200 Subject: [PATCH] Use PlotGroups explicitly If this commit is applied then plotJuggler groups will be used instead of series so that if a topic is keyed then it is easy to add its instance to the group. Stored all groups pointer into an unordered map so that I can find back the group based on topic names. Note that I have used default separator "/", might be an issue if it changes. Issue: [https://github.com/eProsima/fastdds-visualizer-plugin/issues/56] Signed-off-by: Manuel Valch --- .../datastreamer/FastDdsDataStreamer.cpp | 28 ++++++++++++++++--- .../datastreamer/FastDdsDataStreamer.hpp | 2 ++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.cpp b/plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.cpp index 7513ea6..a3194f1 100644 --- a/plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.cpp +++ b/plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.cpp @@ -245,18 +245,38 @@ bool FastDdsDataStreamer::timeSeriesCreation() std::vector numeric_series = fastdds_handler_.numeric_data_series_names(); for (const auto& series : numeric_series) { + std::size_t char_id = series.find_first_of("/"); + std::string topic_name = series.substr(0U, char_id); + std::string series_name = series.substr(char_id); + + if (plot_groups_.end() == plot_groups_.find(topic_name)) + { + // Create plotjuggler group + DEBUG("Creating plotjuggler group: " << topic_name); + plot_groups_.insert({topic_name, std::make_shared(topic_name)}); + } // Create a series - DEBUG("Creating numeric series: " << series); - dataMap().addNumeric(series); + DEBUG("Creating numeric series: " << series_name); + dataMap().addNumeric(series_name, plot_groups_.at(topic_name)); } // STRING std::vector string_series = fastdds_handler_.string_data_series_names(); for (const auto& series : string_series) { + std::size_t char_id = series.find_first_of("/"); + std::string topic_name = series.substr(0U, char_id); + std::string series_name = series.substr(char_id); + + if (plot_groups_.end() == plot_groups_.find(topic_name)) + { + // Create plotjuggler group + DEBUG("Creating plotjuggler group: " << topic_name); + plot_groups_.insert({topic_name, std::make_shared(topic_name)}); + } // Create a series - DEBUG("Creating string series: " << series); - dataMap().addStringSeries(series); + DEBUG("Creating string series: " << series_name); + dataMap().addStringSeries(series_name, plot_groups_.at(topic_name)); } return true; } diff --git a/plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.hpp b/plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.hpp index 2bb08ba..8b8b791 100644 --- a/plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.hpp +++ b/plugins/datastreamer_plugin/datastreamer/FastDdsDataStreamer.hpp @@ -148,6 +148,8 @@ class FastDdsDataStreamer : bool running_; constexpr static const char* CONFIGURATION_SETTINGS_PREFIX_ = "FastDDSVisualizerPlugin"; + + std::unordered_map> plot_groups_; }; } /* namespace datastreamer */