Skip to content

Commit

Permalink
scatterChart tooltip moved from roundedRadius to borderRadius
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiaPispisa committed Jan 19, 2025
1 parent 7c2cedb commit c3b0a4c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
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 @@ -1071,9 +1071,9 @@ class LineTouchTooltipData with EquatableMixin {
@Deprecated('use tooltipBorderRadius instead')
final double tooltipRoundedRadius;

/// Sets a border radius for the tooltip.
final BorderRadius? _tooltipBorderRadius;

/// Sets a rounded radius for the tooltip.
BorderRadius get tooltipBorderRadius =>
_tooltipBorderRadius ?? BorderRadius.circular(tooltipRoundedRadius);

Expand Down
14 changes: 12 additions & 2 deletions lib/src/chart/scatter_chart/scatter_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,11 @@ class ScatterTouchTooltipData with EquatableMixin {
/// if [ScatterTouchData.handleBuiltInTouches] is true,
/// [ScatterChart] shows a tooltip popup on top of spots automatically when touch happens,
/// otherwise you can show it manually using [ScatterChartData.showingTooltipIndicators].
/// Tooltip shows on top of spots, with [getTooltipColor] as a background color,
/// and you can set corner radius using [tooltipRoundedRadius].
/// Tooltip shows on top of rods, with [getTooltipColor] as a background color.
/// You can set the corner radius using [tooltipRoundedRadius],
/// or if you need a custom border, you can use [tooltipBorderRadius].
/// Note that if both [tooltipRoundedRadius] and [tooltipBorderRadius] are set,
/// the value from [tooltipBorderRadius] will be used.
/// If you want to have a padding inside the tooltip, fill [tooltipPadding].
/// Content of the tooltip will provide using [getTooltipItems] callback, you can override it
/// and pass your custom data to show in the tooltip.
Expand All @@ -444,6 +447,7 @@ class ScatterTouchTooltipData with EquatableMixin {
/// also you can set [fitInsideVertically] true to force it to shift inside the chart vertically.
ScatterTouchTooltipData({
double? tooltipRoundedRadius,
BorderRadius? tooltipBorderRadius,
EdgeInsets? tooltipPadding,
FLHorizontalAlignment? tooltipHorizontalAlignment,
double? tooltipHorizontalOffset,
Expand All @@ -455,6 +459,8 @@ class ScatterTouchTooltipData with EquatableMixin {
BorderSide? tooltipBorder,
GetScatterTooltipColor? getTooltipColor,
}) : tooltipRoundedRadius = tooltipRoundedRadius ?? 4,
tooltipBorderRadius = tooltipBorderRadius ??
BorderRadius.circular(tooltipRoundedRadius ?? 4),
tooltipPadding = tooltipPadding ??
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
tooltipHorizontalAlignment =
Expand All @@ -470,8 +476,12 @@ class ScatterTouchTooltipData with EquatableMixin {
super();

/// Sets a rounded radius for the tooltip.
@Deprecated('use tooltipBorderRadius instead')
final double tooltipRoundedRadius;

/// Sets a border radius for the tooltip.
final BorderRadius tooltipBorderRadius;

/// Applies a padding for showing contents inside the tooltip.
final EdgeInsets tooltipPadding;

Expand Down
9 changes: 4 additions & 5 deletions lib/src/chart/scatter_chart/scatter_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,12 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData> {
}
}

final radius = Radius.circular(tooltipData.tooltipRoundedRadius);
final roundedRect = RRect.fromRectAndCorners(
rect,
topLeft: radius,
topRight: radius,
bottomLeft: radius,
bottomRight: radius,
topLeft: tooltipData.tooltipBorderRadius.topLeft,
topRight: tooltipData.tooltipBorderRadius.topRight,
bottomLeft: tooltipData.tooltipBorderRadius.bottomLeft,
bottomRight: tooltipData.tooltipBorderRadius.bottomRight,
);

_bgTouchTooltipPaint.color = tooltipData.getTooltipColor(showOnSpot);
Expand Down
9 changes: 7 additions & 2 deletions test/chart/scatter_chart/scatter_chart_painter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ void main() {
touchTooltipData: ScatterTouchTooltipData(
rotateAngle: 18,
getTooltipColor: (touchedSpot) => const Color(0xFF00FF00),
tooltipRoundedRadius: 85,
tooltipBorderRadius: const BorderRadius.only(
topLeft: Radius.circular(85),
topRight: Radius.circular(8),
),
tooltipPadding: const EdgeInsets.all(12),
getTooltipItems: (_) {
return ScatterTooltipItem(
Expand Down Expand Up @@ -462,8 +465,10 @@ void main() {
final bgPaint = captured2[0][1] as Paint;
final textPainter = captured2[1][0] as TextPainter;

expect(rRect.blRadiusX, 85);
expect(rRect.blRadiusX, 0);
expect(rRect.blRadiusY, 0);
expect(rRect.tlRadiusY, 85);
expect(rRect.trRadiusX, 8);

expect(bgPaint.color, const Color(0xFF00FF00));
expect(
Expand Down

0 comments on commit c3b0a4c

Please sign in to comment.