Skip to content
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
41 changes: 39 additions & 2 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class BarChartRodData with EquatableMixin {
Gradient? gradient,
double? width,
BorderRadius? borderRadius,
List<int>? dashArray,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The only thing that worries me is this property that we're removing (it adds a breaking change)
But the point is that the value here was ignored. So I don't know what to do, haha.

Maybe we can go ahead with the breaking change as it is a special edge-case

Copy link
Copy Markdown
Owner

@imaNNeo imaNNeo Apr 28, 2026

Choose a reason for hiding this comment

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

In a professional way, we should deprecate the previous name and introduce the new name. But in this case it doesn't really make sense.

List<int>? borderDashArray,
BorderSide? borderSide,
BackgroundBarChartRodData? backDrawRodData,
List<BarChartRodStackItem>? rodStackItems,
Expand All @@ -426,7 +426,7 @@ class BarChartRodData with EquatableMixin {
gradient: gradient ?? this.gradient,
width: width ?? this.width,
borderRadius: borderRadius ?? this.borderRadius,
borderDashArray: borderDashArray,
borderDashArray: borderDashArray ?? this.borderDashArray,
borderSide: borderSide ?? this.borderSide,
backDrawRodData: backDrawRodData ?? this.backDrawRodData,
rodStackItems: rodStackItems ?? this.rodStackItems,
Expand Down Expand Up @@ -840,10 +840,47 @@ class BarTouchTooltipData with EquatableMixin {
getTooltipItem,
fitInsideHorizontally,
fitInsideVertically,
direction,
rotateAngle,
tooltipBorder,
getTooltipColor,
];

/// Copies current [BarTouchTooltipData] to a new [BarTouchTooltipData],
/// and replaces provided values.
BarTouchTooltipData copyWith({
BorderRadius? tooltipBorderRadius,
EdgeInsets? tooltipPadding,
double? tooltipMargin,
FLHorizontalAlignment? tooltipHorizontalAlignment,
double? tooltipHorizontalOffset,
double? maxContentWidth,
GetBarTooltipItem? getTooltipItem,
GetBarTooltipColor? getTooltipColor,
bool? fitInsideHorizontally,
bool? fitInsideVertically,
TooltipDirection? direction,
double? rotateAngle,
BorderSide? tooltipBorder,
}) =>
BarTouchTooltipData(
tooltipBorderRadius: tooltipBorderRadius ?? _tooltipBorderRadius,
tooltipPadding: tooltipPadding ?? this.tooltipPadding,
tooltipMargin: tooltipMargin ?? this.tooltipMargin,
tooltipHorizontalAlignment:
tooltipHorizontalAlignment ?? this.tooltipHorizontalAlignment,
tooltipHorizontalOffset:
tooltipHorizontalOffset ?? this.tooltipHorizontalOffset,
maxContentWidth: maxContentWidth ?? this.maxContentWidth,
getTooltipItem: getTooltipItem ?? this.getTooltipItem,
getTooltipColor: getTooltipColor ?? this.getTooltipColor,
fitInsideHorizontally:
fitInsideHorizontally ?? this.fitInsideHorizontally,
fitInsideVertically: fitInsideVertically ?? this.fitInsideVertically,
direction: direction ?? this.direction,
rotateAngle: rotateAngle ?? this.rotateAngle,
tooltipBorder: tooltipBorder ?? this.tooltipBorder,
);
}

/// Provides a [BarTooltipItem] for showing content inside the [BarTouchTooltipData].
Expand Down
3 changes: 3 additions & 0 deletions lib/src/chart/candlestick_chart/candlestick_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ class CandlestickTouchTooltipData with EquatableMixin {
GetCandlestickTooltipItems? getTooltipItems,
bool? fitInsideHorizontally,
bool? fitInsideVertically,
bool? showOnTopOfTheChartBoxArea,
double? rotateAngle,
BorderSide? tooltipBorder,
GetCandlestickTooltipColor? getTooltipColor,
Expand All @@ -591,6 +592,8 @@ class CandlestickTouchTooltipData with EquatableMixin {
fitInsideHorizontally:
fitInsideHorizontally ?? this.fitInsideHorizontally,
fitInsideVertically: fitInsideVertically ?? this.fitInsideVertically,
showOnTopOfTheChartBoxArea:
showOnTopOfTheChartBoxArea ?? this.showOnTopOfTheChartBoxArea,
rotateAngle: rotateAngle ?? this.rotateAngle,
tooltipBorder: tooltipBorder ?? this.tooltipBorder,
getTooltipColor: getTooltipColor ?? this.getTooltipColor,
Expand Down
37 changes: 37 additions & 0 deletions lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,43 @@ class LineTouchTooltipData with EquatableMixin {
tooltipBorder,
getTooltipColor,
];

/// Copies current [LineTouchTooltipData] to a new [LineTouchTooltipData],
/// and replaces provided values.
LineTouchTooltipData copyWith({
BorderRadius? tooltipBorderRadius,
EdgeInsets? tooltipPadding,
double? tooltipMargin,
FLHorizontalAlignment? tooltipHorizontalAlignment,
double? tooltipHorizontalOffset,
double? maxContentWidth,
GetLineTooltipItems? getTooltipItems,
GetLineTooltipColor? getTooltipColor,
bool? fitInsideHorizontally,
bool? fitInsideVertically,
bool? showOnTopOfTheChartBoxArea,
double? rotateAngle,
BorderSide? tooltipBorder,
}) =>
LineTouchTooltipData(
tooltipBorderRadius: tooltipBorderRadius ?? _tooltipBorderRadius,
tooltipPadding: tooltipPadding ?? this.tooltipPadding,
tooltipMargin: tooltipMargin ?? this.tooltipMargin,
tooltipHorizontalAlignment:
tooltipHorizontalAlignment ?? this.tooltipHorizontalAlignment,
tooltipHorizontalOffset:
tooltipHorizontalOffset ?? this.tooltipHorizontalOffset,
maxContentWidth: maxContentWidth ?? this.maxContentWidth,
getTooltipItems: getTooltipItems ?? this.getTooltipItems,
getTooltipColor: getTooltipColor ?? this.getTooltipColor,
fitInsideHorizontally:
fitInsideHorizontally ?? this.fitInsideHorizontally,
fitInsideVertically: fitInsideVertically ?? this.fitInsideVertically,
showOnTopOfTheChartBoxArea:
showOnTopOfTheChartBoxArea ?? this.showOnTopOfTheChartBoxArea,
rotateAngle: rotateAngle ?? this.rotateAngle,
tooltipBorder: tooltipBorder ?? this.tooltipBorder,
);
}

/// Provides a [LineTooltipItem] for showing content inside the [LineTouchTooltipData].
Expand Down
3 changes: 2 additions & 1 deletion lib/src/chart/scatter_chart/scatter_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class ScatterChartData extends AxisChartData with EquatableMixin {
minY,
maxY,
baselineY,
rangeAnnotations,
scatterLabelSettings,
clipData,
backgroundColor,
Expand Down Expand Up @@ -533,6 +532,7 @@ class ScatterTouchTooltipData with EquatableMixin {
/// Copies current [ScatterTouchTooltipData] to a new [ScatterTouchTooltipData],
/// and replaces provided values.
ScatterTouchTooltipData copyWith({
BorderRadius? tooltipBorderRadius,
EdgeInsets? tooltipPadding,
FLHorizontalAlignment? tooltipHorizontalAlignment,
double? tooltipHorizontalOffset,
Expand All @@ -545,6 +545,7 @@ class ScatterTouchTooltipData with EquatableMixin {
GetScatterTooltipColor? getTooltipColor,
}) =>
ScatterTouchTooltipData(
tooltipBorderRadius: tooltipBorderRadius ?? _tooltipBorderRadius,
tooltipPadding: tooltipPadding ?? this.tooltipPadding,
tooltipHorizontalAlignment:
tooltipHorizontalAlignment ?? this.tooltipHorizontalAlignment,
Expand Down
38 changes: 38 additions & 0 deletions test/chart/bar_chart/bar_chart_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ void main() {
expect(barChartRodData1 == barChartRodData8, false);
});

test('BarChartRodData copyWith borderDashArray', () {
final base = BarChartRodData(toY: 10, borderDashArray: [4, 4]);

final unchanged = base.copyWith(toY: 20);
expect(unchanged.borderDashArray, [4, 4]);

final changed = base.copyWith(borderDashArray: [2, 8]);
expect(changed.borderDashArray, [2, 8]);

final noArray = BarChartRodData(toY: 10);
final withArray = noArray.copyWith(borderDashArray: [6, 2]);
expect(withArray.borderDashArray, [6, 2]);
});

test('BarChartRodStackItem equality test', () {
expect(barChartRodStackItem1 == barChartRodStackItem1Clone, true);
expect(
Expand Down Expand Up @@ -110,6 +124,30 @@ void main() {
expect(barTouchTooltipData1 == barTouchTooltipData11, false);
});

test('BarTouchTooltipData direction in props', () {
const base = BarTouchTooltipData(direction: TooltipDirection.auto);
const different = BarTouchTooltipData(direction: TooltipDirection.bottom);
expect(base == different, false);
});

test('BarTouchTooltipData copyWith', () {
const base = BarTouchTooltipData(
tooltipMargin: 8,
direction: TooltipDirection.top,
);

final unchanged = base.copyWith(maxContentWidth: 200);
expect(unchanged.tooltipMargin, 8);
expect(unchanged.direction, TooltipDirection.top);

final changed = base.copyWith(
tooltipMargin: 24,
direction: TooltipDirection.bottom,
);
expect(changed.tooltipMargin, 24);
expect(changed.direction, TooltipDirection.bottom);
});

test('BarTooltipItem equality test', () {
expect(barTooltipItem1 == barTooltipItem1Clone, true);
expect(barTooltipItem1 == barTooltipItem2, false);
Expand Down
12 changes: 12 additions & 0 deletions test/chart/candlestick_chart/candlestick_chart_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,18 @@ void main() {
);
});

test('CandlestickTouchTooltipData copyWith showOnTopOfTheChartBoxArea', () {
final base = CandlestickTouchTooltipData(
showOnTopOfTheChartBoxArea: false,
);

final unchanged = base.copyWith(maxContentWidth: 200);
expect(unchanged.showOnTopOfTheChartBoxArea, false);

final changed = base.copyWith(showOnTopOfTheChartBoxArea: true);
expect(changed.showOnTopOfTheChartBoxArea, true);
});

test('CandlestickTooltipItem equality test', () {
final sample1 = CandlestickTooltipItem(
'aa',
Expand Down
18 changes: 18 additions & 0 deletions test/chart/line_chart/line_chart_data_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../data_pool.dart';
Expand Down Expand Up @@ -144,6 +145,23 @@ void main() {
expect(lineTouchTooltipData1 == lineTouchTooltipData7, false);
});

test('LineTouchTooltipData copyWith', () {
const base = LineTouchTooltipData(tooltipMargin: 8);

final unchanged = base.copyWith(maxContentWidth: 200);
expect(unchanged.tooltipMargin, 8);
expect(unchanged.showOnTopOfTheChartBoxArea, false);

final changed = base.copyWith(
tooltipMargin: 24,
showOnTopOfTheChartBoxArea: true,
tooltipBorderRadius: BorderRadius.circular(8),
);
expect(changed.tooltipMargin, 24);
expect(changed.showOnTopOfTheChartBoxArea, true);
expect(changed.tooltipBorderRadius, BorderRadius.circular(8));
});

test('LineBarSpot equality test', () {
expect(lineBarSpot1 == lineBarSpot1Clone, true);
expect(lineBarSpot1 == lineBarSpot2, false);
Expand Down
12 changes: 12 additions & 0 deletions test/chart/scatter_chart/scatter_chart_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ void main() {
expect(scatterTouchTooltipData1 == scatterTouchTooltipData3, false);
});

test('ScatterTouchTooltipData copyWith tooltipBorderRadius', () {
const base = ScatterTouchTooltipData(maxContentWidth: 100);

final unchanged = base.copyWith(maxContentWidth: 200);
expect(unchanged.tooltipBorderRadius, BorderRadius.circular(4));

final changed = base.copyWith(
tooltipBorderRadius: BorderRadius.circular(12),
);
expect(changed.tooltipBorderRadius, BorderRadius.circular(12));
});

test('ScatterTooltipItem equality test', () {
final sample1 = ScatterTooltipItem(
'aa',
Expand Down
Loading