mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 11:33:34 +08:00
GraphView: Start layouting on moving the nodes
This is awesome. It's exactly what I wanted. The graph layout algorithm will need to be improved, but this is already quite usable.
This commit is contained in:
@ -112,6 +112,7 @@ class Graph extends ChangeNotifier {
|
||||
|
||||
void notify() {
|
||||
notifyListeners();
|
||||
startLayout();
|
||||
}
|
||||
|
||||
List<int> computeNeighbours(Node n) {
|
||||
@ -189,18 +190,20 @@ class Graph extends ChangeNotifier {
|
||||
const interval = Duration(milliseconds: 25);
|
||||
layoutTimer = Timer.periodic(interval, (Timer t) {
|
||||
bool shouldStop = updateGraphPositions(this);
|
||||
print("shouldStop $shouldStop");
|
||||
if (shouldStop) {
|
||||
layoutTimer.cancel();
|
||||
layoutTimer = null;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
Timer(const Duration(seconds: 5), () {
|
||||
if (layoutTimer != null) {
|
||||
layoutTimer.cancel();
|
||||
layoutTimer = null;
|
||||
}
|
||||
});
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,6 +326,11 @@ bool updateGraphPositions(Graph g) {
|
||||
for (var i = 0; i < numNodes; i++) {
|
||||
var node = g.nodes[i];
|
||||
|
||||
// Skip Node which is current being controlled
|
||||
if (node.pressed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var dx = delta_t * node.forceX;
|
||||
var dy = delta_t * node.forceY;
|
||||
|
||||
@ -493,12 +501,15 @@ class _GraphStackViewState extends State<GraphStackView> {
|
||||
onPanStart: (details) {
|
||||
node.x = details.globalPosition.dx;
|
||||
node.y = details.globalPosition.dy;
|
||||
node.pressed = true;
|
||||
|
||||
widget.graph.notify();
|
||||
print("Pan start ${node.label} $details");
|
||||
},
|
||||
onPanEnd: (DragEndDetails details) {
|
||||
print("Pan end ${node.label} $details");
|
||||
node.pressed = false;
|
||||
widget.graph.notify();
|
||||
},
|
||||
onPanUpdate: (details) {
|
||||
node.x = details.globalPosition.dx;
|
||||
|
Reference in New Issue
Block a user