Skip to content

Commit

Permalink
Fix tooltips problem
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Mar 3, 2021
1 parent 07b8701 commit 0866e07
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,15 @@ class BarTouchTooltipData with EquatableMixin {
/// You can override [BarTouchTooltipData.getTooltipItem], it gives you
/// [group], [groupIndex], [rod], and [rodIndex] that touch happened on,
/// then you should and pass your custom [BarTooltipItem] to show inside the tooltip popup.
typedef GetBarTooltipItem = BarTooltipItem Function(
typedef GetBarTooltipItem = BarTooltipItem? Function(
BarChartGroupData group,
int groupIndex,
BarChartRodData rod,
int rodIndex,
);

/// Default implementation for [BarTouchTooltipData.getTooltipItem].
BarTooltipItem defaultBarTooltipItem(
BarTooltipItem? defaultBarTooltipItem(
BarChartGroupData group,
int groupIndex,
BarChartRodData rod,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ class BarChartPainter extends AxisChartPainter<BarChartData> with TouchHandler<B
barRodIndex,
);

if (tooltipItem == null) {
return;
}

final span = TextSpan(style: tooltipItem.textStyle, text: tooltipItem.text);
final tp = TextPainter(
text: span,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ class LineTouchData extends FlTouchData with EquatableMixin {
/// in the given [barData], you should return a list of [TouchedSpotIndicatorData],
/// length of this list should be equal to the [spotIndexes.length],
/// each [TouchedSpotIndicatorData] determines the look of showing indicator.
typedef GetTouchedSpotIndicator = List<TouchedSpotIndicatorData> Function(
typedef GetTouchedSpotIndicator = List<TouchedSpotIndicatorData?> Function(
LineChartBarData barData, List<int> spotIndexes);

/// Default presentation of touched indicators.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ class LineChartPainter extends AxisChartPainter<LineChartData>
final index = barData.showingIndicators[i];
final spot = barData.spots[index];

if (indicatorData == null) {
continue;
}

final touchedSpot =
Offset(getPixelX(spot.x, chartViewSize), getPixelY(spot.y, chartViewSize));

Expand Down
4 changes: 2 additions & 2 deletions lib/src/chart/scatter_chart/scatter_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ class ScatterTouchTooltipData with EquatableMixin {
/// [touchedSpot] that touch happened on,
/// then you should and pass your custom [ScatterTooltipItem]
/// to show it inside the tooltip popup.
typedef GetScatterTooltipItems = ScatterTooltipItem Function(ScatterSpot touchedSpot);
typedef GetScatterTooltipItems = ScatterTooltipItem? Function(ScatterSpot touchedSpot);

/// Default implementation for [ScatterTouchTooltipData.getTooltipItems].
ScatterTooltipItem defaultScatterTooltipItem(ScatterSpot touchedSpot) {
ScatterTooltipItem? defaultScatterTooltipItem(ScatterSpot touchedSpot) {
final textStyle = TextStyle(
color: touchedSpot.color,
fontWeight: FontWeight.bold,
Expand Down
3 changes: 0 additions & 3 deletions lib/src/chart/scatter_chart/scatter_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData>
}

void _drawSpots(CanvasWrapper canvasWrapper) {
if (data.scatterSpots == null) {
return;
}
final viewSize = canvasWrapper.size;
final chartUsableSize = getChartUsableDrawSize(viewSize);
for (final scatterSpot in data.scatterSpots) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/lerp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ List<int>? lerpIntList(List<int>? a, List<int>? b, double t) => _lerpList(a, b,
/// Lerps [int] list based on [t] value, check [Tween.lerp].
int lerpInt(int a, int b, double t) => (a + (b - a) * t).round();

double _lerpNonNullDouble(double a, double b, double t) => _lerpNonNullDouble(a, b, t);
double _lerpNonNullDouble(double a, double b, double t) => lerpDouble(a, b, t)!;

/// Lerps [FlSpot] list based on [t] value, check [Tween.lerp].
List<FlSpot>? lerpFlSpotList(List<FlSpot>? a, List<FlSpot>? b, double t) =>
Expand Down

0 comments on commit 0866e07

Please sign in to comment.