Skip to content

Commit

Permalink
Fix barChart tooltip for values below or above the 0 point, #1462
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Dec 3, 2023
1 parent 2bb9c81 commit e9ab493
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ScatterSpot(
),
),
```
* **BUGFIX** (by @imaNNeo) Fix barChart tooltip for values below or above the 0 point, #1462

## 0.65.0
* **FEATURE** (by @Dartek12) Added gradient to [FlLine](https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/base_chart.md#FlLine), #1197
Expand Down
14 changes: 9 additions & 5 deletions lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,21 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
/// if we have multiple bar lines,
/// there are more than one FlCandidate on touch area,
/// we should get the most top FlSpot Offset to draw the tooltip on top of it
final barOffset = Offset(
final barToYPixel = Offset(
groupPositions[barGroupIndex].barsX[barRodIndex],
getPixelY(showOnRodData.toY, viewSize, holder),
);

final barFromYPixel = Offset(
groupPositions[barGroupIndex].barsX[barRodIndex],
getPixelY(showOnRodData.fromY, viewSize, holder),
);

final tooltipWidth = textWidth + tooltipData.tooltipPadding.horizontal;
final tooltipHeight = textHeight + tooltipData.tooltipPadding.vertical;

final zeroY = getPixelY(0, viewSize, holder);
final barTopY = min(zeroY, barOffset.dy);
final barBottomY = max(zeroY, barOffset.dy);
final barTopY = min(barToYPixel.dy, barFromYPixel.dy);
final barBottomY = max(barToYPixel.dy, barFromYPixel.dy);
final drawTooltipOnTop = tooltipData.direction == TooltipDirection.top ||
(tooltipData.direction == TooltipDirection.auto &&
showOnRodData.isUpward());
Expand All @@ -405,7 +409,7 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
: barBottomY + tooltipData.tooltipMargin;

final tooltipLeft = getTooltipLeft(
barOffset.dx,
barToYPixel.dx,
tooltipWidth,
tooltipData.tooltipHorizontalAlignment,
tooltipData.tooltipHorizontalOffset,
Expand Down

0 comments on commit e9ab493

Please sign in to comment.