CanvasHelper
|
🏠️ Project homepage: https://petrstepanov.com/root-canvas-helper
🐱 Github repository: https://github.com/petrstepanov/root-canvas-helper
By default, ROOT graphics on the canvas scales according to the canvas size. The bigger the canvas size is - the larger corresponding fonts, paddings are. This approach works good for canvases that contain one or two sub-pads. However, when ROOT canvas is divided into a higher number of sub-pads, say, 3x3, 5x5 or more, following issues take place:
Above issues are especially notable on screens with smaller resolution. For instance, let us create a test ROOT canvas divided into 4 sub-pads. On the screenshot below, canvas size is set to 800x600 pixels.
It is quite clear that sharing the plots with such a small text is rather unacceptable. Often when sharing screen at the online conferences, participants can hardly see the results.
Indeed, ROOT allows for setting a fixed pixel size font. However, this is usually not enough. A nice looking multi-pad plot also requires tweaking of the number of the tick marks, adjusting frame margins, tick mark length, changing title font sizes, axis title spacing and many more. ROOT is a very flexible framework and majority of these things can be easily tweaked. But at what cost? It comes down to duplicating chunks of code for every particular canvas. Moreover,
This library is aimed on fixing issues outlined above. Canvas Helper converts ROOT plots from fractional-based geometry to fixed pixel sizes. As a result, the plot looks more alike to what Gnuplot output is.:
A single line of code is required to make the change happen. We simply pass the canvas instance to the library after all the primitives were created:
This is the preferred installation option. Installation depends on prerequisites:
cmake
version 3.XX program installed on computer. Usually CMake is included in Linux "Development Tools" group package. On older distributions CMake v3.XX may be named cmake3
.First we download the repository and create an out-of-source build folder.
Next we invoke CMake. It ensures that all the dependencies are satisfied and generates GNU Makefile
. Finally, we execute Makefile's install
target:
Makefile generates dictionary, builds shared libaray, compiles code into object files, links the executable, and installs corresponding files files in required locations.
Tip. If above command requires administrator privilleges that current user does not have, the install prefix can be changed to a local install:
Additionally, $PATH
, $LD_LIBRARY_PATH
, and $CPLUS_INCLUDE_PATH
environemnt variables need to be modified for the library to be discoverable. Below please find an example how to do it in BASH and CSH shells:
This should do the trick.
This is an alternative way of building the the library with Cling interpreter. Check out the repository:
Make sure your ROOT environment is set up. Next, enter the Cling interpreter shell and compile a shared library from sources:
Now that the shared library is compiled we install the .so
library, .pcm
dictionary and *.h
header files. Commands below may require administrative persissions:
Now that the library is installed, user should be able to run the demo macros:
After the library was installed, it needs to be loaded into the interpreter session in your ROOT script:
If developing a ROOT-based project (not a ROOT macro script), corresponding library header file needs to be included #include <CanvasHelper.h>
. Program needs to be link against the CanvasHelper shared library. Library should be discoverable witn CMake's find_library(...)
. function.
Please refer to the Doxygen documentation to get familiar with all functionality: https://petrstepanov.com/root-canvas-helper/classCanvasHelper.html
Find a demo ROOT macros utilizing the CanvasHepler library here: https://github.com/petrstepanov/root-canvas-helper/blob/main/src/canvasHelperDemo.cpp
Feel free to contribute or suggest any useful features. Library can be compiled with debug symbols and/or imported to the IDE of your choice. Following CMake variable should be specified to successfully build the library in the IDE:
Please refer to this GitHub repository to find an example of integration of this library into a CMake-Based project:
https://github.com/petrstepanov/light-guides/tree/main/draw
Thank you for your attention!