Skip to content

Commit

Permalink
Added preventCurveOvershootingThreshold in LineChartBarData for a…
Browse files Browse the repository at this point in the history
…pplying prevent overshooting algorithm, #193.
  • Loading branch information
imaNNeo committed Mar 8, 2020
1 parent 9d842c5 commit c26abf7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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 @@ -221,6 +221,9 @@ class LineChartBarData {
/// prevent overshooting when draw curve line on linear sequence spots
/// check this [issue](https://github.com/imaNNeoFighT/fl_chart/issues/25)
final bool preventCurveOverShooting;

/// threshold for applying prevent overshooting algorithm
final double preventCurveOvershootingThreshold;

final bool isStrokeCapRound;

Expand Down Expand Up @@ -249,6 +252,7 @@ class LineChartBarData {
this.isCurved = false,
this.curveSmoothness = 0.35,
this.preventCurveOverShooting = false,
this.preventCurveOvershootingThreshold = 10.0,
this.isStrokeCapRound = false,
this.belowBarData = const BarAreaData(),
this.aboveBarData = const BarAreaData(),
Expand All @@ -266,6 +270,7 @@ class LineChartBarData {
isCurved: b.isCurved,
isStrokeCapRound: b.isStrokeCapRound,
preventCurveOverShooting: b.preventCurveOverShooting,
preventCurveOvershootingThreshold: lerpDouble(a.preventCurveOvershootingThreshold, b.preventCurveOvershootingThreshold, t),
dotData: FlDotData.lerp(a.dotData, b.dotData, t),
dashArray: lerpIntList(a.dashArray, b.dashArray, t),
colors: lerpColorList(a.colors, b.colors, t),
Expand Down
6 changes: 4 additions & 2 deletions lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,13 @@ class LineChartPainter extends AxisChartPainter<LineChartData>
temp = ((next - previous) / 2) * smoothness;

if (barData.preventCurveOverShooting) {
if ((next - current).dy <= 10 || (current - previous).dy <= 10) {
if ((next - current).dy <= barData.preventCurveOvershootingThreshold
|| (current - previous).dy <= barData.preventCurveOvershootingThreshold) {
temp = Offset(temp.dx, 0);
}

if ((next - current).dx <= 10 || (current - previous).dx <= 10) {
if ((next - current).dx <= barData.preventCurveOvershootingThreshold
|| (current - previous).dx <= barData.preventCurveOvershootingThreshold) {
temp = Offset(0, temp.dy);
}
}
Expand Down
1 change: 1 addition & 0 deletions repo_files/documentations/line_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ LineChart(
|isCurved| curves the corners of the line on the spot's positions| false|
|curveSmoothness| smoothness radius of the curve corners (works when isCurved is true) | 0.35|
|preventCurveOverShooting|prevent overshooting when draw curve line on linear sequence spots, check this [issue](https://github.com/imaNNeoFighT/fl_chart/issues/25)| false|
|preventCurveOvershootingThreshold|threshold for applying prevent overshooting algorithm | 10.0|
|isStrokeCapRound| determines whether start and end of the bar line is Qubic or Round | false|
|belowBarData| check the [BarAreaData](#BarAreaData) |BarAreaData|
|aboveBarData| check the [BarAreaData](#BarAreaData) |BarAreaData|
Expand Down

0 comments on commit c26abf7

Please sign in to comment.