diff --git a/src/app/qt/utility/QtGraphPostprocessor.cpp b/src/app/qt/utility/QtGraphPostprocessor.cpp index 57cabd3c..391e8878 100644 --- a/src/app/qt/utility/QtGraphPostprocessor.cpp +++ b/src/app/qt/utility/QtGraphPostprocessor.cpp @@ -1,15 +1,14 @@ #include "QtGraphPostprocessor.h" -// remark: maybe those two values could at some point be moved to an external config file (?) -unsigned int QtGraphPostprocessor::s_cellSize = 5; -unsigned int QtGraphPostprocessor::s_cellPadding = 10; +#include "component/view/GraphViewStyle.h" + +unsigned int QtGraphPostprocessor::s_cellSize = GraphViewStyle::s_gridCellSize; +unsigned int QtGraphPostprocessor::s_cellPadding = GraphViewStyle::s_gridCellPadding; void QtGraphPostprocessor::doPostprocessing(std::list>& nodes) { unsigned int atomarGridSize = s_cellSize; - resizeNodes(nodes); - if (nodes.size() < 2) { LOG_WARNING_STREAM(<< "Skipping postprocessing, need at least 2 nodes but got " << nodes.size()); @@ -415,31 +414,6 @@ Vec2f QtGraphPostprocessor::heatMapRayCast(const MatrixDynamicBase return length; } -void QtGraphPostprocessor::resizeNodes(std::list>& nodes) -{ - std::list>::iterator it = nodes.begin(); - for (; it != nodes.end(); it++) - { - Vec2i size = (*it)->getSize(); - - int newWidth = s_cellSize; - while(size.x - newWidth > 3) - { - newWidth += s_cellPadding + s_cellSize; - } - size.x = newWidth; - - int newHeight = s_cellSize; - while(size.y - newHeight > 3) - { - newHeight += s_cellPadding + s_cellSize; - } - size.y = newHeight; - - (*it)->setSize(size); - } -} - Vec2i QtGraphPostprocessor::calculateRasterNodeSize(const std::shared_ptr& node) { Vec2i size = node->getSize(); diff --git a/src/app/qt/utility/QtGraphPostprocessor.h b/src/app/qt/utility/QtGraphPostprocessor.h index 07983fed..902c6614 100644 --- a/src/app/qt/utility/QtGraphPostprocessor.h +++ b/src/app/qt/utility/QtGraphPostprocessor.h @@ -26,7 +26,6 @@ private: static void modifyHeatmapArea(MatrixDynamicBase& heatMap, const Vec2i& leftUpperCorner, const Vec2i& size, const int modifier); static bool getHeatmapGradient(Vec2f& outGradient, const MatrixDynamicBase& heatMap, const Vec2i& leftUpperCorner, const Vec2i& size); static Vec2f heatMapRayCast(const MatrixDynamicBase& heatMap, const Vec2f& startPosition, const Vec2f& direction, const int minValue); - static void resizeNodes(std::list>& nodes); static Vec2i calculateRasterNodeSize(const std::shared_ptr& node); }; diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 2ee64584..86ebbfa1 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -375,6 +375,11 @@ void GraphController::layoutNesting() { layoutNestingRecursive(node); } + + for (DummyNode& node : m_dummyNodes) + { + layoutToGrid(node); + } } void GraphController::layoutNestingRecursive(DummyNode& node) const @@ -387,7 +392,7 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const } else if (node.isAccessNode()) { - margins = GraphViewStyle::getMarginsOfAccessNode(); + margins = GraphViewStyle::getMarginsOfAccessNode(node.accessType); } else if (node.isExpandToggleNode()) { @@ -474,7 +479,16 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const for (DummyNode& subNode : node.subNodes) { - if (subNode.isExpandToggleNode()) + if (!subNode.visible) + { + continue; + } + + if (subNode.isAccessNode()) + { + subNode.size.x = width; + } + else if (subNode.isExpandToggleNode()) { subNode.position.x = margins.left + width - subNode.size.x; subNode.position.y = 6; @@ -512,6 +526,48 @@ void GraphController::addExpandToggleNode(DummyNode& node) const node.subNodes.push_back(expandNode); } +void GraphController::layoutToGrid(DummyNode& node) const +{ + if (!node.isGraphNode()) + { + LOG_ERROR("Only GraphNodes can be layouted to the grid"); + return; + } + + size_t width = GraphViewStyle::toGridSize(node.size.x); + size_t height = GraphViewStyle::toGridSize(node.size.y); + + size_t incX = width - node.size.x; + size_t incY = height - node.size.y; + + node.size.x = width; + node.size.y = height; + + DummyNode* lastAccessNode = nullptr; + for (DummyNode& subNode : node.subNodes) + { + if (!subNode.visible) + { + continue; + } + + if (subNode.isAccessNode()) + { + subNode.size.x = subNode.size.x + incX; + lastAccessNode = &subNode; + } + else if (subNode.isExpandToggleNode()) + { + subNode.position.x = subNode.position.x + incX; + } + } + + if (lastAccessNode) + { + lastAccessNode->size.y = lastAccessNode->size.y + incY; + } +} + DummyNode* GraphController::findDummyNodeRecursive(std::vector& nodes, Id tokenId) { for (DummyNode& node : nodes) diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 13730214..2ed3d67e 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -54,6 +54,7 @@ private: void layoutNesting(); void layoutNestingRecursive(DummyNode& node) const; void addExpandToggleNode(DummyNode& node) const; + void layoutToGrid(DummyNode& node) const; DummyNode* findDummyNodeRecursive(std::vector& nodes, Id tokenId); DummyNode* findDummyNodeAccessRecursive(std::vector& nodes, Id parentId, TokenComponentAccess::AccessType type); diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index 4ea3e2d7..1f087887 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -125,7 +125,7 @@ std::string GraphViewStyle::getFontNameOfExpandToggleNode() GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType type, bool hasChildren) { NodeMargins margins; - margins.spacingX = 12; + margins.spacingX = 6; margins.spacingY = 8; switch (type) @@ -178,7 +178,7 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType return margins; } -GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode() +GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode(TokenComponentAccess::AccessType type) { NodeMargins margins; margins.spacingX = margins.spacingY = 8; @@ -187,7 +187,21 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode() margins.top = 40; margins.bottom = 10; - margins.minWidth = 82; + switch (type) + { + case TokenComponentAccess::ACCESS_NONE: + margins.minWidth = 30; + break; + case TokenComponentAccess::ACCESS_PUBLIC: + margins.minWidth = 56; + break; + case TokenComponentAccess::ACCESS_PROTECTED: + margins.minWidth = 80; + break; + case TokenComponentAccess::ACCESS_PRIVATE: + margins.minWidth = 64; + break; + } return margins; } @@ -402,5 +416,20 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(Edge::EdgeType typ return style; } +size_t GraphViewStyle::toGridSize(size_t x) +{ + size_t r = s_gridCellSize; + + while (r < x - 1) + { + r += s_gridCellPadding + s_gridCellSize; + } + + return r; +} + +size_t GraphViewStyle::s_gridCellSize = 5; +size_t GraphViewStyle::s_gridCellPadding = 10; + std::map GraphViewStyle::s_charWidths; std::shared_ptr GraphViewStyle::s_impl; diff --git a/src/lib/component/view/GraphViewStyle.h b/src/lib/component/view/GraphViewStyle.h index 154ccb67..98eeef35 100644 --- a/src/lib/component/view/GraphViewStyle.h +++ b/src/lib/component/view/GraphViewStyle.h @@ -7,6 +7,7 @@ #include "component/view/graphElements/GraphNode.h" #include "component/view/GraphViewStyleImpl.h" #include "data/graph/Node.h" +#include "data/graph/token_component/TokenComponentAccess.h" class GraphViewStyle { @@ -88,7 +89,7 @@ public: static std::string getFontNameOfExpandToggleNode(); static NodeMargins getMarginsForNodeType(Node::NodeType type, bool hasChildren); - static NodeMargins getMarginsOfAccessNode(); + static NodeMargins getMarginsOfAccessNode(TokenComponentAccess::AccessType type); static NodeMargins getMarginsOfExpandToggleNode(); static NodeStyle getStyleForNodeType(Node::NodeType type, bool isActive, bool isFocused, bool hasChildren); @@ -97,6 +98,11 @@ public: static EdgeStyle getStyleForEdgeType(Edge::EdgeType type, bool isActive, bool isFocused); + static size_t toGridSize(size_t x); + + static size_t s_gridCellSize; + static size_t s_gridCellPadding; + private: static std::map s_charWidths; static std::shared_ptr s_impl;