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

added custom properties attribute to line chart bar data #1664

Open
wants to merge 1 commit 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
10 changes: 10 additions & 0 deletions lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class LineChartBarData with EquatableMixin {
this.shadow = const Shadow(color: Colors.transparent),
this.isStepLineChart = false,
this.lineChartStepData = const LineChartStepData(),
this.properties = const {},
}) : color =
color ?? ((color == null && gradient == null) ? Colors.cyan : null),
belowBarData = belowBarData ?? BarAreaData(),
Expand Down Expand Up @@ -366,6 +367,9 @@ class LineChartBarData with EquatableMixin {
/// Holds data for representing a Step Line Chart, and works only if [isStepChart] is true.
final LineChartStepData lineChartStepData;

/// Holds custom properties for this [LineChartBarData], like curve title, subtitle that can be used in the tooltip, etc.
final Map<String, dynamic> properties;

/// Lerps a [LineChartBarData] based on [t] value, check [Tween.lerp].
static LineChartBarData lerp(
LineChartBarData a,
Expand Down Expand Up @@ -397,6 +401,9 @@ class LineChartBarData with EquatableMixin {
isStepLineChart: b.isStepLineChart,
lineChartStepData:
LineChartStepData.lerp(a.lineChartStepData, b.lineChartStepData, t),
properties: {}
..addAll(a.properties)
Copy link
Owner

@imaNNeo imaNNeo Jan 6, 2025

Choose a reason for hiding this comment

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

Hi, sorry for my late reply.
You should not do this here. Because everytime you set a new value to the properties list, it adds to the previous map and it is not a correct behaviour.

Suppose that you have:

{
   "title": "Hello"
}

And in the next setState, you change it to

{
  "name": "Hello"
}

And in the end you have:

{
  "title": "Help",
  "name": "Hello"
}

which is not correct in my opinion
So I suggest to have a dynamic type and in the lerp method, we can have
properties: b.properties

..addAll(b.properties),
);
}

Expand All @@ -422,6 +429,7 @@ class LineChartBarData with EquatableMixin {
Shadow? shadow,
bool? isStepLineChart,
LineChartStepData? lineChartStepData,
Map<String, dynamic>? properties,
}) {
return LineChartBarData(
spots: spots ?? this.spots,
Expand All @@ -445,6 +453,7 @@ class LineChartBarData with EquatableMixin {
shadow: shadow ?? this.shadow,
isStepLineChart: isStepLineChart ?? this.isStepLineChart,
lineChartStepData: lineChartStepData ?? this.lineChartStepData,
properties: properties ?? this.properties,
);
}

Expand All @@ -470,6 +479,7 @@ class LineChartBarData with EquatableMixin {
shadow,
isStepLineChart,
lineChartStepData,
properties,
];
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: fl_chart
description: A highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, and Radar Chart.
version: 0.68.0
version: 0.69.0
homepage: https://flchart.dev/
repository: https://github.com/imaNNeo/fl_chart
issue_tracker: https://github.com/imaNNeo/fl_chart/issues
Expand Down