Skip to content

Commit

Permalink
Added option to change default period and graph period
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Dec 18, 2023
1 parent 6231988 commit 5f2074d
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 157 deletions.
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ void main() async {
preferences.getDouble(PrefKeys.cornerRadius) ?? Settings.cornerRadius;
Settings.autoResizeToDS =
preferences.getBool(PrefKeys.autoResizeToDS) ?? Settings.autoResizeToDS;
Settings.defaultPeriod =
preferences.getDouble(PrefKeys.defaultPeriod) ?? Settings.defaultPeriod;
Settings.defaultGraphPeriod =
preferences.getDouble(PrefKeys.defaultGraphPeriod) ??
Settings.defaultGraphPeriod;

NTWidgetBuilder.ensureInitialized();

Expand Down
28 changes: 28 additions & 0 deletions lib/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,34 @@ class _DashboardPageState extends State<DashboardPage> with WindowListener {

await _preferences.setBool(PrefKeys.autoResizeToDS, value);
},
onDefaultPeriodChanged: (value) async {
if (value == null) {
return;
}
double? newPeriod = double.tryParse(value);

if (newPeriod == null) {
return;
}

await _preferences.setDouble(PrefKeys.defaultPeriod, newPeriod);

setState(() => Settings.defaultPeriod = newPeriod);
},
onDefaultGraphPeriodChanged: (value) async {
if (value == null) {
return;
}
double? newPeriod = double.tryParse(value);

if (newPeriod == null) {
return;
}

await _preferences.setDouble(PrefKeys.defaultGraphPeriod, newPeriod);

setState(() => Settings.defaultGraphPeriod = newPeriod);
},
onColorChanged: widget.onColorChanged,
),
);
Expand Down
4 changes: 3 additions & 1 deletion lib/services/nt_widget_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ class NTWidgetBuilder {
String type,
String topic, {
String dataType = 'Unknown',
double period = Settings.defaultPeriod,
double? period,
}) {
period ??= Settings.defaultPeriod;

ensureInitialized();

if (_widgetNameBuildMap.containsKey(type)) {
Expand Down
6 changes: 4 additions & 2 deletions lib/services/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Settings {
static bool isWindowDraggable = true;
static bool isWindowMaximizable = true;

static const double defaultPeriod = 0.1;
static const double defaultGraphPeriod = 0.033;
static double defaultPeriod = 0.1;
static double defaultGraphPeriod = 0.033;
}

class PrefKeys {
Expand All @@ -33,4 +33,6 @@ class PrefKeys {
static String cornerRadius = 'corner_radius';
static String showGrid = 'show_grid';
static String autoResizeToDS = 'auto_resize_to_driver_station';
static String defaultPeriod = 'default_period';
static String defaultGraphPeriod = 'default_graph_period';
}
4 changes: 3 additions & 1 deletion lib/widgets/nt_widgets/nt_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ abstract class NTWidget extends StatelessWidget {
super.key,
required this.topic,
this.dataType = 'Unknown',
this.period = Settings.defaultPeriod,
double? period,
}) {
this.period = period ?? Settings.defaultPeriod;

init();
}

Expand Down
3 changes: 1 addition & 2 deletions lib/widgets/nt_widgets/single_topic/graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:provider/provider.dart';
import 'package:syncfusion_flutter_charts/charts.dart';

import 'package:elastic_dashboard/services/nt4_client.dart';
import 'package:elastic_dashboard/services/settings.dart';
import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_color_picker.dart';
import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_text_input.dart';
import 'package:elastic_dashboard/widgets/nt_widgets/nt_widget.dart';
Expand All @@ -34,7 +33,7 @@ class GraphWidget extends NTWidget {
this.maxValue,
this.mainColor = Colors.cyan,
super.dataType,
super.period = Settings.defaultGraphPeriod,
super.period,
}) : super();

GraphWidget.fromJson({super.key, required Map<String, dynamic> jsonData})
Expand Down
Loading

0 comments on commit 5f2074d

Please sign in to comment.