mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
Graph Layout: Minor refactor
This commit is contained in:
@ -36,17 +36,7 @@ class _MyExampleWidgetState extends State<MyExampleWidget> {
|
|||||||
graph.edges = edges;
|
graph.edges = edges;
|
||||||
|
|
||||||
graph.assignRandomPositions(400, 650);
|
graph.assignRandomPositions(400, 650);
|
||||||
|
graph.startLayout();
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -230,6 +220,30 @@ class Graph extends ChangeNotifier {
|
|||||||
|
|
||||||
notifyListeners();
|
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());
|
void main() => runApp(MyApp());
|
||||||
|
Reference in New Issue
Block a user