Skip to content

Commit 3b19020

Browse files
Add RTreeMap
1 parent a8ef8b0 commit 3b19020

File tree

7 files changed

+578
-0
lines changed

7 files changed

+578
-0
lines changed

gui/treemap/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (C) 1995-2025, Rene Brun and Fons Rademakers.
2+
# All rights reserved.
3+
#
4+
# For the licensing terms see $ROOTSYS/LICENSE.
5+
# For the list of contributors see $ROOTSYS/README/CREDITS.
6+
7+
############################################################################
8+
# CMakeLists.txt file for building ROOT treemap package
9+
# @author Patryk Tymoteusz Pilichowski CERN
10+
############################################################################
11+
12+
ROOT_STANDARD_LIBRARY_PACKAGE(ROOTTreeMap
13+
HEADERS
14+
ROOT/RTreeMapBase.hxx
15+
ROOT/RTreeMapPainter.hxx
16+
SOURCES
17+
RTreeMapBase.cxx
18+
RTreeMapImporter.cxx
19+
RTreeMapPainter.cxx
20+
DEPENDENCIES
21+
ROOTNTuple
22+
ROOTNTupleUtil
23+
Gpad
24+
RIO
25+
)

gui/treemap/inc/LinkDef.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Author: Patryk Pilichowski 08/2025
2+
3+
/*************************************************************************
4+
* Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
5+
* All rights reserved. *
6+
* *
7+
* For the licensing terms see $ROOTSYS/LICENSE. *
8+
* For the list of contributors see $ROOTSYS/README/CREDITS. *
9+
*************************************************************************/
10+
11+
#ifdef __CLING__
12+
#pragma link off all globals;
13+
#pragma link off all classes;
14+
#pragma link off all functions;
15+
#pragma link C++ class ROOT::Experimental::RTreeMapBase+;
16+
#pragma link C++ class ROOT::Experimental::RTreeMapPainter+;
17+
#endif

gui/treemap/inc/ROOT/RTreeMapBase.hxx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
Note: this visualization class/technique is independent/unrelated to `TTree`.
40+
*/
41+
// clang-format on
42+
class RTreeMapBase {
43+
public:
44+
struct Node {
45+
std::string fName, fType;
46+
uint64_t fSize;
47+
uint64_t fChildrenIdx;
48+
uint64_t fNChildren;
49+
Node() = default;
50+
Node(const std::string &name, const std::string &type, uint64_t size, uint64_t childrenIdx, uint64_t nChildren)
51+
: fName(name), fType(type), fSize(size), fChildrenIdx(childrenIdx), fNChildren(nChildren)
52+
{
53+
}
54+
};
55+
56+
struct Vec2 {
57+
float x, y;
58+
Vec2(float xArg, float yArg) : x(xArg), y(yArg) {}
59+
};
60+
struct Rect {
61+
Vec2 fBottomLeft, fTopRight;
62+
Rect(const Vec2 &bottomLeftArg, const Vec2 &topRightArg) : fBottomLeft(bottomLeftArg), fTopRight(topRightArg) {}
63+
};
64+
struct RGBColor {
65+
uint8_t r, g, b, a;
66+
RGBColor(uint8_t rArg, uint8_t gArg, uint8_t bArg, uint8_t aArg = 255) : r(rArg), g(gArg), b(bArg), a(aArg) {}
67+
};
68+
std::vector<Node> fNodes;
69+
RTreeMapBase() = default;
70+
virtual ~RTreeMapBase() = default;
71+
72+
protected:
73+
/////////////////////////////////////////////////////////////////////////////
74+
/// \brief Logic for drawing the entirety of the treemap.
75+
void DrawTreeMap(const Node &elem, Rect rect, int depth) const;
76+
77+
/////////////////////////////////////////////////////////////////////////////
78+
/// \brief Logic for drawing the legend of leaf types
79+
void DrawLegend() const;
80+
81+
/////////////////////////////////////////////////////////////////////////////
82+
/// \brief Logic for drawing a box
83+
virtual void AddBox(const Rect &rect, const RGBColor &color, float borderWidth = 0.15f) const = 0;
84+
85+
/////////////////////////////////////////////////////////////////////////////
86+
/// \brief Logic for drawing a text
87+
virtual void AddText(const Vec2 &pos, const std::string &content, float size,
88+
const RGBColor &color = RGBColor(0, 0, 0), bool alignCenter = false) const = 0;
89+
};
90+
} // namespace ROOT::Experimental
91+
#endif
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/// \file ROOT/RTreeMapPainter.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 TTREEMAP_HXX
17+
#define TTREEMAP_HXX
18+
19+
#include "RTreeMapBase.hxx"
20+
21+
#include "TROOT.h"
22+
#include "TObject.h"
23+
#include "TCanvas.h"
24+
#include "TPad.h"
25+
26+
#include <vector>
27+
28+
namespace ROOT::Experimental {
29+
class RNTupleInspector;
30+
31+
// clang-format off
32+
/**
33+
\class ROOT::Experimental::RTreeMapPainter
34+
\ingroup TreeMap
35+
\brief Logic for drawing a treemap on a TVirtualPad
36+
*/
37+
// clang-format on
38+
class RTreeMapPainter final : public ROOT::Experimental::RTreeMapBase, public TObject {
39+
public:
40+
/////////////////////////////////////////////////////////////////////////////
41+
/// \brief Logic for converting an RNTuple to RTreeMapPainter given RNTupleInspector
42+
static std::unique_ptr<RTreeMapPainter> Import(const ROOT::Experimental::RNTupleInspector &insp);
43+
44+
/////////////////////////////////////////////////////////////////////////////
45+
/// \brief Logic for converting an RNTuple to RTreeMapPainter given file and tuple names
46+
static std::unique_ptr<RTreeMapPainter> Import(std::string_view sourceFileName, std::string_view tupleName);
47+
48+
struct Node final : public ROOT::Experimental::RTreeMapBase::Node, public TObject {
49+
public:
50+
ClassDef(Node, 1);
51+
};
52+
RTreeMapPainter() = default;
53+
void Paint(Option_t *opt) override;
54+
55+
ClassDefOverride(RTreeMapPainter, 1);
56+
57+
~RTreeMapPainter() override = default;
58+
59+
private:
60+
/////////////////////////////////////////////////////////////////////////////
61+
/// \brief Logic for drawing a box on TVirtualPad
62+
void AddBox(const Rect &rect, const RGBColor &color, float borderWidth) const final;
63+
64+
/////////////////////////////////////////////////////////////////////////////
65+
/// \brief Logic for drawing a text on TVirtualPad
66+
void AddText(const Vec2 &pos, const std::string &content, float size, const RGBColor &color = RGBColor(0, 0, 0),
67+
bool alignCenter = false) const final;
68+
};
69+
} // namespace ROOT::Experimental
70+
#endif

0 commit comments

Comments
 (0)