Skip to content

Commit

Permalink
Merge pull request #615 from imaNNeoFighT/dev
Browse files Browse the repository at this point in the history
Dev 0.35.0
  • Loading branch information
imaNNeo authored Apr 1, 2021
2 parents 6876bdc + f83fb8c commit 2d42fdb
Show file tree
Hide file tree
Showing 39 changed files with 623 additions and 170 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## 0.35.0
* **IMPROVEMENT** Added `children` property in the [LineTooltipItem](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/line_chart.md#linetooltipitem), [BarTooltipItem](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#bartooltipitem) and [ScatterTooltipItem](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/scatter_chart.md#scattertooltipitem) which accepts a list of [TextSpan](https://api.flutter.dev/flutter/painting/TextSpan-class.html). It allows you to have more customized texts inside the tooltip. See [BarChartSample1](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#sample-1-source-code) and [ScatterSample2](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/scatter_chart.md#sample-2-source-code), #72, #294.
* **IMPROVEMENT** Added `getTouchLineStart` and `getTouchLineEnd` in [LineTouchData](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/line_chart.md#linetouchdata-read-about-touch-handling) to give more customizability over showing the touch lines. see [SampleLineChart9](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/line_chart.md#sample-8-source-code).
* **IMPROVEMENT** Enabled `sectionsSpace` in PieChart for the web.
* **IMPROVEMENT** Added [Makefile](https://makefiletutorial.com) commands which makes it comfortable for verifying your code before push (It is related to contributors, red more about it in [CONTRIBUTING.md](https://github.com/imaNNeoFighT/fl_chart/blob/master/CONTRIBUTING.md)).
* **IMPROVEMENT** Added `FlDotCrossPainter` which extends `FlDotPainter` to paint X marks on line chart spots.
* **IMPROVEMENT** Added `textDirection` property in [LineTooltipItem](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/line_chart.md#linetooltipitem), [BarTooltipItem](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/bar_chart.md#bartooltipitem) and [ScatterTooltipItem](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/scatter_chart.md#scattertooltipitem). It allows you to support rtl languages in tooltips.
* **IMPROVEMENT** Added `textDirection` property in [SideTitles](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/base_chart.md#sidetitles) class, #531. It allows you to support rtl languages in side titles.
* **IMPROVEMENT** Added `textDirection` property in [AxisTitles](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/base_chart.md#AxisTitle) class. It allows you to support rtl languages in axis titles.
* **BUGFIX** Fixed some bugs on drawing PieChart (for example when we have only one section), #582,
* **BREAKING** Border of pieChart now is hide by default (you can show it using `borderData: FlBorderData(show: true)`.
* **BREAKING** You cannot set `0` value on [PieChartSectionData](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/pie_chart.md#piechartsectiondata).value anymore, instead remove it from list.
* **BREAKING** Removed `fullHeightTouchLine` property from [LineTouchData](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/line_chart.md#linetouchdata-read-about-touch-handling). Now you can have a full line with following snippet:
```dart
LineTouchData(
...
getTouchLineStart: (barData, index) => -double.infinity // default: from bottom,
getTouchLineEnd: (barData, index) => double.infinity //to top,
...
)
```

## 0.30.0
* [IMPROVEMENT] We now use [RenderObject](https://api.flutter.dev/flutter/rendering/RenderObject-class.html) as our default drawing system. It brings a lot of stability. Such as size handling, hitTest handling (touches), and It makes us possible to paint Widgets inside our chart (It might fix #383, #556, #582, #584, #591).
* [IMPROVEMENT] Added [Radar Chart Documentations](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/radar_chart.md)
Expand Down
16 changes: 10 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ It makes draw functions testable.
After you have made your changes, you have to make sure your code works
correctly and meets our guidelines. Our guidelines are:

- Make sure the code passes the tests. To run tests, run `flutter test`.
You can simply run `make checkstyle`, and if you faced any formatting problem, run `make format`.

- Make sure to run `flutter analyze` and resolve any warnings or errors.
##### Run `make checkstyle` to ensure that your code is formatted correctly
- It runs `flutter analyze` to verify that there is no any warning or error.
- It runs `flutter format --set-exit-if-changed --dry-run --line-length 100 .` to verify that code has formatted correctly.

- The code should be formatted correctly. For Visual Studio Code users, this is
automatically enforced. Otherwise, you can run this command inside the
project from the command line: `flutter format --line-length 100 .`.
We use `flutter format --set-exit-if-changed --dry-run --line-length 100 .` command in CI.
#### Run `make format` to reformat the code
- It runs `flutter format --line-length 100 .` to format your code with 100 characters limit.


#### Run `make runTests` to ensure that all tests are passing.
- It runs `flutter test` under the hood.

## Creating a Pull Request

Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
checkstyle:
flutter analyze; \
flutter format --set-exit-if-changed --dry-run --line-length 100 .

format:
flutter format --line-length 100 .

runTests:
flutter test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Thank you all!

```yml
dependencies:
fl_chart: ^0.30.0
fl_chart: ^0.35.0
```
Expand Down
18 changes: 17 additions & 1 deletion example/lib/bar_chart/samples/bar_chart_sample1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,23 @@ class BarChartSample1State extends State<BarChartSample1> {
break;
}
return BarTooltipItem(
weekDay + '\n' + (rod.y - 1).toString(), TextStyle(color: Colors.yellow));
weekDay + '\n',
TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18,
),
children: <TextSpan>[
TextSpan(
text: (rod.y - 1).toString(),
style: TextStyle(
color: Colors.yellow,
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
],
);
}),
touchCallback: (barTouchResponse) {
setState(() {
Expand Down
17 changes: 14 additions & 3 deletions example/lib/line_chart/line_chart_page3.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:flutter/material.dart';

import 'samples/line_chart_sample6.dart';
import 'samples/line_chart_sample9.dart';

class LineChartPage3 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.min,
child: ListView(
padding: EdgeInsets.symmetric(horizontal: 28, vertical: 18),
children: <Widget>[
const Text(
'LineChart (reversed)',
Expand All @@ -20,6 +20,17 @@ class LineChartPage3 extends StatelessWidget {
height: 52,
),
LineChartSample6(),
const SizedBox(
height: 52,
),
const Text(
'LineChart (positive and negative values)',
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold, color: Colors.black),
),
const SizedBox(
height: 52,
),
LineChartSample9(),
],
),
),
Expand Down
29 changes: 27 additions & 2 deletions example/lib/line_chart/samples/line_chart_sample3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,33 @@ class _LineChartSample3State extends State<LineChartSample3> {
}

return LineTooltipItem(
'${widget.weekDays[flSpot.x.toInt()]} \n${flSpot.y} k calories',
const TextStyle(color: Colors.white),
'${widget.weekDays[flSpot.x.toInt()]} \n',
const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
children: [
TextSpan(
text: flSpot.y.toString(),
style: TextStyle(
color: Colors.grey[100],
fontWeight: FontWeight.normal,
),
),
TextSpan(
text: ' k ',
style: TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.normal,
),
),
TextSpan(
text: 'calories',
style: TextStyle(
fontWeight: FontWeight.normal,
),
),
],
);
}).toList();
}),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/line_chart/samples/line_chart_sample8.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class _LineChartSample8State extends State<LineChartSample8> {
),
),
lineTouchData: LineTouchData(
fullHeightTouchLine: true,
getTouchLineEnd: (data, index) => double.infinity,
getTouchedSpotIndicator: (LineChartBarData barData, List<int> spotIndexes) {
return spotIndexes.map((spotIndex) {
return TouchedSpotIndicatorData(
Expand Down
92 changes: 92 additions & 0 deletions example/lib/line_chart/samples/line_chart_sample9.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'dart:math';

// ignore: must_be_immutable
class LineChartSample9 extends StatelessWidget {
final spots = List.generate(101, (i) => (i - 50) / 10).map((x) => FlSpot(x, sin(x))).toList();

LineChartSample9() {}

@override
Widget build(BuildContext context) {
return Container(
child: Padding(
padding: const EdgeInsets.only(right: 22.0, bottom: 20),
child: SizedBox(
width: 400,
height: 400,
child: LineChart(
LineChartData(
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
maxContentWidth: 100,
tooltipBgColor: Colors.orange,
getTooltipItems: (touchedSpots) {
return touchedSpots.map((LineBarSpot touchedSpot) {
final textStyle = TextStyle(
color: touchedSpot.bar.colors[0],
fontWeight: FontWeight.bold,
fontSize: 14,
);
return LineTooltipItem(
'${touchedSpot.x}, ${touchedSpot.y.toStringAsFixed(2)}', textStyle);
}).toList();
}),
handleBuiltInTouches: true,
getTouchLineStart: (data, index) => 0,
),
lineBarsData: [
LineChartBarData(
colors: [
Colors.black,
],
spots: spots,
isCurved: true,
isStrokeCapRound: true,
barWidth: 3,
belowBarData: BarAreaData(
show: false,
),
dotData: FlDotData(show: false),
),
],
minY: -1.5,
maxY: 1.5,
titlesData: FlTitlesData(
leftTitles: SideTitles(
showTitles: true,
getTextStyles: (value) => const TextStyle(
color: Colors.blueGrey, fontWeight: FontWeight.bold, fontSize: 18),
margin: 16,
),
rightTitles: SideTitles(showTitles: false),
bottomTitles: SideTitles(
showTitles: true,
getTextStyles: (value) => const TextStyle(
color: Colors.blueGrey, fontWeight: FontWeight.bold, fontSize: 18),
margin: 16,
),
topTitles: SideTitles(showTitles: false),
),
gridData: FlGridData(
show: true,
drawHorizontalLine: true,
drawVerticalLine: true,
horizontalInterval: 1.5,
verticalInterval: 5,
checkToShowHorizontalLine: (value) {
return value.toInt() == 0;
},
checkToShowVerticalLine: (value) {
return value.toInt() == 0;
},
),
borderData: FlBorderData(show: false),
),
),
),
),
);
}
}
10 changes: 4 additions & 6 deletions example/lib/pie_chart/samples/pie_chart_sample3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,10 @@ class _Badge extends StatelessWidget {
),
padding: EdgeInsets.all(size * .15),
child: Center(
child: kIsWeb
? Image.network(svgAsset, fit: BoxFit.contain)
: SvgPicture.asset(
svgAsset,
fit: BoxFit.contain,
),
child: SvgPicture.asset(
svgAsset,
fit: BoxFit.contain,
),
),
);
}
Expand Down
37 changes: 37 additions & 0 deletions example/lib/scatter_chart/samples/scatter_chart_sample2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,43 @@ class _ScatterChartSample2State extends State {
handleBuiltInTouches: false,
touchTooltipData: ScatterTouchTooltipData(
tooltipBgColor: Colors.black,
getTooltipItems: (ScatterSpot touchedBarSpot) {
return ScatterTooltipItem(
'X: ',
TextStyle(
height: 1.2,
color: Colors.grey[100],
fontStyle: FontStyle.italic,
),
10,
children: [
TextSpan(
text: '${touchedBarSpot.x.toInt()} \n',
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.bold,
),
),
TextSpan(
text: 'Y: ',
style: TextStyle(
height: 1.2,
color: Colors.grey[100],
fontStyle: FontStyle.italic,
),
),
TextSpan(
text: touchedBarSpot.y.toInt().toString(),
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.bold,
),
),
],
);
},
),
touchCallback: (ScatterTouchResponse touchResponse) {
if (touchResponse.clickHappened && touchResponse.touchedSpot != null) {
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2

flutter_svg: ^0.20.0-nullsafety.3
flutter_svg: ^0.21.0-nullsafety.0

dev_dependencies:
flutter_test:
Expand Down
19 changes: 17 additions & 2 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -728,15 +728,30 @@ class BarTooltipItem with EquatableMixin {
/// TextAlign of the showing content.
final TextAlign textAlign;

/// content of the tooltip, is a [text] String with a [textStyle].
BarTooltipItem(this.text, this.textStyle, {this.textAlign = TextAlign.center});
/// Direction of showing text.
final TextDirection textDirection;

/// List<TextSpan> add further style and format to the text of the tooltip
final List<TextSpan>? children;

/// content of the tooltip, is a [text] String with a [textStyle],
/// [textDirection] and optional [children].
BarTooltipItem(
this.text,
this.textStyle, {
this.textAlign = TextAlign.center,
this.textDirection = TextDirection.ltr,
this.children,
});

/// Used for equality check, see [EquatableMixin].
@override
List<Object?> get props => [
text,
textStyle,
textAlign,
textDirection,
children,
];
}

Expand Down
Loading

0 comments on commit 2d42fdb

Please sign in to comment.