Skip to content

Commit

Permalink
Show both axes values in plot touch events (#401)
Browse files Browse the repository at this point in the history
* Show both axes values in plot touch events

* Linted code
  • Loading branch information
andreped authored Jan 6, 2025
1 parent a3d747f commit ea932e4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/core/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ class DatabaseHelper {
file_path = '${directory.path}/backup_database.db';
} else if (Platform.isAndroid) {
file_path = '/storage/emulated/0/Download/backup_database.db';

// Use file picker to select the backup file
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.any,
Expand All @@ -620,7 +620,7 @@ class DatabaseHelper {
} else {
throw Exception('Unsupported platform');
}

// Check if the backup file exists
File selectedFile = File(file_path);
if (!await selectedFile.exists()) {
Expand Down
4 changes: 1 addition & 3 deletions lib/tabs/visualization_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ class VisualizationTabState extends State<VisualizationTab> {
if (_selectedTable == 'Fitness') {
switch (_dataType) {
case 'Weight':
return widget.isKg
? value
: value * 2.20462;
return widget.isKg ? value : value * 2.20462;
case 'Height':
return value; // Assuming height is already in the desired unit
case 'Age':
Expand Down
30 changes: 29 additions & 1 deletion lib/widgets/charts/chart_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,21 @@ class ChartWidget extends StatelessWidget {
);
},
),
lineTouchData: const LineTouchData(
lineTouchData: LineTouchData(
enabled: true,
handleBuiltInTouches: true,
touchTooltipData: LineTouchTooltipData(
tooltipMargin: 8,
tooltipHorizontalAlignment: FLHorizontalAlignment.left,
getTooltipItems: (List<LineBarSpot> touchedSpots) {
return touchedSpots.map((touchedSpot) {
return LineTooltipItem(
_formatTooltip(touchedSpot.x, touchedSpot.y),
TextStyle(color: Colors.white),
);
}).toList();
},
),
),
),
);
Expand Down Expand Up @@ -217,6 +229,16 @@ class ChartWidget extends StatelessWidget {
scatterTouchData: ScatterTouchData(
enabled: true,
handleBuiltInTouches: true,
touchTooltipData: ScatterTouchTooltipData(
getTooltipColor: (ScatterSpot spot) => Colors.blueGrey,
tooltipHorizontalAlignment: FLHorizontalAlignment.left,
getTooltipItems: (ScatterSpot touchedSpot) {
return ScatterTooltipItem(
_formatTooltip(touchedSpot.x, touchedSpot.y),
textStyle: TextStyle(color: Colors.white),
);
},
),
),
),
);
Expand All @@ -238,4 +260,10 @@ class ChartWidget extends StatelessWidget {
),
);
}

String _formatTooltip(double x, double y) {
final date = DateTime.now().add(Duration(days: x.toInt()));
final formattedDate = DateFormat('dd/MM').format(date);
return 'x=$formattedDate\ny=${y.toStringAsFixed(2)}';
}
}
16 changes: 4 additions & 12 deletions lib/widgets/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ class SettingsModalState extends State<SettingsModal> {
value: _appTheme,
style: TextStyle(
fontSize: 14,
color: isDarkMode
? Colors.purple
: Colors.black,
color: isDarkMode ? Colors.purple : Colors.black,
),
items: const [
DropdownMenuItem(
Expand Down Expand Up @@ -287,9 +285,7 @@ class SettingsModalState extends State<SettingsModal> {
child: Text(
_isKg ? 'kg' : 'lbs',
style: TextStyle(
color: Theme.of(context)
.colorScheme
.primary,
color: Theme.of(context).colorScheme.primary,
fontSize: 16,
),
),
Expand Down Expand Up @@ -324,9 +320,7 @@ class SettingsModalState extends State<SettingsModal> {
value: _aggregationMethod,
style: TextStyle(
fontSize: 14,
color: isDarkMode
? Colors.purple
: Colors.black,
color: isDarkMode ? Colors.purple : Colors.black,
),
items: const [
DropdownMenuItem(
Expand Down Expand Up @@ -366,9 +360,7 @@ class SettingsModalState extends State<SettingsModal> {
value: _plotType,
style: TextStyle(
fontSize: 14,
color: isDarkMode
? Colors.purple
: Colors.black,
color: isDarkMode ? Colors.purple : Colors.black,
),
items: const [
DropdownMenuItem(
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: IronFlow
description: "Strength training and fitness app for mobile devices."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 0.12.1+61
version: 0.12.2+62

environment:
sdk: '>=3.4.3 <4.0.0'
Expand Down Expand Up @@ -30,7 +30,7 @@ dependencies:
permission_handler: ^11.3.1

# visualization
fl_chart: ^0.68.0
fl_chart: ^0.70.0

# settings (to remember user settings)
shared_preferences: ^2.0.6
Expand Down

0 comments on commit ea932e4

Please sign in to comment.