Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-14 10:31:21

0001 /// \file ROOT/RTreeMapBase.hxx
0002 /// \ingroup TreeMap ROOT7
0003 /// \author Patryk Tymoteusz Pilichowski <patryk.tymoteusz.pilichowski@cern.ch>
0004 /// \date 2025-08-21
0005 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
0006 /// is welcome!
0007 
0008 /*************************************************************************
0009  * Copyright (C) 1995-2025, Rene Brun and Fons Rademakers.               *
0010  * All rights reserved.                                                  *
0011  *                                                                       *
0012  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0013  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0014  *************************************************************************/
0015 
0016 #ifndef RTREEMAPBASE_HXX
0017 #define RTREEMAPBASE_HXX
0018 
0019 #include <cstdint>
0020 #include <string>
0021 #include <vector>
0022 
0023 namespace ROOT::Experimental {
0024 
0025 // clang-format off
0026 /**
0027 \class ROOT::Experimental::RTreeMapBase
0028 \ingroup TreeMap
0029 \brief Base logic for drawing a treemap visualization
0030 
0031 A treemap can be used for analyzing a hierarchical data structure whose elements have a certain size. It visualizes this
0032 hierarchical data as nested rectangles which allows for easy comparison of proportions within categories, but
0033 also the whole structure. The squarification algorithm is used to make these rectangles as close to squares as
0034 possible for visual clarity.
0035 
0036 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
0037 allows for drawing a legend of types of leaf nodes, and see which types occupy how much of the total space.
0038 
0039 Note: this visualization class/technique is independent/unrelated to `TTree`.
0040 */
0041 // clang-format on
0042 class RTreeMapBase {
0043 public:
0044    struct Node {
0045       std::string fName, fType;
0046       uint64_t fSize;
0047       uint64_t fChildrenIdx;
0048       uint64_t fNChildren;
0049       Node() = default;
0050       Node(const std::string &name, const std::string &type, uint64_t size, uint64_t childrenIdx, uint64_t nChildren)
0051          : fName(name), fType(type), fSize(size), fChildrenIdx(childrenIdx), fNChildren(nChildren)
0052       {
0053       }
0054    };
0055 
0056    struct Vec2 {
0057       float x, y;
0058       Vec2(float xArg, float yArg) : x(xArg), y(yArg) {}
0059    };
0060    struct Rect {
0061       Vec2 fBottomLeft, fTopRight;
0062       Rect(const Vec2 &bottomLeftArg, const Vec2 &topRightArg) : fBottomLeft(bottomLeftArg), fTopRight(topRightArg) {}
0063    };
0064    struct RGBColor {
0065       uint8_t r, g, b, a;
0066       RGBColor(uint8_t rArg, uint8_t gArg, uint8_t bArg, uint8_t aArg = 255) : r(rArg), g(gArg), b(bArg), a(aArg) {}
0067    };
0068    std::vector<Node> fNodes;
0069    RTreeMapBase() = default;
0070    virtual ~RTreeMapBase() = default;
0071 
0072 protected:
0073    /////////////////////////////////////////////////////////////////////////////
0074    /// \brief Logic for drawing the entirety of the treemap.
0075    void DrawTreeMap(const Node &elem, Rect rect, int depth) const;
0076 
0077    /////////////////////////////////////////////////////////////////////////////
0078    /// \brief Logic for drawing the legend of leaf types
0079    void DrawLegend() const;
0080 
0081    /////////////////////////////////////////////////////////////////////////////
0082    /// \brief Logic for drawing a box
0083    virtual void AddBox(const Rect &rect, const RGBColor &color, float borderWidth = 0.15f) const = 0;
0084 
0085    /////////////////////////////////////////////////////////////////////////////
0086    /// \brief Logic for drawing a text
0087    virtual void AddText(const Vec2 &pos, const std::string &content, float size,
0088                         const RGBColor &color = RGBColor(0, 0, 0), bool alignCenter = false) const = 0;
0089 };
0090 } // namespace ROOT::Experimental
0091 #endif