diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 2d5ad046..0f73d18d 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -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& nodes, Id tokenId) const diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 9b7cbcf3..478fc9f8 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -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& nodes, Id tokenId) const; DummyNode* findTopLevelDummyNodeRecursive(std::vector& nodes, Id tokenId) const; diff --git a/src/lib/component/controller/helper/BucketGrid.cpp b/src/lib/component/controller/helper/BucketGrid.cpp index 5d7a4fe9..778978a4 100644 --- a/src/lib/component/controller/helper/BucketGrid.cpp +++ b/src/lib/component/controller/helper/BucketGrid.cpp @@ -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& nodes, const std::vector& 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& 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 widths; diff --git a/src/lib/component/controller/helper/BucketGrid.h b/src/lib/component/controller/helper/BucketGrid.h index 137cf055..8ff7efd4 100644 --- a/src/lib/component/controller/helper/BucketGrid.h +++ b/src/lib/component/controller/helper/BucketGrid.h @@ -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& nodes, const std::vector& edges, Vec2i viewSize); - -private: - static const Edge::EdgeTypeMask s_verticalEdgeMask; - BucketGrid(Vec2i viewSize); - void createBuckets(std::vector& nodes, const std::vector& edges); + void sortBuckets(); void layoutBuckets(); +private: DummyNode* findTopMostDummyNodeRecursive(std::vector& nodes, Id tokenId, DummyNode* top = nullptr); void addNode(DummyNode* node); diff --git a/src/lib/component/controller/helper/GraphLayouter.cpp b/src/lib/component/controller/helper/GraphLayouter.cpp index be9ba675..34af8310 100644 --- a/src/lib/component/controller/helper/GraphLayouter.cpp +++ b/src/lib/component/controller/helper/GraphLayouter.cpp @@ -4,7 +4,6 @@ #include #include -#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& nodes) } } -void GraphLayouter::layoutBucket(std::vector& nodes, const std::vector& edges, Vec2i viewSize) -{ - BucketGrid::layout(nodes, edges, viewSize); -} - void GraphLayouter::layoutSpectralPrototype(std::vector& nodes, const std::vector& edges) { if (nodes.size() < 2) diff --git a/src/lib/component/controller/helper/GraphLayouter.h b/src/lib/component/controller/helper/GraphLayouter.h index 45bb0cea..54d284a3 100644 --- a/src/lib/component/controller/helper/GraphLayouter.h +++ b/src/lib/component/controller/helper/GraphLayouter.h @@ -16,8 +16,6 @@ public: static void layoutSimpleRaster(std::vector& nodes); static void layoutSimpleRing(std::vector& nodes); - static void layoutBucket(std::vector& nodes, const std::vector& edges, Vec2i viewSize); - static void layoutSpectralPrototype(std::vector& nodes, const std::vector& edges); private: diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index 42140f35..02fb316f 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -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;