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