Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Jan 7, 2025
1 parent 71dbf1b commit 34630a2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 8 deletions.
45 changes: 38 additions & 7 deletions example/lib/presentation/samples/line/line_chart_sample2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,47 @@ class _LineChartSample2State extends State<LineChartSample2> {
maxX: 11,
minY: 0,
maxY: 6,
errorIndicatorData: const FlErrorIndicatorData(
show: true,
),
lineBarsData: [
LineChartBarData(
spots: const [
FlSpot(0, 3),
FlSpot(2.6, 2),
FlSpot(4.9, 5),
FlSpot(6.8, 3.1),
FlSpot(8, 4),
FlSpot(9.5, 3),
FlSpot(11, 4),
FlSpot(
0,
3,
yError: FlErrorRange.symmetric(5),
),
FlSpot(
2.6,
2,
yError: FlErrorRange.symmetric(5),
),
FlSpot(
4.9,
5,
yError: FlErrorRange.symmetric(5),
),
FlSpot(
6.8,
3.1,
yError: FlErrorRange.symmetric(5),
),
FlSpot(
8,
4,
yError: FlErrorRange.symmetric(5),
),
FlSpot(
9.5,
3,
yError: FlErrorRange.symmetric(5),
),
FlSpot(
11,
4,
yError: FlErrorRange.symmetric(5),
),
],
isCurved: true,
gradient: LinearGradient(
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c
package_info_plus: 12f1c5c2cfe8727ca46cbd0b26677728972d9a5b
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
url_launcher_macos: 5f437abeda8c85500ceb03f5c1938a8c5a705399

Expand Down
40 changes: 40 additions & 0 deletions lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
canvasWrapper.restore();
}

// Draw error indicators
for (var i = 0; i < data.lineBarsData.length; i++) {
final barData = data.lineBarsData[i];

if (!barData.show) {
continue;
}

drawErrorIndicatorData(
canvasWrapper,
barData,
data.errorIndicatorData,
holder,
);
}

// Draw touch tooltip on most top spot
for (var i = 0; i < data.showingTooltipIndicators.length; i++) {
var tooltipSpots = data.showingTooltipIndicators[i];
Expand Down Expand Up @@ -357,6 +373,30 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
}
}

@visibleForTesting
void drawErrorIndicatorData(
CanvasWrapper canvasWrapper,
LineChartBarData barData,
FlErrorIndicatorData errorIndicatorData,
PaintHolder<LineChartData> holder,
) {
if (!errorIndicatorData.show) {
return;
}

final viewSize = canvasWrapper.size;

Check warning on line 387 in lib/src/chart/line_chart/line_chart_painter.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/chart/line_chart/line_chart_painter.dart#L387

Added line #L387 was not covered by tests

for (var i = 0; i < barData.spots.length; i++) {
final spot = barData.spots[i];
if (spot.isNotNull()) {
final x = getPixelX(spot.x, viewSize, holder);
final y = getPixelY(spot.y, viewSize, holder);
final painter = errorIndicatorData.errorPainter;
canvasWrapper.drawErrorIndicator(painter, spot, Offset(x, y));

Check warning on line 395 in lib/src/chart/line_chart/line_chart_painter.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/chart/line_chart/line_chart_painter.dart#L389-L395

Added lines #L389 - L395 were not covered by tests
}
}
}

@visibleForTesting
void drawTouchedSpotsIndicator(
CanvasWrapper canvasWrapper,
Expand Down
9 changes: 9 additions & 0 deletions lib/src/utils/canvas_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CanvasWrapper {
this.canvas,
this.size,
);

final Canvas canvas;
final Size size;

Expand Down Expand Up @@ -118,6 +119,14 @@ class CanvasWrapper {
painter.draw(canvas, spot, offset);
}

void drawErrorIndicator(

Check warning on line 122 in lib/src/utils/canvas_wrapper.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/utils/canvas_wrapper.dart#L122

Added line #L122 was not covered by tests
FlSpotErrorRangePainter painter,
FlSpot origin,
Offset offset,
) {
painter.draw(canvas, offset, origin);

Check warning on line 127 in lib/src/utils/canvas_wrapper.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/utils/canvas_wrapper.dart#L127

Added line #L127 was not covered by tests
}

/// Handles performing multiple draw actions rotated.
void drawRotated({
required Size size,
Expand Down

0 comments on commit 34630a2

Please sign in to comment.