Skip to content

Commit

Permalink
Merge pull request #510 from imaNNeoFighT/improvement/bar-area-spotli…
Browse files Browse the repository at this point in the history
…nes-applycutoffy

Added applyCutOffY property in BarAreaSpotsLine to inherit cutOffY pr…
  • Loading branch information
imaNNeo authored Dec 11, 2020
2 parents f98901a + b609ec7 commit dcb22f0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
9 changes: 8 additions & 1 deletion lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -688,23 +688,29 @@ class BarAreaSpotsLine with EquatableMixin {
/// Checks to show or hide lines on the spots.
final CheckToShowSpotLine checkToShowSpotLine;

/// Determines to inherit the cutOff properties from its parent [BarAreaData]
final bool applyCutOffY;

/// If [show] is true, [LineChart] draws some lines on above or below the spots,
/// you can customize the appearance of the lines using [flLineStyle]
/// and you can decide to show or hide the lines on each spot using [checkToShowSpotLine].
BarAreaSpotsLine({
bool show,
FlLine flLineStyle,
CheckToShowSpotLine checkToShowSpotLine,
bool applyCutOffY,
}) : show = show ?? false,
flLineStyle = flLineStyle ?? FlLine(),
checkToShowSpotLine = checkToShowSpotLine ?? showAllSpotsBelowLine;
checkToShowSpotLine = checkToShowSpotLine ?? showAllSpotsBelowLine,
applyCutOffY = applyCutOffY ?? true;

/// Lerps a [BarAreaSpotsLine] based on [t] value, check [Tween.lerp].
static BarAreaSpotsLine lerp(BarAreaSpotsLine a, BarAreaSpotsLine b, double t) {
return BarAreaSpotsLine(
show: b.show,
checkToShowSpotLine: b.checkToShowSpotLine,
flLineStyle: FlLine.lerp(a.flLineStyle, b.flLineStyle, t),
applyCutOffY: b.applyCutOffY,
);
}

Expand All @@ -714,6 +720,7 @@ class BarAreaSpotsLine with EquatableMixin {
show,
flLineStyle,
checkToShowSpotLine,
applyCutOffY,
];
}

Expand Down
36 changes: 28 additions & 8 deletions lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,20 @@ class LineChartPainter extends AxisChartPainter<LineChartData>
);

final double bottomPadding = getExtraNeededVerticalSpace() - getTopOffsetDrawSize();
final Offset to = Offset(
getPixelX(spot.x, chartViewSize),
viewSize.height - bottomPadding,
);
Offset to;

// Check applyCutOffY
if (barData.belowBarData.spotsLine.applyCutOffY && barData.belowBarData.applyCutOffY) {
to = Offset(
getPixelX(spot.x, chartViewSize),
getPixelY(barData.belowBarData.cutOffY, chartViewSize),
);
} else {
to = Offset(
getPixelX(spot.x, chartViewSize),
viewSize.height - bottomPadding,
);
}

_barAreaLinesPaint.color = barData.belowBarData.spotsLine.flLineStyle.color;
_barAreaLinesPaint.strokeWidth = barData.belowBarData.spotsLine.flLineStyle.strokeWidth;
Expand Down Expand Up @@ -670,10 +680,20 @@ class LineChartPainter extends AxisChartPainter<LineChartData>
getPixelY(spot.y, chartViewSize),
);

final Offset to = Offset(
getPixelX(spot.x, chartViewSize),
getTopOffsetDrawSize(),
);
Offset to;

// Check applyCutOffY
if (barData.aboveBarData.spotsLine.applyCutOffY && barData.aboveBarData.applyCutOffY) {
to = Offset(
getPixelX(spot.x, chartViewSize),
getPixelY(barData.aboveBarData.cutOffY, chartViewSize),
);
} else {
to = Offset(
getPixelX(spot.x, chartViewSize),
getTopOffsetDrawSize(),
);
}

_barAreaLinesPaint.color = barData.aboveBarData.spotsLine.flLineStyle.color;
_barAreaLinesPaint.strokeWidth = barData.aboveBarData.spotsLine.flLineStyle.strokeWidth;
Expand Down
2 changes: 1 addition & 1 deletion repo_files/documentations/line_chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ LineChart(
|show|determines show or hide the below, or above spots line|true|
|flLineStyle|a [FlLine](base_chart.md#FlLine) object that determines style of the line|[Colors.blueGrey]|
|checkToShowSpotLine|a function to determine whether to show or hide the below or above line on the given spot|showAllSpotsBelowLine|

|applyCutOffY|Determines to inherit the cutOff properties from its parent [BarAreaData](#BarAreaData)|true|

### FlDotData
|PropName|Description|default value|
Expand Down

0 comments on commit dcb22f0

Please sign in to comment.