ui: sort buckets in graph layout alphabetically and put bundles at end

This commit is contained in:
Eberhard Graether
2016-05-17 14:28:22 +02:00
parent 67e4d84631
commit 79f788db2e
7 changed files with 54 additions and 33 deletions
@@ -6,8 +6,7 @@
#include "utility/utility.h"
#include "utility/utilityString.h"
#include "component/controller/helper/GraphLayouter.h"
#include "component/controller/helper/GraphPostprocessor.h"
#include "component/controller/helper/BucketGrid.h"
#include "component/view/GraphView.h"
#include "component/view/GraphViewStyle.h"
#include "data/access/StorageAccess.h"
@@ -75,7 +74,7 @@ void GraphController::handleMessage(MessageActivateTokens* message)
}
layoutNesting();
layoutGraph();
layoutGraph(true);
buildGraph(message);
}
@@ -126,7 +125,7 @@ void GraphController::handleMessage(MessageGraphNodeBundleSplit* message)
setActiveAndVisibility(utility::concat(m_activeNodeIds, m_activeEdgeIds));
layoutNesting();
layoutGraph();
layoutGraph(true);
buildGraph(message);
}
@@ -1033,12 +1032,17 @@ void GraphController::layoutToGrid(DummyNode& node) const
}
}
void GraphController::layoutGraph()
void GraphController::layoutGraph(bool sort)
{
// GraphLayouter::layoutSpectralPrototype(m_dummyNodes, m_dummyEdges);
// GraphPostprocessor::doPostprocessing(m_dummyNodes);
BucketGrid grid(getView()->getViewSize());
grid.createBuckets(m_dummyNodes, m_dummyEdges);
GraphLayouter::layoutBucket(m_dummyNodes, m_dummyEdges, getView()->getViewSize());
if (sort)
{
grid.sortBuckets();
}
grid.layoutBuckets();
}
DummyNode* GraphController::findDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId) const
@@ -81,7 +81,7 @@ private:
void addExpandToggleNode(DummyNode& node) const;
void layoutToGrid(DummyNode& node) const;
void layoutGraph();
void layoutGraph(bool sort = false);
DummyNode* findDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId) const;
DummyNode* findTopLevelDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId) const;
@@ -1,5 +1,7 @@
#include "component/controller/helper/BucketGrid.h"
#include "utility/utilityString.h"
#include "component/controller/helper/DummyEdge.h"
#include "component/controller/helper/DummyNode.h"
#include "component/view/GraphViewStyle.h"
@@ -51,6 +53,27 @@ void Bucket::addNode(DummyNode* node)
m_height += node->size.y + GraphViewStyle::toGridGap(10);
}
void Bucket::sort()
{
std::sort(m_nodes.begin(), m_nodes.end(),
[](const DummyNode* a, const DummyNode* b) -> bool
{
if ((a->isGraphNode() && b->isGraphNode()) || (a->isBundleNode() && b->isBundleNode()))
{
return utility::toLowerCase(a->name) < utility::toLowerCase(b->name);
}
else if (a->isGraphNode())
{
return true;
}
else
{
return false;
}
}
);
}
void Bucket::preLayout(Vec2i viewSize)
{
int cols = m_height / viewSize.y + 1;
@@ -76,7 +99,7 @@ void Bucket::preLayout(Vec2i viewSize)
{
y = 0;
x += width + GraphViewStyle::toGridGap(25);
x += width + GraphViewStyle::toGridGap(30);
width = 0;
}
}
@@ -97,13 +120,6 @@ void Bucket::layout(int x, int y, int width, int height)
}
void BucketGrid::layout(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges, Vec2i viewSize)
{
BucketGrid grid(viewSize);
grid.createBuckets(nodes, edges);
grid.layoutBuckets();
}
BucketGrid::BucketGrid(Vec2i viewSize)
: m_viewSize(viewSize)
, m_i1(0)
@@ -187,6 +203,17 @@ void BucketGrid::createBuckets(std::vector<DummyNode>& nodes, const std::vector<
}
}
void BucketGrid::sortBuckets()
{
for (int j = m_j1; j <= m_j2; j++)
{
for (int i = m_i1; i <= m_i2; i++)
{
m_buckets[j][i].sort();
}
}
}
void BucketGrid::layoutBuckets()
{
std::map<int, int> widths;
@@ -23,6 +23,8 @@ public:
bool hasNode(DummyNode* node) const;
void addNode(DummyNode* node);
void sort();
void preLayout(Vec2i viewSize);
void layout(int x, int y, int width, int height);
@@ -40,16 +42,12 @@ private:
class BucketGrid
{
public:
static void layout(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges, Vec2i viewSize);
private:
static const Edge::EdgeTypeMask s_verticalEdgeMask;
BucketGrid(Vec2i viewSize);
void createBuckets(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges);
void sortBuckets();
void layoutBuckets();
private:
DummyNode* findTopMostDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId, DummyNode* top = nullptr);
void addNode(DummyNode* node);
@@ -4,7 +4,6 @@
#include <map>
#include <queue>
#include "component/controller/helper/BucketGrid.h"
#include "component/controller/helper/DummyEdge.h"
#include "component/controller/helper/DummyNode.h"
#include "data/graph/Node.h"
@@ -64,11 +63,6 @@ void GraphLayouter::layoutSimpleRing(std::vector<DummyNode>& nodes)
}
}
void GraphLayouter::layoutBucket(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges, Vec2i viewSize)
{
BucketGrid::layout(nodes, edges, viewSize);
}
void GraphLayouter::layoutSpectralPrototype(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges)
{
if (nodes.size() < 2)
@@ -16,8 +16,6 @@ public:
static void layoutSimpleRaster(std::vector<DummyNode>& nodes);
static void layoutSimpleRing(std::vector<DummyNode>& nodes);
static void layoutBucket(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges, Vec2i viewSize);
static void layoutSpectralPrototype(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges);
private:
+2 -2
View File
@@ -436,8 +436,8 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(Edge::EdgeType typ
style.width = 2;
style.arrowLength = 7;
style.arrowWidth = 10;
style.originOffset.x = 22;
style.targetOffset.x = 22;
style.originOffset.x = 24;
style.targetOffset.x = 24;
style.originOffset.y = 0;
style.targetOffset.y = 0;
style.verticalOffset = 0;