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

Manage render priority for Scatter Chart #1760

Merged
merged 3 commits into from
Dec 23, 2024
Merged
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
9 changes: 9 additions & 0 deletions lib/src/chart/scatter_chart/scatter_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ class ScatterSpot extends FlSpot with EquatableMixin {
super.x,
super.y, {
bool? show,
int? renderPriority,
FlDotPainter? dotPainter,
}) : show = show ?? true,
renderPriority = renderPriority ?? 0,
dotPainter = dotPainter ??
FlDotCirclePainter(
radius: 6,
Expand All @@ -205,6 +207,9 @@ class ScatterSpot extends FlSpot with EquatableMixin {
/// Determines show or hide the spot.
final bool show;

// Determines Z-Index of the spot
final int renderPriority;

/// Determines shape of the spot
final FlDotPainter dotPainter;

Expand All @@ -223,12 +228,14 @@ class ScatterSpot extends FlSpot with EquatableMixin {
double? x,
double? y,
bool? show,
int? renderPriority,
FlDotPainter? dotPainter,
}) =>
ScatterSpot(
x ?? this.x,
y ?? this.y,
show: show ?? this.show,
renderPriority: renderPriority ?? this.renderPriority,
dotPainter: dotPainter ?? this.dotPainter,
);

Expand All @@ -238,6 +245,7 @@ class ScatterSpot extends FlSpot with EquatableMixin {
lerpDouble(a.x, b.x, t)!,
lerpDouble(a.y, b.y, t)!,
show: b.show,
renderPriority: a.renderPriority + (t * (b.renderPriority - a.renderPriority)).round(),
dotPainter: a.dotPainter.lerp(a.dotPainter, b.dotPainter, t),
);

Expand All @@ -247,6 +255,7 @@ class ScatterSpot extends FlSpot with EquatableMixin {
x,
y,
show,
renderPriority,
dotPainter,
];
}
Expand Down
1 change: 1 addition & 0 deletions repo_files/documentations/scatter_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ When you change the chart's state, it animates to the new state internally (usin
|show| determines to show or hide the spot|true|
|radius| radius of the showing spot| [8]
|color| colors of the spot|// a color based on the values|
|renderPriority| sort by this to manage overlap|0|


### ScatterTouchData ([read about touch handling](handle_touches.md))
Expand Down
2 changes: 2 additions & 0 deletions test/chart/data_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2307,12 +2307,14 @@ final ScatterChartData scatterChartData1 = ScatterChartData(
2,
2,
show: false,
renderPriority: 10,
dotPainter: FlDotCirclePainter(radius: 11, color: Colors.purple),
),
ScatterSpot(
1,
2,
show: false,
renderPriority: -1,
dotPainter: FlDotCirclePainter(radius: 11, color: Colors.white),
),
],
Expand Down
5 changes: 5 additions & 0 deletions test/chart/scatter_chart/scatter_chart_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void main() {
2,
2,
show: false,
renderPriority: 10,
dotPainter: FlDotCirclePainter(
radius: 11,
color: Colors.purple,
Expand All @@ -63,6 +64,7 @@ void main() {
1,
2,
show: false,
renderPriority: -1,
dotPainter: FlDotCirclePainter(
radius: 11,
color: Colors.white,
Expand All @@ -80,6 +82,7 @@ void main() {
2,
2,
show: false,
renderPriority: 10,
dotPainter: FlDotCirclePainter(
radius: 11,
color: Colors.purple,
Expand All @@ -89,6 +92,7 @@ void main() {
0,
0,
show: false,
renderPriority: 0,
dotPainter: FlDotCirclePainter(
radius: 33,
color: Colors.yellow,
Expand All @@ -98,6 +102,7 @@ void main() {
1,
2,
show: false,
renderPriority: -1,
dotPainter: FlDotCirclePainter(
radius: 11,
color: Colors.white,
Expand Down