From c12560c66857568d2ea9f67b7e4a116a3e18fd94 Mon Sep 17 00:00:00 2001
From: zleba <radek.zlebcik@gmail.com>
Date: Thu, 14 Jan 2021 09:44:14 +0100
Subject: [PATCH] Removal of the user-defined label

---
 RemoveOverlaps.h | 18 +++++++++++++++---
 test.C           |  4 ++--
 test.py          |  4 ++--
 test2.C          |  6 +++---
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/RemoveOverlaps.h b/RemoveOverlaps.h
index b9bd899..e12a67f 100644
--- a/RemoveOverlaps.h
+++ b/RemoveOverlaps.h
@@ -1691,7 +1691,7 @@ L210:
 
 
 
-inline double RemoveOverlaps(TVirtualPad *pad, TAxis *ax, bool remFirst=true, bool remLast=true, bool isVisual = false)
+inline double RemoveOverlaps(TVirtualPad *pad, TAxis *ax, vector<TString> excluded = {}, bool remFirst=true, bool remLast=true, bool isVisual = false)
 {
 	//std::cout << "Helenka " << ax->GetName() << std::endl;
 	pad->cd();
@@ -1789,10 +1789,22 @@ inline double RemoveOverlaps(TVirtualPad *pad, TAxis *ax, bool remFirst=true, bo
 			}
 			//std::cout << "Marketka "<<isX<<" "<<i<<" "<<   myX1 <<" "<< myX2 <<" : "<< myY1<<" "<<myY2<< std::endl;
 
-			bool isOutside = (isX && ((remFirst && myX1 < 0) || (remLast  && myX2 > 1))) ||
+			bool isRemoved = (isX && ((remFirst && myX1 < 0) || (remLast  && myX2 > 1))) ||
 			                (!isX && ((remFirst && myY1 < 0) || (remLast && myY2 > 1) ));
 
-			if(isOutside) {
+            //removing labels by names
+            TString name = gAx->recsNDC[i].lat->GetTitle();
+            name.ReplaceAll("#minus", "-");
+            name.ReplaceAll("#times", " ");
+            name.ReplaceAll("{", "");
+            name.ReplaceAll("}", "");
+
+            cout << "Helenka " << name << endl;
+            if(find(excluded.begin(), excluded.end(), name) != excluded.end()) {
+                isRemoved = true;
+            }
+
+			if(isRemoved) {
 				//ax->ChangeLabel(i+1, -1, 0);
 				if(gAx->recsNDC[i].lat) li->Remove(gAx->recsNDC[i].lat);
 				if(gAx->recsNDC[i].tex) li->Remove(gAx->recsNDC[i].tex);
diff --git a/test.C b/test.C
index c13fe7a..5bac5f9 100644
--- a/test.C
+++ b/test.C
@@ -29,8 +29,8 @@ void test()
         GetYaxis()->SetRangeUser(0, 300);
         DrawLatexUp( -1,  Form("n_{Ev} = %d", nEv));
         //Remove overlaps of both axes
-        RemoveOverlaps(gPad, GetXaxis(), true, true);
-        RemoveOverlaps(gPad, GetYaxis(), true, true);
+        RemoveOverlaps(gPad, GetXaxis(), {"-1", "2", "3"}, true, true);
+        RemoveOverlaps(gPad, GetYaxis(), {"150", "200"}, true, true);
     }
 
     DrawLatexUp(can->GetPad(1), can->GetPad(5), 2, "This is a testing grid");
diff --git a/test.py b/test.py
index e20ead2..3ced3f3 100644
--- a/test.py
+++ b/test.py
@@ -33,8 +33,8 @@ for i in range(5*3):
     ph.DrawLatexUp( -1,  "n_{Ev} = "+str(nEv));
 
     #Remove overlaps of both axes
-    #RemoveOverlaps(gPad, GetXaxis(), true, true);
-    #RemoveOverlaps(gPad, GetYaxis(), true, true);
+    #RemoveOverlaps(gPad, GetXaxis(), {}, true, true);
+    #RemoveOverlaps(gPad, GetYaxis(), {], true, true);
 
 ph.DrawLatexUp(can.GetPad(1), can.GetPad(5), 2, "This is a testing grid in Python");
 can.SaveAs("testGridPy.pdf");
diff --git a/test2.C b/test2.C
index 92f7552..1aa7e03 100644
--- a/test2.C
+++ b/test2.C
@@ -27,7 +27,7 @@ void test2()
         }
         h->Draw("hist e");
         GetXaxis()->SetMoreLogLabels();
-        GetXaxis()->SetNoExponent();
+        //GetXaxis()->SetNoExponent();
 
 
 
@@ -42,8 +42,8 @@ void test2()
         if(i%5 != 0 ) GetYaxis()->SetLabelSize(0.001);
         if(i < 10 ) GetXaxis()->SetLabelSize(0.001);
 
-        RemoveOverlaps(gPad, GetXaxis(), true, true);
-        RemoveOverlaps(gPad, GetYaxis(), true, true);
+        RemoveOverlaps(gPad, GetXaxis(), {"10^3"}, true, true);
+        RemoveOverlaps(gPad, GetYaxis(), {}, true, true);
     }
 
     DrawLatexUp(can->GetPad(1), can->GetPad(5), 2, "This is a testing grid");
-- 
GitLab