From 6bfbae58bd4f3f4572f90e026250670ca5d65f91 Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.priv>
Date: Thu, 6 Jun 2019 18:36:41 +0200
Subject: [PATCH] v1.2.16.18 CLEAN: new management for layout in
 plot.OutputsModel fun

---
 DESCRIPTION           |  2 +-
 NEWS.rmd              |  2 +-
 R/plot.OutputsModel.R | 48 ++++++++++++++++++++-----------------------
 3 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 1bfb2f09..ed6ba35a 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
 Package: airGR
 Type: Package
 Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
-Version: 1.2.16.17
+Version: 1.2.16.18
 Date: 2019-06-06
 Authors@R: c(
   person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
diff --git a/NEWS.rmd b/NEWS.rmd
index f9d4f8aa..5410c615 100644
--- a/NEWS.rmd
+++ b/NEWS.rmd
@@ -14,7 +14,7 @@ output:
 
 
 
-### 1.2.16.17 Release Notes (2019-06-06)
+### 1.2.16.18 Release Notes (2019-06-06)
 
 
 #### New features
diff --git a/R/plot.OutputsModel.R b/R/plot.OutputsModel.R
index 802a8162..c9f8459d 100644
--- a/R/plot.OutputsModel.R
+++ b/R/plot.OutputsModel.R
@@ -250,45 +250,41 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
     if (is.null(LayoutMat)) {     
       matlayout <- NULL
       iPlot <- 0
+      iHght <- NULL
       
-      Sum1 <- sum(c(BOOLPLOT_Precip, BOOLPLOT_SnowPack, BOOLPLOT_Flows))
-      Sum2 <- sum(c(BOOLPLOT_Regime, BOOLPLOT_CumFreq, BOOLPLOT_CorQQ))
-      if (BOOLPLOT_Precip) {
-        matlayout <- rbind(matlayout, c(iPlot + 1, iPlot + 1, iPlot + 1))
-        iPlot <- iPlot + 1
-      }
-      if (BOOLPLOT_PotEvap) {
-        matlayout <- rbind(matlayout, c(iPlot + 1, iPlot + 1, iPlot + 1), c(iPlot + 1, iPlot + 1, iPlot + 1))
-        iPlot <- iPlot + 1
-      } 
-      if (BOOLPLOT_Temp) {
-        matlayout <- rbind(matlayout, c(iPlot + 1, iPlot + 1, iPlot + 1), c(iPlot + 1, iPlot + 1, iPlot + 1))
-        iPlot <- iPlot + 1
-      }      
-      if (BOOLPLOT_SnowPack) {
-        matlayout <- rbind(matlayout, c(iPlot + 1, iPlot + 1, iPlot + 1), c(iPlot + 1, iPlot + 1, iPlot + 1))
+      listBOOLPLOT1 <- c(Precip = BOOLPLOT_Precip, PotEvap  = BOOLPLOT_PotEvap,
+                         Temp   = BOOLPLOT_Temp  , SnowPack = BOOLPLOT_SnowPack,
+                         Flows  = BOOLPLOT_Flows , Error    = BOOLPLOT_Error)
+      listBOOLPLOT2 <- c(Regime = BOOLPLOT_Regime, CumFreq  = BOOLPLOT_CumFreq,
+                         CorQQ = BOOLPLOT_CorQQ)
+      Sum1 <- sum(listBOOLPLOT1)
+      Sum2 <- sum(listBOOLPLOT2)
+      
+      for (k in seq_len(Sum1)) {
+        matlayout <- rbind(matlayout, iPlot + c(1, 1, 1))
         iPlot <- iPlot + 1
+        iHght <- c(iHght, 0.7)
       }
-      if (BOOLPLOT_Flows) {
-        matlayout <- rbind(matlayout, c(iPlot + 1, iPlot + 1, iPlot + 1), c(iPlot + 1, iPlot + 1, iPlot + 1))
-        iPlot <- iPlot + 1
+      ## Flows plot is higher than the other TS
+      listBOOLPLOT1 <- listBOOLPLOT1[listBOOLPLOT1]
+      listBOOLPLOTF <- (names(listBOOLPLOT1) == "Flows") * BOOLPLOT_Flows
+      iHght <- iHght + listBOOLPLOTF * listBOOLPLOT1 * 0.3
+      if (Sum2 >= 1) {
+        iHght <- c(iHght, 1.0)
       }
-      if (BOOLPLOT_Error) {
-        matlayout <- rbind(matlayout, c(iPlot + 1, iPlot + 1, iPlot + 1), c(iPlot + 1, iPlot + 1, iPlot + 1))
-        iPlot <- iPlot + 1
-      }    
       if ((Sum1 >= 1 & Sum2 != 0) | (Sum1 == 0 & Sum2 == 3)) {
-        matlayout <- rbind(matlayout, c(iPlot + 1, iPlot + 2, iPlot + 3), c(iPlot + 1, iPlot + 2, iPlot + 3))
+        matlayout <- rbind(matlayout, iPlot + c(1, 2, 3))
         iPlot <- iPlot + 3
       }
       if (Sum1 == 0 & Sum2 == 2) {
-        matlayout <- rbind(matlayout, c(iPlot + 1, iPlot + 2))
+        matlayout <- rbind(matlayout, iPlot + c(1, 2))
         iPlot <- iPlot + 2
       }
       if (Sum1 == 0 & Sum2 == 1) {
         matlayout <- rbind(matlayout, iPlot + 1)
         iPlot <- iPlot + 1
       }
+
       iPlotMax <- iPlot
       
       # isRStudio <- Sys.getenv("RSTUDIO") == "1";
@@ -306,7 +302,7 @@ plot.OutputsModel <- function(x, Qobs = NULL, IndPeriod_Plot = NULL, BasinArea =
       #}
       
       LayoutWidths  <- rep.int(1, ncol(matlayout))
-      LayoutHeights <- rep.int(1, nrow(matlayout))
+      LayoutHeights <- iHght #rep.int(1, nrow(matlayout))
     }
     if (!is.null(LayoutMat)) {
       matlayout <- LayoutMat
-- 
GitLab