Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions gui/treemap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 1995-2025, Rene Brun and Fons Rademakers.
# All rights reserved.
#
# For the licensing terms see $ROOTSYS/LICENSE.
# For the list of contributors see $ROOTSYS/README/CREDITS.

############################################################################
# CMakeLists.txt file for building ROOT treemap package
# @author Patryk Tymoteusz Pilichowski CERN
############################################################################

ROOT_STANDARD_LIBRARY_PACKAGE(ROOTTreeMap
HEADERS
ROOT/RTreeMapBase.hxx
ROOT/RTreeMapPainter.hxx
SOURCES
RTreeMapBase.cxx
RTreeMapImporter.cxx
RTreeMapPainter.cxx
DEPENDENCIES
ROOTNTuple
ROOTNTupleUtil
Gpad
RIO
)
17 changes: 17 additions & 0 deletions gui/treemap/inc/LinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Author: Patryk Pilichowski 08/2025

/*************************************************************************
* Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifdef __CLING__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class ROOT::Experimental::RTreeMapBase+;
#pragma link C++ class ROOT::Experimental::RTreeMapPainter+;
#endif
89 changes: 89 additions & 0 deletions gui/treemap/inc/ROOT/RTreeMapBase.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/// \file ROOT/RTreeMapBase.hxx
/// \ingroup TreeMap ROOT7
/// \author Patryk Tymoteusz Pilichowski <[email protected]>
/// \date 2025-08-21
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
* Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef RTREEMAPBASE_HXX
#define RTREEMAPBASE_HXX

#include <cstdint>
#include <string>
#include <vector>

namespace ROOT::Experimental {

// clang-format off
/**
\class ROOT::Experimental::RTreeMapBase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we planning any test for these classes? Is there any 'how to use' documentation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A brief tutorial would be nice to have indeed.

\ingroup TreeMap
\brief Base logic for drawing a treemap visualization

A treemap can be used for analyzing a hierarchical data structure whose elements have a certain size. It visualizes this
hierarchical data as nested rectangles which allows for easy comparison of proportions within categories, but
also the whole structure. The squarification algorithm is used to make these rectangles as close to squares as
possible for visual clarity.

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
allows for drawing a legend of types of leaf nodes, and see which types occupy how much of the total space.
*/
Comment on lines +37 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allows for drawing a legend of types of leaf nodes, and see which types occupy how much of the total space.
*/
allows for drawing a legend of types of leaf nodes, and see which types occupy how much of the total space.
Note: this visualization class/technique is independent/unrelated to `TTree`.
*/

// clang-format on
class RTreeMapBase {
public:
struct Node {
std::string fName, fType;
uint64_t fSize;
uint64_t fChildrenIdx;
uint64_t fNChildren;
Node() = default;
Node(const std::string &name, const std::string &type, uint64_t size, uint64_t childrenIdx, uint64_t nChildren)
: fName(name), fType(type), fSize(size), fChildrenIdx(childrenIdx), fNChildren(nChildren)
{
}
};

struct Vec2 {
float x, y;
Vec2(float xArg, float yArg) : x(xArg), y(yArg) {}
};
struct Rect {
Vec2 fBottomLeft, fTopRight;
Rect(const Vec2 &bottomLeftArg, const Vec2 &topRightArg) : fBottomLeft(bottomLeftArg), fTopRight(topRightArg) {}
};
struct RGBColor {
uint8_t r, g, b, a;
RGBColor(uint8_t rArg, uint8_t gArg, uint8_t bArg, uint8_t aArg = 255) : r(rArg), g(gArg), b(bArg), a(aArg) {}
};
std::vector<Node> fNodes;
RTreeMapBase() = default;
virtual ~RTreeMapBase() = default;

protected:
/////////////////////////////////////////////////////////////////////////////
/// \brief Logic for drawing the entirety of the treemap.
void DrawTreeMap(const Node &elem, Rect rect, int depth) const;

/////////////////////////////////////////////////////////////////////////////
/// \brief Logic for drawing the legend of leaf types
void DrawLegend() const;

/////////////////////////////////////////////////////////////////////////////
/// \brief Logic for drawing a box
virtual void AddBox(const Rect &rect, const RGBColor &color, float borderWidth = 0.15f) const = 0;

/////////////////////////////////////////////////////////////////////////////
/// \brief Logic for drawing a text
virtual void AddText(const Vec2 &pos, const std::string &content, float size,
const RGBColor &color = RGBColor(0, 0, 0), bool alignCenter = false) const = 0;
};
} // namespace ROOT::Experimental
#endif
70 changes: 70 additions & 0 deletions gui/treemap/inc/ROOT/RTreeMapPainter.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/// \file ROOT/RTreeMapPainter.hxx
/// \ingroup TreeMap ROOT7
/// \author Patryk Tymoteusz Pilichowski <[email protected]>
/// \date 2025-08-21
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
* Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef TTREEMAP_HXX
#define TTREEMAP_HXX

#include "RTreeMapBase.hxx"

#include "TROOT.h"
#include "TObject.h"
#include "TCanvas.h"
#include "TPad.h"

#include <vector>

namespace ROOT::Experimental {
class RNTupleInspector;

// clang-format off
/**
\class ROOT::Experimental::RTreeMapPainter
\ingroup TreeMap
\brief Logic for drawing a treemap on a TVirtualPad
*/
// clang-format on
class RTreeMapPainter final : public ROOT::Experimental::RTreeMapBase, public TObject {
public:
/////////////////////////////////////////////////////////////////////////////
/// \brief Logic for converting an RNTuple to RTreeMapPainter given RNTupleInspector
static std::unique_ptr<RTreeMapPainter> Import(const ROOT::Experimental::RNTupleInspector &insp);

/////////////////////////////////////////////////////////////////////////////
/// \brief Logic for converting an RNTuple to RTreeMapPainter given file and tuple names
static std::unique_ptr<RTreeMapPainter> Import(std::string_view sourceFileName, std::string_view tupleName);

struct Node final : public ROOT::Experimental::RTreeMapBase::Node, public TObject {
public:
ClassDef(Node, 1);
};
RTreeMapPainter() = default;
void Paint(Option_t *opt) override;

ClassDefOverride(RTreeMapPainter, 1);

~RTreeMapPainter() override = default;

private:
/////////////////////////////////////////////////////////////////////////////
/// \brief Logic for drawing a box on TVirtualPad
void AddBox(const Rect &rect, const RGBColor &color, float borderWidth) const final;

/////////////////////////////////////////////////////////////////////////////
/// \brief Logic for drawing a text on TVirtualPad
void AddText(const Vec2 &pos, const std::string &content, float size, const RGBColor &color = RGBColor(0, 0, 0),
bool alignCenter = false) const final;
};
} // namespace ROOT::Experimental
#endif
Loading
Loading