mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 12:23:44 +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() {
|
void notify() {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
startLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> computeNeighbours(Node n) {
|
List<int> computeNeighbours(Node n) {
|
||||||
@ -189,18 +190,20 @@ class Graph extends ChangeNotifier {
|
|||||||
const interval = Duration(milliseconds: 25);
|
const interval = Duration(milliseconds: 25);
|
||||||
layoutTimer = Timer.periodic(interval, (Timer t) {
|
layoutTimer = Timer.periodic(interval, (Timer t) {
|
||||||
bool shouldStop = updateGraphPositions(this);
|
bool shouldStop = updateGraphPositions(this);
|
||||||
|
print("shouldStop $shouldStop");
|
||||||
if (shouldStop) {
|
if (shouldStop) {
|
||||||
layoutTimer.cancel();
|
layoutTimer.cancel();
|
||||||
layoutTimer = null;
|
layoutTimer = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
Timer(const Duration(seconds: 5), () {
|
Timer(const Duration(seconds: 5), () {
|
||||||
if (layoutTimer != null) {
|
if (layoutTimer != null) {
|
||||||
layoutTimer.cancel();
|
layoutTimer.cancel();
|
||||||
layoutTimer = null;
|
layoutTimer = null;
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +326,11 @@ bool updateGraphPositions(Graph g) {
|
|||||||
for (var i = 0; i < numNodes; i++) {
|
for (var i = 0; i < numNodes; i++) {
|
||||||
var node = g.nodes[i];
|
var node = g.nodes[i];
|
||||||
|
|
||||||
|
// Skip Node which is current being controlled
|
||||||
|
if (node.pressed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var dx = delta_t * node.forceX;
|
var dx = delta_t * node.forceX;
|
||||||
var dy = delta_t * node.forceY;
|
var dy = delta_t * node.forceY;
|
||||||
|
|
||||||
@ -493,12 +501,15 @@ class _GraphStackViewState extends State<GraphStackView> {
|
|||||||
onPanStart: (details) {
|
onPanStart: (details) {
|
||||||
node.x = details.globalPosition.dx;
|
node.x = details.globalPosition.dx;
|
||||||
node.y = details.globalPosition.dy;
|
node.y = details.globalPosition.dy;
|
||||||
|
node.pressed = true;
|
||||||
|
|
||||||
widget.graph.notify();
|
widget.graph.notify();
|
||||||
print("Pan start ${node.label} $details");
|
print("Pan start ${node.label} $details");
|
||||||
},
|
},
|
||||||
onPanEnd: (DragEndDetails details) {
|
onPanEnd: (DragEndDetails details) {
|
||||||
print("Pan end ${node.label} $details");
|
print("Pan end ${node.label} $details");
|
||||||
|
node.pressed = false;
|
||||||
|
widget.graph.notify();
|
||||||
},
|
},
|
||||||
onPanUpdate: (details) {
|
onPanUpdate: (details) {
|
||||||
node.x = details.globalPosition.dx;
|
node.x = details.globalPosition.dx;
|
||||||
|
Reference in New Issue
Block a user