mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
Graph Layout: Minor refactor
This commit is contained in:
@ -36,17 +36,7 @@ class _MyExampleWidgetState extends State<MyExampleWidget> {
|
||||
graph.edges = edges;
|
||||
|
||||
graph.assignRandomPositions(400, 650);
|
||||
|
||||
const interval = Duration(milliseconds: 25);
|
||||
bool shouldStop = false;
|
||||
var timer = Timer.periodic(interval, (Timer t) {
|
||||
if (shouldStop) {
|
||||
return;
|
||||
}
|
||||
shouldStop = updateGraphPositions(graph);
|
||||
});
|
||||
|
||||
Timer(const Duration(seconds: 5), () => timer.cancel());
|
||||
graph.startLayout();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -230,6 +220,30 @@ class Graph extends ChangeNotifier {
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Timer layoutTimer;
|
||||
|
||||
void startLayout() {
|
||||
if (layoutTimer != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const interval = Duration(milliseconds: 25);
|
||||
layoutTimer = Timer.periodic(interval, (Timer t) {
|
||||
bool shouldStop = updateGraphPositions(this);
|
||||
if (shouldStop) {
|
||||
layoutTimer.cancel();
|
||||
layoutTimer = null;
|
||||
}
|
||||
});
|
||||
|
||||
Timer(const Duration(seconds: 5), () {
|
||||
if (layoutTimer != null) {
|
||||
layoutTimer.cancel();
|
||||
layoutTimer = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
Reference in New Issue
Block a user