Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
MakeTCanvasJS.C
Go to the documentation of this file.
1/// Generates the root file output of the macro MacroName
2
3#include "TString.h"
4#include "TCanvas.h"
5#include "TSystem.h"
6#include "TROOT.h"
7#include "TBufferJSON.h"
8#include <fstream>
9
10void MakeTCanvasJS(const char *MacroName, const char *IN, const char *OutDir, bool cp, bool py, bool aclic)
11{
12
13 // Execute the macro as a C++ one or a Python one.
14 if (py)
15 gROOT->ProcessLine(TString::Format("TPython::ExecScript(\"%s\");",MacroName));
16 else if (aclic)
17 gROOT->ProcessLine(TString::Format(".x %s+",MacroName));
18 else
19 gROOT->ProcessLine(TString::Format(".x %s",MacroName));
20
21 // If needed, copy the macro in the documentation directory.
22 if (cp) {
23 TString MN = MacroName;
24 Int_t i = MN.Index("(");
25 Int_t l = MN.Length();
26 if (i>0) MN.Remove(i, l);
27 gSystem->Exec(TString::Format("cp %s %s/macros", MN.Data(), OutDir));
28 }
29
30 // Build the html file inlining the JS pictures
31
32 TIter next(gROOT->GetListOfCanvases());
33 std::vector<TString> json_codes;
34 TCanvas* canvas = nullptr;
35 int ImageNum = 0;
36
37 // Iterate over all the pads generated by the macro and produce the corresponding pictures.
38
39 FILE *fh = fopen(TString::Format("%s/macros/%s.html",OutDir,IN), "w");
40 fprintf(fh,"<center>\n");
41 while ((canvas = (TCanvas*) next()) != nullptr) {
42 ImageNum++;
44 fprintf(fh," <div id=\"draw_pict%d_%s\" style=\"position: relative; width: %dpx; height: %dpx;\"></div>\n",
45 ImageNum,IN,canvas->GetWindowWidth(),canvas->GetWindowHeight());
46 }
47 fprintf(fh,"</center>\n");
48
49 fprintf(fh,"<script type=\"module\">\n");
50 fprintf(fh," import { settings, parse, draw } from './js/modules/main.mjs';\n");
51 fprintf(fh," settings.HandleKeys = false;\n");
52 for (int i=1; i<=ImageNum; i++) {
53 fprintf(fh," let obj%d = parse(%s);\n", i, json_codes[i-1].Data());
54 fprintf(fh," draw('draw_pict%d_%s', obj%d, \"\");\n", i,IN,i);
55 }
56 fprintf(fh,"</script>\n");
57
58 fclose(fh);
59}
void MakeTCanvasJS(const char *MacroName, const char *IN, const char *OutDir, bool cp, bool py, bool aclic)
Generates the root file output of the macro MacroName.
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
#define gROOT
Definition TROOT.h:417
externTSystem * gSystem
Definition TSystem.h:582
TCanvas * canvas
Definition webwindow.cxx:22
@ kNoSpaces
no new lines plus remove all spaces around "," and ":" symbols
Definition TBufferJSON.h:39
@ kSameSuppression
zero suppression plus compress many similar values together
Definition TBufferJSON.h:45
The Canvas class.
Definition TCanvas.h:23
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
const char * Data() const
Definition TString.h:384
TString & Remove(Ssiz_t pos)
Definition TString.h:694
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2385
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:660
static TString CreateCanvasJSON(TCanvas *c, Int_t json_compression=0, Bool_t batchmode=kFALSE)
Create JSON painting output for given canvas Produce JSON can be used for offline drawing with JSROOT...
Float_t py
Definition hprod.C:37
TLine l
Definition textangle.C:4