Skip to content

Commit

Permalink
Add textDirection property in AxisTitles class.
Browse files Browse the repository at this point in the history
  • Loading branch information
imaN Khoshabi committed Apr 1, 2021
1 parent 72afa50 commit 5b3bdc1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 @@ -134,13 +134,17 @@ 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;

/// You can show or hide it using [showTitle],
/// [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.
Expand All @@ -161,6 +165,7 @@ class AxisTitle with EquatableMixin {
color: Colors.black,
fontSize: 11,
),
textDirection = textDirection ?? TextDirection.ltr,
textAlign = textAlign ?? TextAlign.center,
margin = margin ?? 4;

Expand All @@ -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),
);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/chart/base/axis_chart/axis_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class AxisChartPainter<D extends AxisChartData> 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();
Expand All @@ -78,7 +78,7 @@ abstract class AxisChartPainter<D extends AxisChartData> 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(
Expand All @@ -92,7 +92,7 @@ abstract class AxisChartPainter<D extends AxisChartData> 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();
Expand All @@ -111,7 +111,7 @@ abstract class AxisChartPainter<D extends AxisChartData> 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(
Expand Down

0 comments on commit 5b3bdc1

Please sign in to comment.