Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show tooltip on top of bar chart #1472

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ class BarTouchTooltipData with EquatableMixin {
TooltipDirection? direction,
double? rotateAngle,
BorderSide? tooltipBorder,
bool? showOnTopOfTheChartBoxArea,
}) : tooltipBgColor = tooltipBgColor ?? Colors.blueGrey.darken(15),
tooltipRoundedRadius = tooltipRoundedRadius ?? 4,
tooltipPadding = tooltipPadding ??
Expand All @@ -720,6 +721,7 @@ class BarTouchTooltipData with EquatableMixin {
direction = direction ?? TooltipDirection.auto,
rotateAngle = rotateAngle ?? 0.0,
tooltipBorder = tooltipBorder ?? BorderSide.none,
showOnTopOfTheChartBoxArea = showOnTopOfTheChartBoxArea ?? false,
super();

/// The tooltip background color.
Expand Down Expand Up @@ -761,6 +763,8 @@ class BarTouchTooltipData with EquatableMixin {
/// The tooltip border color.
final BorderSide tooltipBorder;

final bool showOnTopOfTheChartBoxArea;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add it in the props section


/// Used for equality check, see [EquatableMixin].
@override
List<Object?> get props => [
Expand Down
17 changes: 11 additions & 6 deletions lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,17 @@
final zeroY = getPixelY(0, viewSize, holder);
final barTopY = min(zeroY, barOffset.dy);
final barBottomY = max(zeroY, barOffset.dy);
final drawTooltipOnTop = tooltipData.direction == TooltipDirection.top ||
(tooltipData.direction == TooltipDirection.auto &&
showOnRodData.isUpward());
final tooltipTop = drawTooltipOnTop
? barTopY - tooltipHeight - tooltipData.tooltipMargin
: barBottomY + tooltipData.tooltipMargin;
final double tooltipTop;
if (tooltipData.showOnTopOfTheChartBoxArea) {
tooltipTop = 0 - tooltipHeight - tooltipData.tooltipMargin;

Check warning on line 393 in lib/src/chart/bar_chart/bar_chart_painter.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/chart/bar_chart/bar_chart_painter.dart#L393

Added line #L393 was not covered by tests
} else {
final drawTooltipOnTop = tooltipData.direction == TooltipDirection.top ||
(tooltipData.direction == TooltipDirection.auto &&
showOnRodData.isUpward());
tooltipTop = drawTooltipOnTop
? barTopY - tooltipHeight - tooltipData.tooltipMargin
: barBottomY + tooltipData.tooltipMargin;
}

final tooltipLeft = getTooltipLeft(
barOffset.dx,
Expand Down