Skip to content

Commit

Permalink
hard code chart units
Browse files Browse the repository at this point in the history
  • Loading branch information
o-bagge committed Jan 13, 2024
1 parent a37441c commit e6864f4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions open_earable/lib/sensor_data_tab/sensor_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class _EarableDataChartState extends State<EarableDataChart> {
late SimpleKalman kalmanX, kalmanY, kalmanZ;
late String _sensorName;
int _numDatapoints = 200;
Map<String, String> _units = {
"Accelerometer": "m/s\u00B2",
"Gyroscope": "°/s",
"Magnetometer": "µT",
"Pressure": "Pa",
"Temperature": "°C"
};
_setupListeners() {
if (_title == "Pressure" || _title == "Temperature") {
_dataSubscription =
Expand Down Expand Up @@ -168,7 +175,7 @@ class _EarableDataChartState extends State<EarableDataChart> {
if (_title == 'Pressure' || _title == 'Temperature') {
seriesList = [
charts.Series<SensorData, int>(
id: '$_title${_data.isNotEmpty ? " (${_data[0].units[_title]})" : ""}',
id: '$_title${_data.isNotEmpty ? " (${_units[_title]})" : ""}',
colorFn: (_, __) => charts.Color.fromHex(code: colors[0]),
domainFn: (SensorData data, _) => data.timestamp,
measureFn: (SensorData data, _) => data.values[0],
Expand All @@ -178,21 +185,21 @@ class _EarableDataChartState extends State<EarableDataChart> {
} else {
seriesList = [
charts.Series<SensorData, int>(
id: 'X${_data.isNotEmpty ? " (${_data[0].units['X']})" : ""}',
id: 'X${_data.isNotEmpty ? " (${_units[_title]})" : ""}',
colorFn: (_, __) => charts.Color.fromHex(code: colors[0]),
domainFn: (SensorData data, _) => data.timestamp,
measureFn: (SensorData data, _) => data.values[0],
data: _data,
),
charts.Series<SensorData, int>(
id: 'Y${_data.isNotEmpty ? " (${_data[0].units['Y']})" : ""}',
id: 'Y${_data.isNotEmpty ? " (${_units[_title]})" : ""}',
colorFn: (_, __) => charts.Color.fromHex(code: colors[1]),
domainFn: (SensorData data, _) => data.timestamp,
measureFn: (SensorData data, _) => data.values[1],
data: _data,
),
charts.Series<SensorData, int>(
id: 'Z${_data.isNotEmpty ? " (${_data[0].units['Z']})" : ""}',
id: 'Z${_data.isNotEmpty ? " (${_units[_title]})" : ""}',
colorFn: (_, __) => charts.Color.fromHex(code: colors[2]),
domainFn: (SensorData data, _) => data.timestamp,
measureFn: (SensorData data, _) => data.values[2],
Expand Down

0 comments on commit e6864f4

Please sign in to comment.