From 043d23ff9db4aa5654a112132cf0f75345b5d2db Mon Sep 17 00:00:00 2001 From: imaN Khoshabi Date: Thu, 1 Apr 2021 17:27:38 +0430 Subject: [PATCH] Add `textDirection` property in SideTitles class --- CHANGELOG.md | 1 + lib/src/chart/bar_chart/bar_chart_painter.dart | 8 ++++---- lib/src/chart/base/axis_chart/axis_chart_data.dart | 6 ++++++ lib/src/chart/line_chart/line_chart_painter.dart | 8 ++++---- lib/src/chart/scatter_chart/scatter_chart_painter.dart | 8 ++++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2609d9ccc2..4a8a8fe19d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/src/chart/bar_chart/bar_chart_painter.dart b/lib/src/chart/bar_chart/bar_chart_painter.dart index 678b715d76..aac4320f39 100644 --- a/lib/src/chart/bar_chart/bar_chart_painter.dart +++ b/lib/src/chart/bar_chart/bar_chart_painter.dart @@ -353,7 +353,7 @@ class BarChartPainter extends AxisChartPainter { 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; @@ -386,7 +386,7 @@ class BarChartPainter extends AxisChartPainter { final tp = TextPainter( text: span, textAlign: TextAlign.center, - textDirection: TextDirection.ltr, + textDirection: topTitles.textDirection, textScaleFactor: holder.textScale); tp.layout(); var x = groupBarPos.groupX; @@ -421,7 +421,7 @@ class BarChartPainter extends AxisChartPainter { 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; @@ -455,7 +455,7 @@ class BarChartPainter extends AxisChartPainter { final tp = TextPainter( text: span, textAlign: TextAlign.center, - textDirection: TextDirection.ltr, + textDirection: bottomTitles.textDirection, textScaleFactor: holder.textScale); tp.layout(); var x = groupBarPos.groupX; diff --git a/lib/src/chart/base/axis_chart/axis_chart_data.dart b/lib/src/chart/base/axis_chart/axis_chart_data.dart index 3860e5bfbd..73b7122616 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_data.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_data.dart @@ -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; @@ -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], @@ -280,6 +284,7 @@ class SideTitles with EquatableMixin { GetTitleFunction? getTitles, double? reservedSize, GetTitleTextStyleFunction? getTextStyles, + TextDirection? textDirection, double? margin, double? interval, double? rotateAngle, @@ -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, diff --git a/lib/src/chart/line_chart/line_chart_painter.dart b/lib/src/chart/line_chart/line_chart_painter.dart index cbe2c32781..d0f9dcadd3 100644 --- a/lib/src/chart/line_chart/line_chart_painter.dart +++ b/lib/src/chart/line_chart/line_chart_painter.dart @@ -858,7 +858,7 @@ class LineChartPainter extends AxisChartPainter { 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; @@ -897,7 +897,7 @@ class LineChartPainter extends AxisChartPainter { final tp = TextPainter( text: span, textAlign: TextAlign.center, - textDirection: TextDirection.ltr, + textDirection: topTitles.textDirection, textScaleFactor: holder.textScale); tp.layout(); @@ -937,7 +937,7 @@ class LineChartPainter extends AxisChartPainter { final tp = TextPainter( text: span, textAlign: TextAlign.center, - textDirection: TextDirection.ltr, + textDirection: rightTitles.textDirection, textScaleFactor: holder.textScale); tp.layout(maxWidth: getExtraNeededHorizontalSpace(holder)); @@ -976,7 +976,7 @@ class LineChartPainter extends AxisChartPainter { final tp = TextPainter( text: span, textAlign: TextAlign.center, - textDirection: TextDirection.ltr, + textDirection: bottomTitles.textDirection, textScaleFactor: holder.textScale); tp.layout(); diff --git a/lib/src/chart/scatter_chart/scatter_chart_painter.dart b/lib/src/chart/scatter_chart/scatter_chart_painter.dart index 5efd492bcd..92fc2d4278 100644 --- a/lib/src/chart/scatter_chart/scatter_chart_painter.dart +++ b/lib/src/chart/scatter_chart/scatter_chart_painter.dart @@ -79,7 +79,7 @@ class ScatterChartPainter extends AxisChartPainter { 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; @@ -118,7 +118,7 @@ class ScatterChartPainter extends AxisChartPainter { final tp = TextPainter( text: span, textAlign: TextAlign.center, - textDirection: TextDirection.ltr, + textDirection: topTitles.textDirection, textScaleFactor: holder.textScale); tp.layout(); @@ -158,7 +158,7 @@ class ScatterChartPainter extends AxisChartPainter { final tp = TextPainter( text: span, textAlign: TextAlign.center, - textDirection: TextDirection.ltr, + textDirection: rightTitles.textDirection, textScaleFactor: holder.textScale); tp.layout(maxWidth: getExtraNeededHorizontalSpace(holder)); @@ -198,7 +198,7 @@ class ScatterChartPainter extends AxisChartPainter { final tp = TextPainter( text: span, textAlign: TextAlign.center, - textDirection: TextDirection.ltr, + textDirection: bottomTitles.textDirection, textScaleFactor: holder.textScale); tp.layout();