Skip to content

Commit

Permalink
#228 Polish the layouts sample with random and OrgTree layouts.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Aug 15, 2024
1 parent d1c9570 commit 93c8f7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
31 changes: 17 additions & 14 deletions samples/layouts/layouts.qml
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,39 @@ ApplicationWindow {
let n1 = graph.insertNode()
id: graphView
graphView.treeRoot = n1
n1.label = "n1"; n1.item.x=15; n1.item.y= 25
n1.label = "n1"; n1.item.x = 15; n1.item.y = 25
n1.item.ratio = 0.4

let n11 = graph.insertNode()
n11.label = "n11"; n11.item.x=15; n11.item.y= 125
let n12 = graph.insertNode()
n12.label = "n12"; n12.item.x=125; n12.item.y= 125
n11.label = "n11"; n11.item.x = 115; n11.item.y = 100
let n111 = graph.insertNode()
n111.label = "n111"; n111.item.x = 215; n111.item.y = 170
let n1111 = graph.insertNode()
n1111.label = "n1111"; n1111.item.x = 315; n1111.item.y = 240

let n12 = graph.insertNode()
n12.label = "n12"; n12.item.x = 115; n12.item.y= 310
let n121 = graph.insertNode()
n121.label = "n121"; n121.item.x=125; n121.item.y= 225
n121.label = "n121"; n121.item.x = 215; n121.item.y = 380
let n122 = graph.insertNode()
n122.label = "n122"; n122.item.x=225; n122.item.y= 225

let n1211 = graph.insertNode()
n1211.label = "n1211"; n1211.item.x=125; n1211.item.y= 225
n122.label = "n122"; n122.item.x = 215; n122.item.y = 450

let n13 = graph.insertNode()
n13.label = "n13"; n13.item.x=225; n13.item.y= 125
n13.label = "n13"; n13.item.x = 115; n13.item.y = 520
let n131 = graph.insertNode()
n131.label = "n131"; n131.item.x=225; n131.item.y= 125
n131.label = "n131"; n131.item.x = 225; n131.item.y = 590

graph.insertEdge(n1, n11)
graph.insertEdge(n1, n12)
graph.insertEdge(n1, n13)

graph.insertEdge(n11, n111)
graph.insertEdge(n111, n1111)

graph.insertEdge(n12, n121)
graph.insertEdge(n12, n122)
//graph.insertEdge(n121, n1211)
graph.insertEdge(n13, n131)

randomLayout.layout(n1);
graph.insertEdge(n13, n131)
}
Qan.OrgTreeLayout {
id: orgTreeLayout
Expand Down
5 changes: 2 additions & 3 deletions src/qanTreeLayouts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ void RandomLayout::layout(qan::Node& root) noexcept
if (node->getItem() == nullptr)
continue;
const auto nodeBr = node->getItem()->boundingRect();
qreal maxX = layoutRect.width() - nodeBr.width();
qreal maxY = layoutRect.height() - nodeBr.height();
// Generate and set random x and y positions within available area
qreal maxX = layoutRect.width() - nodeBr.width(); // Generate and set random x and y positions
qreal maxY = layoutRect.height() - nodeBr.height(); // within available layoutRect area
node->getItem()->setX(QRandomGenerator::global()->bounded(maxX) + layoutRect.left());
node->getItem()->setY(QRandomGenerator::global()->bounded(maxY) + layoutRect.top());
}
Expand Down

0 comments on commit 93c8f7f

Please sign in to comment.