Files
TelemetryMonitor/lib/layout/chart_config.dart
2026-04-21 14:40:09 -03:00

60 lines
1.5 KiB
Dart

import 'app_config_safe.dart';
enum YMode { auto, fixed, userZoomed }
YMode yModeFromString(String s) {
switch (s) {
case 'fixed': return YMode.fixed;
case 'userZoomed': return YMode.userZoomed;
case 'auto':
default: return YMode.auto;
}
}
String yModeToString(YMode m) {
switch (m) {
case YMode.auto: return 'auto';
case YMode.fixed: return 'fixed';
case YMode.userZoomed: return 'userZoomed';
}
}
/// Per-channel display configuration.
///
/// `channel` is the proto channel index (1..16). `enabled` toggles UI
/// visibility — disabled channels still record to the buffer and to CSV.
class ChartConfig {
ChartConfig({
required this.channel,
required this.name,
this.enabled = true,
this.yMode = YMode.auto,
this.yMin = AppConfigSafe.defaultYMin,
this.yMax = AppConfigSafe.defaultYMax,
});
final int channel;
String name;
bool enabled;
YMode yMode;
double yMin;
double yMax;
Map<String, dynamic> toJson() => {
'channel': channel,
'name': name,
'enabled': enabled,
'yMode': yModeToString(yMode),
'yMin': yMin,
'yMax': yMax,
};
static ChartConfig fromJson(Map<String, dynamic> j) => ChartConfig(
channel: j['channel'] as int,
name: j['name'] as String,
enabled: j['enabled'] as bool? ?? true,
yMode: yModeFromString(j['yMode'] as String? ?? 'auto'),
yMin: (j['yMin'] as num?)?.toDouble() ?? AppConfigSafe.defaultYMin,
yMax: (j['yMax'] as num?)?.toDouble() ?? AppConfigSafe.defaultYMax,
);
}