59static std::vector<std::pair<std::string, uint64_t>>
GetDiskOccupation(
const std::vector<RTreeMapBase::Node> &nodes)
61 std::unordered_map<std::string, uint64_t> acc;
62 for (
const auto &node : nodes) {
63 if (node.fNChildren > 0)
65 acc[node.fType] += node.fSize;
68 std::vector<std::pair<std::string, uint64_t>>
vec;
69 vec.reserve(acc.size());
71 vec.emplace_back(std::move(p.first), p.second);
73 std::sort(
vec.begin(),
vec.end(), [](
const auto &
a,
const auto &
b) { return a.second > b.second; });
78static float ComputeWorstRatio(
const std::vector<RTreeMapBase::Node> &row,
float width,
float height,
79 uint64_t totalSize,
bool horizontalRows)
84 for (
const auto &child : row)
85 sumRow += child.fSize;
88 float worstRatio = 0.0f;
89 for (
const auto &child : row) {
90 float ratio = horizontalRows ?
static_cast<float>(child.fSize * width * totalSize) / (sumRow * sumRow * height)
91 :
static_cast<float>(child.fSize * height * totalSize) / (sumRow * sumRow * width);
92 float aspectRatio = std::max(ratio, 1.0f / ratio);
93 if (aspectRatio > worstRatio)
94 worstRatio = aspectRatio;
105 std::vector<RTreeMapBase::Node> remainingChildren = children;
106 std::sort(remainingChildren.begin(), remainingChildren.end(),
108 std::vector<std::pair<RTreeMapBase::Node, RTreeMapBase::Rect>> result;
110 while (!remainingChildren.empty()) {
111 std::vector<RTreeMapBase::Node> row;
112 float currentWorstRatio = std::numeric_limits<float>::max();
113 float remainingWidth = rect.
fTopRight.
x - remainingBegin.
x;
114 float remainingHeight = rect.
fTopRight.
y - remainingBegin.
y;
115 if (remainingWidth <= 0 || remainingHeight <= 0)
117 while (!remainingChildren.empty()) {
118 row.push_back(remainingChildren.front());
119 remainingChildren.erase(remainingChildren.begin());
120 float newWorstRatio =
ComputeWorstRatio(row, remainingWidth, remainingHeight, totalSize, horizontalRows);
121 if (newWorstRatio > currentWorstRatio) {
122 remainingChildren.insert(remainingChildren.begin(), row.back());
126 currentWorstRatio = newWorstRatio;
129 for (
const auto &child : row)
130 sumRow += child.fSize;
133 float dimension = horizontalRows ? (
static_cast<float>(sumRow) / totalSize * height)
134 : (
static_cast<float>(sumRow) / totalSize * width);
135 float position = 0.0f;
136 for (
const auto &child : row) {
137 float childDimension =
static_cast<float>(child.fSize) / sumRow * (horizontalRows ? width : height);
143 ?
RTreeMapBase::Vec2{remainingBegin.
x + position + childDimension, remainingBegin.
y + dimension}
144 :
RTreeMapBase::Vec2{remainingBegin.
x + dimension, remainingBegin.
y + position + childDimension};
145 result.push_back({child, {childBegin, childEnd}});
146 position += childDimension;
149 remainingBegin.
y += dimension;
151 remainingBegin.
x += dimension;
161 const uint64_t totalSize =
fNodes[0].fSize;
166 for (
const auto &entry : diskOccupation) {
167 const auto &typeName = entry.first;
168 const uint64_t entrySize = entry.second;
172 const auto offset = 0.835f, factor = 0.05f;
173 const auto posY = offset - counter * factor;
177 const float percent = (entrySize /
static_cast<float>(totalSize)) * 100.0f;
180 float currOffset = 0.0125f;
181 for (
const auto &currContent : {typeName, content,
GetFloatStr(percent, 2) +
"%"}) {
196 AddBox(drawRect, boxColor, 0.15f);
205 float textSize = std::min(std::min(rectWidth, rectHeight) * 0.1f,
kTextSizeFactor);
213 std::vector<RTreeMapBase::Node> children;
214 for (std::uint64_t i = 0; i < element.
fNChildren; ++i)
216 uint64_t totalSize = 0;
217 for (
const auto &child : children)
218 totalSize += child.fSize;
223 bool horizontalRows = width > height;
224 auto childRects =
SquarifyChildren(children, innerRect, horizontalRows, totalSize);
225 for (
const auto &[child, childRect] : childRects)
static std::vector< std::pair< RTreeMapBase::Node, RTreeMapBase::Rect > > SquarifyChildren(const std::vector< RTreeMapBase::Node > &children, RTreeMapBase::Rect rect, bool horizontalRows, uint64_t totalSize)
static float ComputeWorstRatio(const std::vector< RTreeMapBase::Node > &row, float width, float height, uint64_t totalSize, bool horizontalRows)
virtual void AddText(const Vec2 &pos, const std::string &content, float size, const RGBColor &color=RGBColor(0, 0, 0), bool alignCenter=false) const =0
Logic for drawing a text.