From dc2d8a844238dec11f161f96cc1dd1878f40a555 Mon Sep 17 00:00:00 2001
From: Olivier Couet <olivier.couet@gmail.com>
Date: Wed, 28 Nov 2018 13:57:44 +0100
Subject: [PATCH] Implement automatic placement of legend for TMultiGraph and
 THStack.

---
 README/ReleaseNotes/v618/index.md |  1 +
 graf2d/gpad/src/TPad.cxx          | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/README/ReleaseNotes/v618/index.md b/README/ReleaseNotes/v618/index.md
index a3a206c9d0b..42d365cb447 100644
--- a/README/ReleaseNotes/v618/index.md
+++ b/README/ReleaseNotes/v618/index.md
@@ -76,6 +76,7 @@ The methods could be replaced by equivalent methods with other signature:
   - In the statistics painting for 2D histograms, the  central cell of
     the underflow/overflow grid was not properly rendered for very large contents.
     This problem was reported [here](https://root-forum.cern.ch/t/stat-box-for-th2/).
+  - The automatic placement of legend now "sees" TMultiGraph and THStack.
 
 ## 3D Graphics Libraries
 
diff --git a/graf2d/gpad/src/TPad.cxx b/graf2d/gpad/src/TPad.cxx
index b795df8a302..e85c5764d8d 100644
--- a/graf2d/gpad/src/TPad.cxx
+++ b/graf2d/gpad/src/TPad.cxx
@@ -3035,6 +3035,20 @@ void TPad::FillCollideGrid(TObject *oi)
          if (o->InheritsFrom(TBox::Class()))   { FillCollideGridTBox(o);   continue;}
          if (o->InheritsFrom(TH1::Class()))    { FillCollideGridTH1(o);    continue;}
          if (o->InheritsFrom(TGraph::Class())) { FillCollideGridTGraph(o); continue;}
+         if (o->InheritsFrom(TMultiGraph::Class())) {
+            TList * grlist = ((TMultiGraph *)o)->GetListOfGraphs();
+            TIter nextgraph(grlist);
+            TObject * og;
+            while ((og = nextgraph())) FillCollideGridTGraph(og);
+         }
+         if (o->InheritsFrom(THStack::Class())) {
+            TList * hlist = ((THStack *)o)->GetHists();
+            TIter nexthist(hlist);
+            TObject * oh;
+            while ((oh = nexthist())) {
+               if (oh->InheritsFrom(TH1::Class())) FillCollideGridTH1(oh);
+            }
+         }
       }
    }
 }
-- 
GitLab