ui: Improved graph layouting to properly place and resize subnodes

This change moves the toplevel node resizing from the QtPostProcessor to the GraphController to place and resize their
subnodes accordingly as well.
This commit is contained in:
Eberhard Graether
2015-04-30 16:25:24 +02:00
parent 749b1647e4
commit aa0c40b213
6 changed files with 102 additions and 37 deletions
+4 -30
View File
@@ -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<std::shared_ptr<QtGraphNode>>& 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<unsigned int>
return length;
}
void QtGraphPostprocessor::resizeNodes(std::list<std::shared_ptr<QtGraphNode>>& nodes)
{
std::list<std::shared_ptr<QtGraphNode>>::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<QtGraphNode>& node)
{
Vec2i size = node->getSize();
@@ -26,7 +26,6 @@ private:
static void modifyHeatmapArea(MatrixDynamicBase<unsigned int>& heatMap, const Vec2i& leftUpperCorner, const Vec2i& size, const int modifier);
static bool getHeatmapGradient(Vec2f& outGradient, const MatrixDynamicBase<unsigned int>& heatMap, const Vec2i& leftUpperCorner, const Vec2i& size);
static Vec2f heatMapRayCast(const MatrixDynamicBase<unsigned int>& heatMap, const Vec2f& startPosition, const Vec2f& direction, const int minValue);
static void resizeNodes(std::list<std::shared_ptr<QtGraphNode>>& nodes);
static Vec2i calculateRasterNodeSize(const std::shared_ptr<QtGraphNode>& node);
};
@@ -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<DummyNode>& nodes, Id tokenId)
{
for (DummyNode& node : nodes)
@@ -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<DummyNode>& nodes, Id tokenId);
DummyNode* findDummyNodeAccessRecursive(std::vector<DummyNode>& nodes, Id parentId, TokenComponentAccess::AccessType type);
+32 -3
View File
@@ -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<Node::NodeType, float> GraphViewStyle::s_charWidths;
std::shared_ptr<GraphViewStyleImpl> GraphViewStyle::s_impl;
+7 -1
View File
@@ -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<Node::NodeType, float> s_charWidths;
static std::shared_ptr<GraphViewStyleImpl> s_impl;