Hi thanks, I must apologies I haven't looked closely at the 40000 chips demo, I did play with it a while back and was impressed, I'm trying to get the pyqt version so I can have more of a play, I didn't realise that you could drag the chips around. I did see the zooming
However, I have found an example that's much closer to what I'm doing http://doc.qt.io/qt-5/qtwidgets-grap...s-example.html
This is the elastic nodes. I have got the pyqt version but in essence it works great, very fluid and dynamic, however I believe it will slow right down when there are 2000+ nodes and edges.
I suspect that
// Sum up all forces pushing this item away
qreal xvel = 0;
qreal yvel = 0;
Node *node = qgraphicsitem_cast<Node *>(item);
if (!node)
continue;
QPointF vec
= mapToItem
(node,
0,
0);
qreal dx = vec.x();
qreal dy = vec.y();
double l = 2.0 * (dx * dx + dy * dy);
if (l > 0) {
xvel += (dx * 150.0) / l;
yvel += (dy * 150.0) / l;
}
}
// Sum up all forces pushing this item away
qreal xvel = 0;
qreal yvel = 0;
foreach (QGraphicsItem *item, scene()->items()) {
Node *node = qgraphicsitem_cast<Node *>(item);
if (!node)
continue;
QPointF vec = mapToItem(node, 0, 0);
qreal dx = vec.x();
qreal dy = vec.y();
double l = 2.0 * (dx * dx + dy * dy);
if (l > 0) {
xvel += (dx * 150.0) / l;
yvel += (dy * 150.0) / l;
}
}
To copy to clipboard, switch view to plain text mode
...
// Now subtract all forces pulling items together
double weight = (edgeList.size() + 1) * 10;
foreach (Edge *edge, edgeList) {
if (edge->sourceNode() == this)
vec = mapToItem(edge->destNode(), 0, 0);
else
vec = mapToItem(edge->sourceNode(), 0, 0);
xvel -= vec.x() / weight;
yvel -= vec.y() / weight;
}
// Now subtract all forces pulling items together
double weight = (edgeList.size() + 1) * 10;
foreach (Edge *edge, edgeList) {
QPointF vec;
if (edge->sourceNode() == this)
vec = mapToItem(edge->destNode(), 0, 0);
else
vec = mapToItem(edge->sourceNode(), 0, 0);
xvel -= vec.x() / weight;
yvel -= vec.y() / weight;
}
To copy to clipboard, switch view to plain text mode
...
QRectF sceneRect
= scene
()->sceneRect
();
newPos
= pos
() + QPointF(xvel, yvel
);
newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10));
newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10));
}
QRectF sceneRect = scene()->sceneRect();
newPos = pos() + QPointF(xvel, yvel);
newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10));
newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10));
}
To copy to clipboard, switch view to plain text mode
These for_each loops may be fine when the number of nodes isn't many but as the number of nodes grows that loop may become a performance issue. As the positions of each node as well as each edge needs recalculating. I hope this demonstrates better what I'm doing and where I am struggling. maybe it works better in C but in python/pyqt I bet its noticeably slower when the scene is busy. I have to confess that I haven't tried the elastic nodes with 100000 nodes though, can anyone say that its still fast and smooth?
Bookmarks