Add some legends to C++ tool output.
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 24 Aug 2013 17:41:29 +0000 (20:41 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Mon, 9 Sep 2013 11:42:37 +0000 (13:42 +0200)
Mostly add the selection name as legend for those plots where there is
one or two columns per selection.  The complex legend logic from g_bond
is still missing, since it is not clear how to best represent a generic
selection position as a short string.

Change-Id: I41b3b62a2e40f024e8c9c0b5be50e573881b5d7a

src/gromacs/analysisdata/modules/plot.cpp
src/gromacs/analysisdata/modules/plot.h
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/distance.cpp
src/gromacs/trajectoryanalysis/modules/select.cpp

index c716bed0000ff8d87b3b918cbacad7df32433b42..7b07ae11674328257a5d3cf82d937c4123bcc908 100644 (file)
@@ -273,6 +273,13 @@ AbstractPlotModule::appendLegend(const char *setname)
 }
 
 
+void
+AbstractPlotModule::appendLegend(const std::string &setname)
+{
+    impl_->legend_.push_back(setname);
+}
+
+
 void
 AbstractPlotModule::setXFormat(int width, int precision, char format)
 {
index 668f041680da00c6631d956a22c818b3b00b8244..023d095055e0e1de459eb8885d5d2e70b6301fc6 100644 (file)
@@ -210,6 +210,8 @@ class AbstractPlotModule : public AnalysisDataModuleSerial
          * together.
          */
         void appendLegend(const char *setname);
+        //! \copydoc appendLegend(const char *)
+        void appendLegend(const std::string &setname);
         /*! \brief
          * Set field width and precision for X value output.
          */
index b40188071387ef3fc34b47b418e1c3a23187da51..ff53dfa5ac1c4a331334703dbc2d18d37749b962 100644 (file)
@@ -319,7 +319,12 @@ Angle::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plotm->setTitle("Average angle");
         plotm->setXAxisIsTime();
         plotm->setYLabel("Angle (degrees)");
-        // TODO: Add legends
+        // TODO: Consider adding information about the second selection,
+        // and/or a subtitle describing what kind of angle this is.
+        for (size_t g = 0; g < sel1_.size(); ++g)
+        {
+            plotm->appendLegend(sel1_[g].name());
+        }
         averageModule_->addModule(plotm);
     }
 
@@ -343,7 +348,12 @@ Angle::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plotm->setTitle("Angle histogram");
         plotm->setXLabel("Angle (degrees)");
         plotm->setYLabel("Probability");
-        // TODO: Add legends
+        // TODO: Consider adding information about the second selection,
+        // and/or a subtitle describing what kind of angle this is.
+        for (size_t g = 0; g < sel1_.size(); ++g)
+        {
+            plotm->appendLegend(sel1_[g].name());
+        }
         histogramModule_->averager().addModule(plotm);
     }
 }
index de2c2fae1304521f62b3aea089c38691158c327f..adf7bb6e8141aef14cf47fad8c593be0e15471ec 100644 (file)
@@ -211,7 +211,10 @@ Distance::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plotm->setTitle("Average distance");
         plotm->setXAxisIsTime();
         plotm->setYLabel("Distance (nm)");
-        // TODO: Add legends
+        for (size_t g = 0; g < sel_.size(); ++g)
+        {
+            plotm->appendLegend(sel_[g].name());
+        }
         averageModule_->addModule(plotm);
     }
 
@@ -247,7 +250,10 @@ Distance::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plotm->setTitle("Distance histogram");
         plotm->setXLabel("Distance (nm)");
         plotm->setYLabel("Probability");
-        // TODO: Add legends
+        for (size_t g = 0; g < sel_.size(); ++g)
+        {
+            plotm->appendLegend(sel_[g].name());
+        }
         histogramModule_->averager().addModule(plotm);
     }
 
@@ -260,7 +266,11 @@ Distance::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plotm->setTitle("Statistics for individual distances");
         plotm->setXLabel("Distance index");
         plotm->setYLabel("Average/standard deviation (nm)");
-        // TODO: Add legends
+        for (size_t g = 0; g < sel_.size(); ++g)
+        {
+            plotm->appendLegend(std::string(sel_[g].name()) + " avg");
+            plotm->appendLegend(std::string(sel_[g].name()) + " std.dev.");
+        }
         // TODO: Consider whether this output format is the best possible.
         allStatsModule_->addModule(plotm);
     }
index e088c46d81017f8fcdef88820c989e82358ce69c..ef211292b427a9fbc56787f0e893cb22c86e58ce 100644 (file)
@@ -434,6 +434,10 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plot->setTitle("Selection size");
         plot->setXAxisIsTime();
         plot->setYLabel("Number");
+        for (size_t g = 0; g < sel_.size(); ++g)
+        {
+            plot->appendLegend(sel_[g].name());
+        }
         sdata_.addModule(plot);
     }
 
@@ -447,6 +451,10 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plot->setXAxisIsTime();
         plot->setYLabel("Fraction");
         plot->setYFormat(6, 4);
+        for (size_t g = 0; g < sel_.size(); ++g)
+        {
+            plot->appendLegend(sel_[g].name());
+        }
         cdata_.addModule(plot);
     }
 
@@ -486,6 +494,7 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plot->setXAxisIsTime();
         plot->setYLabel("Occupancy");
         plot->setYFormat(1, 0);
+        // TODO: Add legend? (there can be massive amount of columns)
         mdata_.addModule(plot);
     }
     if (!fnOccupancy_.empty())
@@ -496,6 +505,10 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plot->setTitle("Fraction of time selection matches");
         plot->setXLabel("Selected position");
         plot->setYLabel("Occupied fraction");
+        for (size_t g = 0; g < sel_.size(); ++g)
+        {
+            plot->appendLegend(sel_[g].name());
+        }
         occupancyModule_->addModule(plot);
     }
     if (!fnLifetime_.empty())
@@ -506,6 +519,10 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
         plot->setTitle("Lifetime histogram");
         plot->setXAxisIsTime();
         plot->setYLabel("Number of occurrences");
+        for (size_t g = 0; g < sel_.size(); ++g)
+        {
+            plot->appendLegend(sel_[g].name());
+        }
         lifetimeModule_->addModule(plot);
     }