-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[gui] Add RTreeMap #19731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
magnustymoteus
wants to merge
1
commit into
root-project:master
Choose a base branch
from
magnustymoteus:treemap-c++
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[gui] Add RTreeMap #19731
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||||||||||||||
\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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
// clang-format on | ||||||||||||||
class RTreeMapBase { | ||||||||||||||
silverweed marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.