Skip to content

Commit

Permalink
Add textDirection property in SideTitles class
Browse files Browse the repository at this point in the history
  • Loading branch information
imaN Khoshabi committed Apr 1, 2021
1 parent 5701a3e commit 043d23f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [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. It allows you to support rtl languages in side 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.
Expand Down
8 changes: 4 additions & 4 deletions lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: leftTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout(maxWidth: getExtraNeededHorizontalSpace(holder));
x -= tp.width + leftTitles.margin;
Expand Down Expand Up @@ -386,7 +386,7 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: topTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout();
var x = groupBarPos.groupX;
Expand Down Expand Up @@ -421,7 +421,7 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: rightTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout(maxWidth: getExtraNeededHorizontalSpace(holder));
x += rightTitles.margin;
Expand Down Expand Up @@ -455,7 +455,7 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: bottomTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout();
var x = groupBarPos.groupX;
Expand Down
6 changes: 6 additions & 0 deletions lib/src/chart/base/axis_chart/axis_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class SideTitles with EquatableMixin {
final GetTitleFunction getTitles;
final double reservedSize;
final GetTitleTextStyleFunction getTextStyles;
final TextDirection textDirection;
final double margin;
final double? interval;
final double rotateAngle;
Expand All @@ -267,6 +268,9 @@ class SideTitles with EquatableMixin {
/// It gives you an axis value (double value), and you should return a TextStyle based on it,
/// It works just like [getTitles]
///
/// [textDirection] specifies the direction of showing text.
/// it applies on all showing titles in this side.
///
/// [margin] determines margin of texts from the border line,
///
/// texts are showing with provided [interval],
Expand All @@ -280,6 +284,7 @@ class SideTitles with EquatableMixin {
GetTitleFunction? getTitles,
double? reservedSize,
GetTitleTextStyleFunction? getTextStyles,
TextDirection? textDirection,
double? margin,
double? interval,
double? rotateAngle,
Expand All @@ -288,6 +293,7 @@ class SideTitles with EquatableMixin {
getTitles = getTitles ?? defaultGetTitle,
reservedSize = reservedSize ?? 22,
getTextStyles = getTextStyles ?? defaultGetTitleTextStyle,
textDirection = textDirection ?? TextDirection.ltr,
margin = margin ?? 6,
interval = interval,
rotateAngle = rotateAngle ?? 0.0,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: leftTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout(maxWidth: getExtraNeededHorizontalSpace(holder));
x -= tp.width + leftTitles.margin;
Expand Down Expand Up @@ -897,7 +897,7 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: topTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout();

Expand Down Expand Up @@ -937,7 +937,7 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: rightTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout(maxWidth: getExtraNeededHorizontalSpace(holder));

Expand Down Expand Up @@ -976,7 +976,7 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: bottomTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout();

Expand Down
8 changes: 4 additions & 4 deletions lib/src/chart/scatter_chart/scatter_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: leftTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout(maxWidth: getExtraNeededHorizontalSpace(holder));
x -= tp.width + leftTitles.margin;
Expand Down Expand Up @@ -118,7 +118,7 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: topTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout();

Expand Down Expand Up @@ -158,7 +158,7 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: rightTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout(maxWidth: getExtraNeededHorizontalSpace(holder));

Expand Down Expand Up @@ -198,7 +198,7 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData> {
final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textDirection: bottomTitles.textDirection,
textScaleFactor: holder.textScale);
tp.layout();

Expand Down

0 comments on commit 043d23f

Please sign in to comment.