Skip to content

Commit

Permalink
Add angle property in the HorizontalLineLabel and VerticalLineLabel…
Browse files Browse the repository at this point in the history
… classes to make it possible to rotate the labels in degrees, #1261
  • Loading branch information
imaNNeo committed Nov 5, 2023
1 parent 696bb2d commit 926fe36
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## nextVersion
* **FEATURE** (by @Dartek12): Added gradient to [FlLine](https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/base_chart.md#FlLine)
* **FEATURE** (by @Dartek12): Added gradient to [FlLine](https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/base_chart.md#FlLine)
* **FEATURE** (by @imaNNeo) Add `angle` property in the [HorizontalLineLabel](https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/base_chart.md#horizontallinelabel) and [VerticalLineLabel](https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/base_chart.md#verticallinelabel) classes to make it possible to rotate the labels in degrees, #1261

## 0.64.0
* **BUGFIX** (by @Anas35) Fix Tooltip not displaying when value from BackgroundBarChartRodData is less than zero. #1345.
Expand Down
8 changes: 7 additions & 1 deletion lib/src/chart/base/axis_chart/axis_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1124,13 +1124,14 @@ class HorizontalLineLabel extends FlLineLabel with EquatableMixin {
/// size, ... of the text.
/// Drawing text will retrieve through [labelResolver],
/// you can override it with your custom data.
/// /// [show] determines showing label or not.
/// [show] determines showing label or not.
HorizontalLineLabel({
EdgeInsets? padding,
super.style,
Alignment? alignment,
super.show = false,
String Function(HorizontalLine)? labelResolver,
super.angle = 0.0,
}) : labelResolver =
labelResolver ?? HorizontalLineLabel.defaultLineLabelResolver,
super(
Expand Down Expand Up @@ -1158,6 +1159,7 @@ class HorizontalLineLabel extends FlLineLabel with EquatableMixin {
alignment: Alignment.lerp(a.alignment, b.alignment, t),
labelResolver: b.labelResolver,
show: b.show,
angle: lerpDouble(a.angle, b.angle, t)!,
);
}

Expand All @@ -1169,6 +1171,7 @@ class HorizontalLineLabel extends FlLineLabel with EquatableMixin {
padding,
style,
alignment,
angle,
];
}

Expand All @@ -1186,6 +1189,7 @@ class VerticalLineLabel extends FlLineLabel with EquatableMixin {
Alignment? alignment,
bool? show,
String Function(VerticalLine)? labelResolver,
super.angle = 0.0,
}) : labelResolver =
labelResolver ?? VerticalLineLabel.defaultLineLabelResolver,
super(
Expand Down Expand Up @@ -1220,6 +1224,7 @@ class VerticalLineLabel extends FlLineLabel with EquatableMixin {
alignment: Alignment.lerp(a.alignment, b.alignment, t),
labelResolver: b.labelResolver,
show: b.show,
angle: lerpDouble(a.angle, b.angle, t)!,
);
}

Expand All @@ -1231,6 +1236,7 @@ class VerticalLineLabel extends FlLineLabel with EquatableMixin {
padding,
style,
alignment,
angle,
];
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/chart/base/axis_chart/axis_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ abstract class AxisChartPainter<D extends AxisChartData>
to.dy + padding.top,
),
),
label.angle,

Check warning on line 318 in lib/src/chart/base/axis_chart/axis_chart_painter.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/chart/base/axis_chart/axis_chart_painter.dart#L318

Added line #L318 was not covered by tests
);
}
}
Expand Down Expand Up @@ -408,6 +409,7 @@ abstract class AxisChartPainter<D extends AxisChartData>
to.dy - padding.bottom,
),
),
label.angle,

Check warning on line 412 in lib/src/chart/base/axis_chart/axis_chart_painter.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/chart/base/axis_chart/axis_chart_painter.dart#L412

Added line #L412 was not covered by tests
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ abstract class FlLineLabel with EquatableMixin {
required this.padding,
required this.style,
required this.alignment,
this.angle = 0,
});

/// Determines showing label or not.
Expand All @@ -1031,13 +1032,17 @@ abstract class FlLineLabel with EquatableMixin {
/// Aligns the text on the line.
final Alignment alignment;

/// [angle] is used to rotate the label (in degrees)
final double angle;

/// Used for equality check, see [EquatableMixin].
@override
List<Object?> get props => [
show,
padding,
style,
alignment,
angle,
];
}

Expand Down
2 changes: 2 additions & 0 deletions repo_files/documentations/base_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Base class for all supported touch/pointer events.
|style|[TextStyle](https://api.flutter.dev/flutter/dart-ui/TextStyle-class.html) which determines label text style|TextStyle(fontSize: 11, color: line.color)|
|alignment|[Alignment](https://api.flutter.dev/flutter/painting/Alignment-class.html) with label position relative to line|Alignment.topLeft|
|labelResolver|Getter function returning label title|defaultLineLabelResolver|
|angle|Angle of the label in degrees|0|

### VerticalLineLabel
|PropName|Description|default value|
Expand All @@ -176,6 +177,7 @@ Base class for all supported touch/pointer events.
|style|[TextStyle](https://api.flutter.dev/flutter/dart-ui/TextStyle-class.html) which determines label text style|TextStyle(fontSize: 11, color: line.color)|
|alignment|[Alignment](https://api.flutter.dev/flutter/painting/Alignment-class.html) with label position relative to line|Alignment.topLeft|
|labelResolver|Getter function returning label title|defaultLineLabelResolver|
|angle|Angle of the label in degrees|0|

### FLHorizontalAlignment
enum values {`center`, `left`, `right`}

0 comments on commit 926fe36

Please sign in to comment.