Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RTreeMapBase.hxx
Go to the documentation of this file.
1/// \file ROOT/RTreeMapBase.hxx
2/// \author Patryk Tymoteusz Pilichowski <patryk.tymoteusz.pilichowski@cern.ch>
3/// \date 2025-08-21
4/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
5/// is welcome!
6
7/*************************************************************************
8 * Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
15#ifndef RTREEMAPBASE_HXX
16#define RTREEMAPBASE_HXX
17
18#include <cstdint>
19#include <string>
20#include <vector>
21
22namespace ROOT::Experimental {
23
24// clang-format off
25/**
26\class ROOT::Experimental::RTreeMapBase
27\ingroup TreeMap
28\brief Base logic for drawing a treemap visualization
29
30A treemap can be used for analyzing a hierarchical data structure whose elements have a certain size. It visualizes this
31hierarchical data as nested rectangles which allows for easy comparison of proportions within categories, but
32also the whole structure. The squarification algorithm is used to make these rectangles as close to squares as
33possible for visual clarity.
34
35Furthermore, we assume that each node has a type and that the size of a non-leaf node equals to the total size of its children. This
36allows for drawing a legend of types of leaf nodes, and see which types occupy how much of the total space.
37
38Note: this visualization class/technique is independent/unrelated to `TTree`.
39*/
40// clang-format on
42public:
43 struct Node {
44 std::string fName, fType;
45 uint64_t fSize;
46 uint64_t fChildrenIdx;
47 uint64_t fNChildren;
48 Node() = default;
49 Node(const std::string &name, const std::string &type, uint64_t size, uint64_t childrenIdx, uint64_t nChildren)
50 : fName(name), fType(type), fSize(size), fChildrenIdx(childrenIdx), fNChildren(nChildren)
51 {
52 }
53 };
54
55 struct Vec2 {
56 float x, y;
57 Vec2(float xArg, float yArg) : x(xArg), y(yArg) {}
58 };
59 struct Rect {
61 Rect(const Vec2 &bottomLeftArg, const Vec2 &topRightArg) : fBottomLeft(bottomLeftArg), fTopRight(topRightArg) {}
62 };
63 struct RGBColor {
64 uint8_t r, g, b, a;
65 RGBColor(uint8_t rArg, uint8_t gArg, uint8_t bArg, uint8_t aArg = 255) : r(rArg), g(gArg), b(bArg), a(aArg) {}
66 };
67 std::vector<Node> fNodes;
68 RTreeMapBase() = default;
69 virtual ~RTreeMapBase() = default;
70
71protected:
72 /////////////////////////////////////////////////////////////////////////////
73 /// \brief Logic for drawing the entirety of the treemap.
74 void DrawTreeMap(const Node &elem, Rect rect, int depth) const;
75
76 /////////////////////////////////////////////////////////////////////////////
77 /// \brief Logic for drawing the legend of leaf types
78 void DrawLegend() const;
79
80 /////////////////////////////////////////////////////////////////////////////
81 /// \brief Logic for drawing a box
82 virtual void AddBox(const Rect &rect, const RGBColor &color, float borderWidth = 0.15f) const = 0;
83
84 /////////////////////////////////////////////////////////////////////////////
85 /// \brief Logic for drawing a text
86 virtual void AddText(const Vec2 &pos, const std::string &content, float size,
87 const RGBColor &color = RGBColor(0, 0, 0), bool alignCenter = false) const = 0;
88};
89} // namespace ROOT::Experimental
90#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char name[80]
Definition TGX11.cxx:148
virtual void AddText(const Vec2 &pos, const std::string &content, float size, const RGBColor &color=RGBColor(0, 0, 0), bool alignCenter=false) const =0
Logic for drawing a text.
void DrawLegend() const
Logic for drawing the legend of leaf types.
virtual void AddBox(const Rect &rect, const RGBColor &color, float borderWidth=0.15f) const =0
Logic for drawing a box.
void DrawTreeMap(const Node &elem, Rect rect, int depth) const
Logic for drawing the entirety of the treemap.
Namespace for ROOT features in testing.
Definition TROOT.h:100
Node(const std::string &name, const std::string &type, uint64_t size, uint64_t childrenIdx, uint64_t nChildren)
RGBColor(uint8_t rArg, uint8_t gArg, uint8_t bArg, uint8_t aArg=255)
Rect(const Vec2 &bottomLeftArg, const Vec2 &topRightArg)