Skip to content

Commit

Permalink
Add textDirection property in LineTooltipItem, BarTooltipItem and Sca…
Browse files Browse the repository at this point in the history
…tterTooltipItem classes to support rtl languages.
  • Loading branch information
imaN Khoshabi committed Apr 1, 2021
1 parent d438b2e commit 5701a3e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [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.
* [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.
Expand Down
8 changes: 7 additions & 1 deletion lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -728,14 +728,19 @@ class BarTooltipItem with EquatableMixin {
/// TextAlign of the showing content.
final TextAlign textAlign;

/// 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] and optional [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,
});

Expand All @@ -745,6 +750,7 @@ class BarTooltipItem with EquatableMixin {
text,
textStyle,
textAlign,
textDirection,
children,
];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
final tp = TextPainter(
text: span,
textAlign: tooltipItem.textAlign,
textDirection: TextDirection.ltr,
textDirection: tooltipItem.textDirection,
textScaleFactor: holder.textScale);
tp.layout(maxWidth: tooltipData.maxContentWidth);

Expand Down
8 changes: 7 additions & 1 deletion lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1628,14 +1628,19 @@ class LineTooltipItem with EquatableMixin {
/// Align of showing text.
final TextAlign textAlign;

/// Direction of showing text.
final TextDirection textDirection;

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

/// Shows a [text] with [textStyle] and optional [children] as a row in the tooltip popup.
/// Shows a [text] with [textStyle], [textDirection],
/// and optional [children] as a row in the tooltip popup.
LineTooltipItem(
this.text,
this.textStyle, {
this.textAlign = TextAlign.center,
this.textDirection = TextDirection.ltr,
this.children,
});

Expand All @@ -1645,6 +1650,7 @@ class LineTooltipItem with EquatableMixin {
text,
textStyle,
textAlign,
textDirection,
children,
];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
final tp = TextPainter(
text: span,
textAlign: tooltipItem.textAlign,
textDirection: TextDirection.ltr,
textDirection: tooltipItem.textDirection,
textScaleFactor: holder.textScale);
tp.layout(maxWidth: tooltipData.maxContentWidth);
drawingTextPainters.add(tp);
Expand Down
11 changes: 8 additions & 3 deletions lib/src/chart/scatter_chart/scatter_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,21 +441,26 @@ class ScatterTooltipItem with EquatableMixin {
/// TextAlign of the showing content.
final TextAlign textAlign;

/// Direction of showing text.
final TextDirection textDirection;

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

/// Shows a [text] with [textStyle] and optional [children] in the tooltip popup,
/// Shows a [text] with [textStyle], [textDirection], and optional [children] in the tooltip popup,
/// [bottomMargin] is the bottom space from spot.
ScatterTooltipItem(
String text,
TextStyle textStyle,
double bottomMargin, {
TextAlign textAlign = TextAlign.center,
TextAlign? textAlign,
TextDirection? textDirection,
List<TextSpan>? children,
}) : text = text,
textStyle = textStyle,
bottomMargin = bottomMargin,
textAlign = textAlign,
textAlign = textAlign ?? TextAlign.center,
textDirection = textDirection ?? TextDirection.ltr,
children = children;

/// Used for equality check, see [EquatableMixin].
Expand Down
2 changes: 1 addition & 1 deletion lib/src/chart/scatter_chart/scatter_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData> {
final drawingTextPainter = TextPainter(
text: span,
textAlign: tooltipItem.textAlign,
textDirection: TextDirection.ltr,
textDirection: tooltipItem.textDirection,
textScaleFactor: holder.textScale);
drawingTextPainter.layout(maxWidth: tooltipData.maxContentWidth);

Expand Down
1 change: 1 addition & 0 deletions repo_files/documentations/bar_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ enum values {`start`, `end`, `center`, `spaceEvenly`, `spaceAround`, `spaceBetwe
|text|text string of each row in the tooltip bubble|null|
|textStyle|[TextStyle](https://api.flutter.dev/flutter/dart-ui/TextStyle-class.html) of the showing text row|null|
|textAlign|[TextAlign](https://api.flutter.dev/flutter/dart-ui/TextAlign-class.html) of the showing text row|TextAlign.center|
|textDirection|[TextDirection](https://api.flutter.dev/flutter/dart-ui/TextDirection-class.html) of the showing text row|TextDirection.ltr|
|children|[List<TextSpan>](https://api.flutter.dev/flutter/painting/InlineSpan-class.html) pass additional InlineSpan children for a more advance tooltip|null|


Expand Down
1 change: 1 addition & 0 deletions repo_files/documentations/line_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ When you change the chart's state, it animates to the new state internally (usin
|text|text string of each row in the tooltip bubble|null|
|textStyle|[TextStyle](https://api.flutter.dev/flutter/dart-ui/TextStyle-class.html) of the showing text row|null|
|textAlign|[TextStyle](https://api.flutter.dev/flutter/dart-ui/TextAlign-class.html) of the showing text row|TextAlign.center|
|textDirection|[TextDirection](https://api.flutter.dev/flutter/dart-ui/TextDirection-class.html) of the showing text row|TextDirection.ltr|
|children|[List<TextSpan>](https://api.flutter.dev/flutter/painting/InlineSpan-class.html) pass additional InlineSpan children for a more advance tooltip|null|

### TouchedSpotIndicatorData
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 @@ -61,6 +61,7 @@ When you change the chart's state, it animates to the new state internally (usin
|:-------|:----------|:------------|
|text|text string of each row in the tooltip bubble|null|
|textStyle|[TextStyle](https://api.flutter.dev/flutter/dart-ui/TextStyle-class.html) of the showing text row|null|
|textDirection|[TextDirection](https://api.flutter.dev/flutter/dart-ui/TextDirection-class.html) of the showing text row|TextDirection.ltr|
|bottomMargin| bottom margin of the tooltip (to the top of most top spot) | radius / 2|
|children|[List<TextSpan>](https://api.flutter.dev/flutter/painting/InlineSpan-class.html) pass additional InlineSpan children for a more advance tooltip|null|

Expand Down

0 comments on commit 5701a3e

Please sign in to comment.