From 5b3bdc1d58e26dd4bbcc7150ff1fc2afbb232f54 Mon Sep 17 00:00:00 2001 From: imaN Khoshabi Date: Thu, 1 Apr 2021 17:34:19 +0430 Subject: [PATCH] Add `textDirection` property in AxisTitles class. --- CHANGELOG.md | 1 + lib/src/chart/base/axis_chart/axis_chart_data.dart | 6 ++++++ lib/src/chart/base/axis_chart/axis_chart_painter.dart | 8 ++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19fcc27a4..abc8b8638 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [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. 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 12348144c..f8cb2a7a7 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_data.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_data.dart @@ -134,6 +134,9 @@ class AxisTitle with EquatableMixin { /// Determines alignment of this title. final TextAlign textAlign; + /// Determines direction of this title + final TextDirection textDirection; + /// Determines margin of this title. final double margin; @@ -141,6 +144,7 @@ class AxisTitle with EquatableMixin { /// [titleText] determines the text, and /// [textStyle] determines the style of this. /// [textAlign] determines alignment of this title, + /// [textDirection] determines direction of this title. /// [BaseChartPainter] uses [reservedSize] for assigning /// a space for drawing this side title, it used for /// some calculations. @@ -161,6 +165,7 @@ class AxisTitle with EquatableMixin { color: Colors.black, fontSize: 11, ), + textDirection = textDirection ?? TextDirection.ltr, textAlign = textAlign ?? TextAlign.center, margin = margin ?? 4; @@ -172,6 +177,7 @@ class AxisTitle with EquatableMixin { reservedSize: lerpDouble(a.reservedSize, b.reservedSize, t), textStyle: TextStyle.lerp(a.textStyle.copyWith(fontSize: a.textStyle.fontSize), b.textStyle.copyWith(fontSize: b.textStyle.fontSize), t), + textDirection: b.textDirection, textAlign: b.textAlign, margin: lerpDouble(a.margin, b.margin, t), ); diff --git a/lib/src/chart/base/axis_chart/axis_chart_painter.dart b/lib/src/chart/base/axis_chart/axis_chart_painter.dart index 18b743c5b..f484db56d 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_painter.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_painter.dart @@ -59,7 +59,7 @@ abstract class AxisChartPainter extends BaseChartPainte final tp = TextPainter( text: span, textAlign: leftTitle.textAlign, - textDirection: TextDirection.ltr, + textDirection: leftTitle.textDirection, textScaleFactor: holder.textScale); tp.layout(minWidth: viewSize.height); canvasWrapper.save(); @@ -78,7 +78,7 @@ abstract class AxisChartPainter extends BaseChartPainte final tp = TextPainter( text: span, textAlign: topTitle.textAlign, - textDirection: TextDirection.ltr, + textDirection: topTitle.textDirection, textScaleFactor: holder.textScale); tp.layout(minWidth: viewSize.width); canvasWrapper.drawText( @@ -92,7 +92,7 @@ abstract class AxisChartPainter extends BaseChartPainte final tp = TextPainter( text: span, textAlign: rightTitle.textAlign, - textDirection: TextDirection.ltr, + textDirection: rightTitle.textDirection, textScaleFactor: holder.textScale); tp.layout(minWidth: viewSize.height); canvasWrapper.save(); @@ -111,7 +111,7 @@ abstract class AxisChartPainter extends BaseChartPainte final tp = TextPainter( text: span, textAlign: bottomTitle.textAlign, - textDirection: TextDirection.ltr, + textDirection: bottomTitle.textDirection, textScaleFactor: holder.textScale); tp.layout(minWidth: viewSize.width); canvasWrapper.drawText(