mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-29 01:18:35 +01:00
Keep the chart tooltips inside the chart
This commit is contained in:
@@ -355,6 +355,10 @@ class MeasurementChartWidgetFl extends StatelessWidget {
|
||||
LineTouchData tooltipData(BuildContext context, Set<int> hidden, Map<int, String?> labels) {
|
||||
return LineTouchData(
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
// Kept inside the chart, else the points near an edge show a tooltip
|
||||
// that is cut off by it, or lies outside it entirely
|
||||
fitInsideHorizontally: true,
|
||||
fitInsideVertically: true,
|
||||
getTooltipColor: (touchedSpot) => Theme.of(context).colorScheme.primaryContainer,
|
||||
getTooltipItems: (touchedSpots) {
|
||||
// The plan context belongs to the touched date, not to a series, so
|
||||
@@ -534,6 +538,10 @@ class MeasurementBarChartWidgetFl extends StatelessWidget {
|
||||
BarTouchData tooltipData(BuildContext context) {
|
||||
return BarTouchData(
|
||||
touchTooltipData: BarTouchTooltipData(
|
||||
// Kept inside the chart, else the bars near an edge show a
|
||||
// tooltip that is cut off by it, or lies outside it entirely
|
||||
fitInsideHorizontally: true,
|
||||
fitInsideVertically: true,
|
||||
getTooltipColor: (group) => Theme.of(context).colorScheme.primaryContainer,
|
||||
getTooltipItem: (group, groupIndex, rod, rodIndex) {
|
||||
if (groupIndex < 0 || groupIndex >= _entries.length) {
|
||||
@@ -660,6 +668,10 @@ class MeasurementStackedBarChartWidgetFl extends StatelessWidget {
|
||||
BarTouchData tooltipData(BuildContext context) {
|
||||
return BarTouchData(
|
||||
touchTooltipData: BarTouchTooltipData(
|
||||
// Kept inside the chart, else the bars near an edge show a
|
||||
// tooltip that is cut off by it, or lies outside it entirely
|
||||
fitInsideHorizontally: true,
|
||||
fitInsideVertically: true,
|
||||
getTooltipColor: (group) => Theme.of(context).colorScheme.primaryContainer,
|
||||
getTooltipItem: (group, groupIndex, rod, rodIndex) {
|
||||
if (groupIndex < 0 || groupIndex >= _entries.length) {
|
||||
|
||||
@@ -56,6 +56,23 @@ void main() {
|
||||
expect(find.byType(BarChart), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the tooltip stays inside the chart', (tester) async {
|
||||
// Without this the reading at either end shows a tooltip that is cut
|
||||
// off by the chart edge, or lies outside it altogether
|
||||
await tester.pumpWidget(
|
||||
_wrap(MeasurementBarChartWidgetFl([entry(1000, DateTime(2026, 1, 1))], 'steps')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final tooltip = tester
|
||||
.widget<BarChart>(find.byType(BarChart))
|
||||
.data
|
||||
.barTouchData
|
||||
.touchTooltipData;
|
||||
expect(tooltip.fitInsideHorizontally, isTrue);
|
||||
expect(tooltip.fitInsideVertically, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('only labels a few dates on the x axis', (tester) async {
|
||||
final entries = List.generate(
|
||||
40,
|
||||
|
||||
Reference in New Issue
Block a user