Skip to content

Commit

Permalink
Merge branch 'main' into remove-axisTitleData-from-bar-chart-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo authored May 9, 2024
2 parents fa40aaf + df2788e commit 3d803d8
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## newVersion
* **IMPROVEMENT** (by @JoshMart) Remove references to deprecated `axisTitleData` property from code and docs, #1259, #1201
* **Improvement** (by @imaNNeo) Update LineChartSample6 to implement a way to show a tooltip on a single spot, #1620

## 0.67.0
* **FEATURE** (by @julien4215) Add direction property to the [HorizontalLineLabel](https://github.com/imaNNeo/fl_chart/blob/main/repo_files/documentations/base_chart.md#horizontallinelabel) and [VerticalLineLabel](https://github.com/imaNNeo/fl_chart/blob/main/repo_files/documentations/base_chart.md#verticallinelabel), #1574
Expand Down
70 changes: 57 additions & 13 deletions example/lib/presentation/samples/line/line_chart_sample6.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,39 @@ class LineChartSample6 extends StatelessWidget {
aspectRatio: 2,
child: LineChart(
LineChartData(
lineTouchData: const LineTouchData(enabled: false),
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
tooltipRoundedRadius: 0,
getTooltipColor: (spot) => Colors.white,
getTooltipItems: (List<LineBarSpot> touchedSpots) {
return touchedSpots.map((LineBarSpot touchedSpot) {
return LineTooltipItem(
touchedSpot.y.toString(),
TextStyle(
color: touchedSpot.bar.gradient!.colors.first,
fontWeight: FontWeight.bold,
fontSize: 20,
),
);
}).toList();
},
),
getTouchedSpotIndicator: (
_,
indicators,
) {
return indicators
.map((int index) => const TouchedSpotIndicatorData(
FlLine(color: Colors.transparent),
FlDotData(show: false),
))
.toList();
},
touchSpotThreshold: 12,
distanceCalculator:
(Offset touchPoint, Offset spotPixelCoordinates) =>
(touchPoint - spotPixelCoordinates).distance,
),
lineBarsData: [
LineChartBarData(
gradient: LinearGradient(
Expand All @@ -141,12 +173,18 @@ class LineChartSample6 extends StatelessWidget {
),
dotData: FlDotData(
show: true,
getDotPainter: (spot, percent, barData, index) =>
FlDotCirclePainter(
radius: 12,
color: Colors.transparent,
strokeColor: AppColors.mainTextColor2,
),
getDotPainter: (spot, percent, barData, index) {
return FlDotCirclePainter(
radius: 12,
color: Color.lerp(
line1Color1,
line1Color2,
percent / 100,
)!,
strokeColor: Colors.white,
strokeWidth: 1,
);
},
),
),
LineChartBarData(
Expand All @@ -165,12 +203,18 @@ class LineChartSample6 extends StatelessWidget {
),
dotData: FlDotData(
show: true,
getDotPainter: (spot, percent, barData, index) =>
FlDotCirclePainter(
radius: 12,
color: Colors.transparent,
strokeColor: AppColors.mainTextColor2,
),
getDotPainter: (spot, percent, barData, index) {
return FlDotCirclePainter(
radius: 12,
color: Color.lerp(
line2Color1,
line2Color2,
percent / 100,
)!,
strokeColor: Colors.white,
strokeWidth: 1,
);
},
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
3 changes: 3 additions & 0 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ class BarChartGroupData with EquatableMixin {
/// you can show some tooltipIndicators (a popup with an information)
/// on top of each [BarChartRodData] using [showingTooltipIndicators],
/// just put indices you want to show it on top of them.
///
/// An important point is that you have to disable the default touch behaviour
/// to show the tooltip manually, see [BarTouchData.handleBuiltInTouches].
final List<int> showingTooltipIndicators;

/// width of the group (sum of all [BarChartRodData]'s width and spaces)
Expand Down
29 changes: 21 additions & 8 deletions lib/src/chart/base/axis_chart/axis_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ class FlTitlesData with EquatableMixin {
}

/// Represents a conceptual position in cartesian (axis based) space.
class FlSpot with EquatableMixin {
@immutable
class FlSpot {
/// [x] determines cartesian (axis based) horizontally position
/// 0 means most left point of the chart
///
Expand Down Expand Up @@ -477,13 +478,6 @@ class FlSpot with EquatableMixin {
/// Determines if [x] and [y] is not null.
bool isNotNull() => !isNull();

/// Used for equality check, see [EquatableMixin].
@override
List<Object?> get props => [
x,
y,
];

/// Lerps a [FlSpot] based on [t] value, check [Tween.lerp].
static FlSpot lerp(FlSpot a, FlSpot b, double t) {
if (a == FlSpot.nullSpot) {
Expand All @@ -499,6 +493,25 @@ class FlSpot with EquatableMixin {
lerpDouble(a.y, b.y, t)!,
);
}

/// Two [FlSpot] are equal if their [x] and [y] are equal.
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other is! FlSpot) {
return false;
}

if (x.isNaN && y.isNaN && other.x.isNaN && other.y.isNaN) {
return true;
}

return other.x == x && other.y == y;
}

/// Override hashCode
@override
int get hashCode => x.hashCode ^ y.hashCode;
}

/// Responsible to hold grid data,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class LineChartData extends AxisChartData with EquatableMixin {
/// You can show some tooltipIndicators (a popup with an information)
/// on top of each [LineChartBarData.spots] using [showingTooltipIndicators],
/// just put line indicator number and spots indices you want to show it on top of them.
///
/// An important point is that you have to disable the default touch behaviour
/// to show the tooltip manually, see [LineTouchData.handleBuiltInTouches].
final List<ShowingTooltipIndicators> showingTooltipIndicators;

/// Lerps a [BaseChartData] based on [t] value, check [Tween.lerp].
Expand Down
8 changes: 8 additions & 0 deletions lib/src/chart/scatter_chart/scatter_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ class ScatterChartData extends AxisChartData with EquatableMixin {
);
final List<ScatterSpot> scatterSpots;
final ScatterTouchData scatterTouchData;

/// you can show some tooltipIndicators (a popup with an information)
/// on top of each [ScatterSpot] using [showingTooltipIndicators],
/// just put indices you want to show it on top of them.
///
/// An important point is that you have to disable the default touch behaviour
/// to show the tooltip manually, see [ScatterTouchData.handleBuiltInTouches].
final List<int> showingTooltipIndicators;

final ScatterLabelSettings scatterLabelSettings;

/// Lerps a [ScatterChartData] based on [t] value, check [Tween.lerp].
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class Utils {

/// Finds the best initial interval value
///
/// If there is a zero point in the axis, we a value that passes through it.
/// If there is a zero point in the axis, we want to have a value that passes through it.
/// For example if we have -3 to +3, with interval 2. if we start from -3, we get something like this: -3, -1, +1, +3
/// But the most important point is zero in most cases. with this logic we get this: -2, 0, 2
double getBestInitialIntervalValue(
Expand Down
Binary file added pub_screenshots/logo_1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dev_dependencies:
very_good_analysis: ^5.1.0

screenshots:
- description: 'FL Chart Logo'
path: pub_screenshots/logo_1024.png
- description: 'LineChartSample1 and LineChartSample2'
path: pub_screenshots/line_chart.jpg
- description: 'LineChartSample10'
Expand Down
6 changes: 2 additions & 4 deletions repo_files/documentations/bar_chart.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# BarChart

<img src="https://github.com/imaNNeo/fl_chart/raw/main/repo_files/images/bar_chart/bar_chart.jpg" width="300" >
<a href="https://youtu.be/vYe0RY1nCAA"><img src="https://github.com/imaNNeo/fl_chart/raw/main/repo_files/images/bar_chart/bar_chart_video_thumbnail.png" width=540></a>

### How to use
```dart
Expand Down Expand Up @@ -40,7 +38,7 @@ When you change the chart's state, it animates to the new state internally (usin
|x| x position of the group on horizontal axis|null|
|barRods| list of [BarChartRodData](#BarChartRodData) that are a bar line| []
|barsSpace| the space between barRods of the group|2|
|showingTooltipIndicators| indexes of barRods to show the tooltip on top of them | []|
|showingTooltipIndicators| indexes of barRods to show the tooltip on top of them, The point is that you need to disable touches to show these tooltips manually | []|


### BarChartAlignment
Expand Down
6 changes: 2 additions & 4 deletions repo_files/documentations/line_chart.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# LineChart

<img src="https://github.com/imaNNeo/fl_chart/raw/main/repo_files/images/line_chart/line_chart.jpg" width="300" >
<a href="https://youtu.be/F3wTxTdAFaU"><img src="https://github.com/imaNNeo/fl_chart/raw/main/repo_files/images/line_chart/line_chart_video_thumbnail.png" width=540></a>

### How to use
```dart
Expand All @@ -25,7 +23,7 @@ When you change the chart's state, it animates to the new state internally (usin
|extraLinesData| [ExtraLinesData](base_chart.md#ExtraLinesData) object to hold drawing details of extra horizontal and vertical lines. Check [ExtraLinesData](base_chart.md#ExtraLinesData)|ExtraLinesData()|
|lineTouchData| [LineTouchData](#linetouchdata-read-about-touch-handling) holds the touch interactivity details| LineTouchData()|
|rangeAnnotations| show range annotations behind the chart, check [RangeAnnotations](base_chart.md#RangeAnnotations) | RangeAnnotations()|
|showingTooltipIndicators| show the tooltip based on provided list of [LineBarSpot](#LineBarSpot)| [] |
|showingTooltipIndicators| show the tooltip based on provided list of [LineBarSpot](#LineBarSpot), The point is that you need to disable touches to show these tooltips manually| [] |
|gridData| check the [FlGridData](base_chart.md#FlGridData)|FlGridData()|
|borderData| check the [FlBorderData](base_chart.md#FlBorderData)|FlBorderData()|
|minX| gets minimum x of x axis, if null, value will read from the input lineBars |null|
Expand Down
2 changes: 1 addition & 1 deletion repo_files/documentations/scatter_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ When you change the chart's state, it animates to the new state internally (usin
|scatterSpots| list of [ScatterSpot ](#ScatterSpot ) to show the scatter spots on the chart|[]|
|titlesData| check the [FlTitlesData](base_chart.md#FlTitlesData)| FlTitlesData()|
|scatterTouchData| [ScatterTouchData](#scattertouchdata-read-about-touch-handling) holds the touch interactivity details| ScatterTouchData()|
|showingTooltipIndicators| indices of showing tooltip|[]|
|showingTooltipIndicators| indices of showing tooltip, The point is that you need to disable touches to show these tooltips manually|[]|



Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed repo_files/images/line_chart/line_chart.jpg
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions test/chart/base/axis_chart/axis_chart_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ void main() {
expect(flSpot1 == flSpot2, false);

expect(flSpot2 == flSpot2Clone, true);

expect(nullSpot1 == nullSpot2, true);

expect(nullSpot2 == nullSpot3, true);

expect(nullSpot1 == nullSpot3, true);
});

test('FlGridData equality test', () {
Expand Down
22 changes: 20 additions & 2 deletions test/chart/base/axis_chart/axis_chart_helper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void main() {
expect(results[4], 10);
});

test('test 4', () {
test('test 5', () {
final results = <double>[];
final axisValues = AxisChartHelper().iterateThroughAxis(
min: 0,
Expand All @@ -95,7 +95,7 @@ void main() {
expect(results[2], 9);
});

test('test 4', () {
test('test 6', () {
final results = <double>[];
final axisValues = AxisChartHelper().iterateThroughAxis(
min: 35,
Expand All @@ -112,6 +112,24 @@ void main() {
expect(results[2], 100);
expect(results[3], 130);
});

test('test 7', () {
final results = <double>[];
final axisValues = AxisChartHelper().iterateThroughAxis(
min: 5,
max: 35,
interval: 10,
baseLine: 5,
);
for (final axisValue in axisValues) {
results.add(axisValue);
}
expect(results.length, 4);
expect(results[0], 5);
expect(results[1], 15);
expect(results[2], 25);
expect(results[3], 35);
});
});

group('calcFitInsideOffset', () {
Expand Down
4 changes: 4 additions & 0 deletions test/chart/data_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ final FlSpot flSpot1Clone = flSpot1.copyWith();
const FlSpot flSpot2 = FlSpot(4, 2);
final FlSpot flSpot2Clone = flSpot2.copyWith();

const nullSpot1 = FlSpot.nullSpot;
final nullSpot2 = nullSpot1.copyWith();
const nullSpot3 = FlSpot.nullSpot;

Widget getTitles(double value, TitleMeta meta) => const Text('sallam');

TextStyle getTextStyles(BuildContext context, double value) =>
Expand Down

0 comments on commit 3d803d8

Please sign in to comment.