diff --git a/.travis.yml b/.travis.yml index e3dda7610b5cd3b9d6a46731d9b5ec82e50ed772..1d8abd89ba56daa555ddc2941e0070f2cead03c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ script: - ./rd make all test - ./rd ./test && mv testGrid.pdf testGrid1.pdf - ./rd root -l -b -q test.C && mv testGrid.pdf testGrid2.pdf + - ./rd root -l -b -q test2.C && mv testGrid.pdf testGrid3.pdf - ./rd python test.py - mkdir public && cp *.pdf public diff --git a/Makefile b/Makefile index 49870b9eaf94884fca9d2b03600ac00ce1bd330b..b07e6cfc51eacda6969bc9dfe62c8631d3d5e7d1 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,10 @@ clean: # clang++ -O0 -shared -Wl,-soname,libplottingHelperNew.so -o libplottingHelperNew.so plottingHelper.o test: test.C - ${CXX} -Wall ${CFLAGS} $< -Wl,-rpath,. plottingHelper_C.so -o test ${LIBS} + ${CXX} -Wall ${CFLAGS} $< -Wl,-rpath,. plottingHelper_C.so -o $@ ${LIBS} + +test2: test2.C + ${CXX} -Wall ${CFLAGS} $< -Wl,-rpath,. plottingHelper_C.so -o $@ ${LIBS} # testFast: test.C libPlottingHelper.so - ${CXX} -Wall ${CFLAGS} $< -Wl,-rpath,. -L. -lPlottingHelper -o testFast ${LIBS} + ${CXX} -Wall ${CFLAGS} $< -Wl,-rpath,. -L. -lPlottingHelper -o $@ ${LIBS} diff --git a/RemoveOverlaps.h b/RemoveOverlaps.h index ee28d7be39f7feafd7054cd67068620e25ea880d..101d67e6c12e53306ff77d28d5e392f77142af5c 100644 --- a/RemoveOverlaps.h +++ b/RemoveOverlaps.h @@ -1798,13 +1798,61 @@ inline double RemoveOverlaps(TVirtualPad *pad, TAxis *ax, bool remFirst=true, bo if(gAx->recsNDC[i].tex) li->Remove(gAx->recsNDC[i].tex); //std::cout << "Removing " << i+1 << std::endl; } + } + + + //remove when pair of labels intersect (with MoreLogLabels) + for(unsigned i = 0; i < gAx->recsNDC.size(); ++i) + for(unsigned j = i+1; j < gAx->recsNDC.size(); ++j) { + TLine *lin = new TLine; + lin->SetLineColor(kRed); + double iX1 = gAx->recsNDC[i].fX; + double iX2 = gAx->recsNDC[i].fX+ gAx->recsNDC[i].fWidth; + double iY1 = gAx->recsNDC[i].fY; + double iY2 = gAx->recsNDC[i].fY+ gAx->recsNDC[i].fHeight; + + double jX1 = gAx->recsNDC[j].fX; + double jX2 = gAx->recsNDC[j].fX+ gAx->recsNDC[j].fWidth; + double jY1 = gAx->recsNDC[j].fY; + double jY2 = gAx->recsNDC[j].fY+ gAx->recsNDC[j].fHeight; + + + + bool isColision = (isX && ((iX1 < jX1 && jX1 < iX2) || (iX1 < jX2 && jX2 < iX2) )); + + + if(isColision && gAx->recsNDC[i].lat && gAx->recsNDC[j].lat) { + TString iName = gAx->recsNDC[i].lat->GetTitle(); + TString jName = gAx->recsNDC[j].lat->GetTitle(); + + cout << "Radek " << iName <<" "<< jName << endl; + int rem; + if(iName[0] > jName[0]) + rem = i; + else + rem = j; + + + //ax->ChangeLabel(i+1, -1, 0); + if(gAx->recsNDC[rem].lat) li->Remove(gAx->recsNDC[rem].lat); + if(gAx->recsNDC[rem].tex) li->Remove(gAx->recsNDC[rem].tex); + + + //if(gAx->recsNDC[j].lat) li->Remove(gAx->recsNDC[j].lat); + //if(gAx->recsNDC[j].tex) li->Remove(gAx->recsNDC[j].tex); + + //std::cout << "Removing " << i+1 << std::endl; + } } + + + //Plot title rect TLine *lin = new TLine; lin->SetLineColor(kBlue); diff --git a/test2.C b/test2.C new file mode 100644 index 0000000000000000000000000000000000000000..92f7552e87b2995b214a3ccaa73106332d2212a6 --- /dev/null +++ b/test2.C @@ -0,0 +1,58 @@ +#include "TROOT.h" +#include "TCanvas.h" +#include "TStyle.h" +#include "TPad.h" +#include "TGaxis.h" + +#include "plottingHelper.h" +#include "RemoveOverlaps.h" + +R__LOAD_LIBRARY(plottingHelper_C.so) +using namespace PlottingHelper; + + +void test2() +{ + gStyle->SetOptStat(0); + TCanvas *can = new TCanvas("can", "", 1200, 800); + DivideTransparent({1,0,1,0,1,0,1,0,1}, {1,0,1,0,1}); + for(int i = 0; i < 5*3; ++i) { + can->cd(i+1); + + TH1D *h = new TH1D(Form("%d",rand()),";;", 100, 30, 50000); + int nEv = 10*(1000 - i*40); + for(int j = 0; j < nEv; ++j) { + double v = exp(pow(gRandom->Uniform()*10,2)); + h->Fill(v); + } + h->Draw("hist e"); + GetXaxis()->SetMoreLogLabels(); + GetXaxis()->SetNoExponent(); + + + + gPad->SetLogx(); + SetFTO({12}, {5}, {1.4, 2, 0.5, 4}); + if(i == 5*3-1) GetXaxis()->SetTitle("x"); + if(i == 0) GetYaxis()->SetTitle("y"); + GetYaxis()->SetRangeUser(0, 300); + DrawLatexUp( -1, Form("n_{Ev} = %d", nEv)); + //Remove overlaps of both axes + + 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); + } + + DrawLatexUp(can->GetPad(1), can->GetPad(5), 2, "This is a testing grid"); + can->SaveAs("testGrid.pdf"); + +} + +int main() +{ + test2(); + return 0; +}