From 291f6ef2d60ac6db4239e2ac8b9df21ec44caf4c Mon Sep 17 00:00:00 2001 From: Iman Khoshabi Date: Fri, 18 Feb 2022 19:27:28 +0330 Subject: [PATCH] Remove getChartUsableDrawSize, getExtraNeededHorizontalSpace, getExtraNeededVerticalSpace, getLeftOffsetDrawSize, and getTopOffsetDrawSize functions from base_chart_painter --- .../chart/bar_chart/bar_chart_painter.dart | 46 ++- .../base/axis_chart/axis_chart_painter.dart | 67 ++-- .../base/base_chart/base_chart_painter.dart | 44 +-- .../chart/line_chart/line_chart_painter.dart | 187 +++++------ .../scatter_chart/scatter_chart_painter.dart | 38 +-- .../bar_chart/bar_chart_painter_test.dart | 100 ------ test/chart/data_pool.dart | 148 +++++++++ .../line_chart/line_chart_painter_test.dart | 301 ------------------ .../pie_chart/pie_chart_painter_test.dart | 16 - .../radar_chart/radar_chart_painter_test.dart | 15 - .../scatter_chart_painter_test.dart | 98 ------ 11 files changed, 284 insertions(+), 776 deletions(-) diff --git a/lib/src/chart/bar_chart/bar_chart_painter.dart b/lib/src/chart/bar_chart/bar_chart_painter.dart index b123f56e96..282977908a 100644 --- a/lib/src/chart/bar_chart/bar_chart_painter.dart +++ b/lib/src/chart/bar_chart/bar_chart_painter.dart @@ -117,7 +117,6 @@ class BarChartPainter extends AxisChartPainter { ) { final data = holder.data; final viewSize = canvasWrapper.size; - final drawSize = getChartUsableDrawSize(viewSize, holder); for (var i = 0; i < data.barGroups.length; i++) { final barGroup = data.barGroups[i]; @@ -145,11 +144,11 @@ class BarChartPainter extends AxisChartPainter { // positive final bottom = getPixelY( max(data.minY, barRod.backDrawRodData.fromY), - drawSize, + viewSize, holder, ); final top = min( - getPixelY(barRod.backDrawRodData.toY, drawSize, holder), + getPixelY(barRod.backDrawRodData.toY, viewSize, holder), bottom - cornerHeight, ); @@ -167,11 +166,11 @@ class BarChartPainter extends AxisChartPainter { // negative final top = getPixelY( min(data.maxY, barRod.backDrawRodData.fromY), - drawSize, + viewSize, holder, ); final bottom = max( - getPixelY(barRod.backDrawRodData.toY, drawSize, holder), + getPixelY(barRod.backDrawRodData.toY, viewSize, holder), top + cornerHeight, ); @@ -201,9 +200,9 @@ class BarChartPainter extends AxisChartPainter { if (barRod.toY > barRod.fromY) { // positive final bottom = - getPixelY(max(data.minY, barRod.fromY), drawSize, holder); + getPixelY(max(data.minY, barRod.fromY), viewSize, holder); final top = min( - getPixelY(barRod.toY, drawSize, holder), bottom - cornerHeight); + getPixelY(barRod.toY, viewSize, holder), bottom - cornerHeight); barRRect = RRect.fromLTRBAndCorners(left, top, right, bottom, topLeft: borderRadius.topLeft, @@ -213,9 +212,9 @@ class BarChartPainter extends AxisChartPainter { } else { // negative final top = - getPixelY(min(data.maxY, barRod.fromY), drawSize, holder); + getPixelY(min(data.maxY, barRod.fromY), viewSize, holder); final bottom = max( - getPixelY(barRod.toY, drawSize, holder), top + cornerHeight); + getPixelY(barRod.toY, viewSize, holder), top + cornerHeight); barRRect = RRect.fromLTRBAndCorners(left, top, right, bottom, topLeft: borderRadius.topLeft, @@ -241,8 +240,8 @@ class BarChartPainter extends AxisChartPainter { if (barRod.rodStackItems.isNotEmpty) { for (var i = 0; i < barRod.rodStackItems.length; i++) { final stackItem = barRod.rodStackItems[i]; - final stackFromY = getPixelY(stackItem.fromY, drawSize, holder); - final stackToY = getPixelY(stackItem.toY, drawSize, holder); + final stackFromY = getPixelY(stackItem.fromY, viewSize, holder); + final stackToY = getPixelY(stackItem.toY, viewSize, holder); _barPaint.color = stackItem.color; canvasWrapper.save(); @@ -259,7 +258,7 @@ class BarChartPainter extends AxisChartPainter { barRod.rodStackItems.length, barRod.width, barRRect, - drawSize, + viewSize, holder); } } @@ -281,7 +280,6 @@ class BarChartPainter extends AxisChartPainter { PaintHolder holder, ) { final viewSize = canvasWrapper.size; - final chartUsableSize = getChartUsableDrawSize(viewSize, holder); const textsBelowMargin = 4; @@ -327,13 +325,13 @@ class BarChartPainter extends AxisChartPainter { /// we should get the most top FlSpot Offset to draw the tooltip on top of it final barOffset = Offset( groupPositions[barGroupIndex].barsX[barRodIndex], - getPixelY(showOnRodData.toY, chartUsableSize, holder), + getPixelY(showOnRodData.toY, viewSize, holder), ); final tooltipWidth = textWidth + tooltipData.tooltipPadding.horizontal; final tooltipHeight = textHeight + tooltipData.tooltipPadding.vertical; - final zeroY = getPixelY(0, chartUsableSize, holder); + final zeroY = getPixelY(0, viewSize, holder); final barTopY = min(zeroY, barOffset.dy); final barBottomY = max(zeroY, barOffset.dy); final drawTooltipOnTop = tooltipData.direction == TooltipDirection.top || @@ -508,8 +506,6 @@ class BarChartPainter extends AxisChartPainter { calculateGroupAndBarsPosition(viewSize, groupsX, data.barGroups); } - final chartViewSize = getChartUsableDrawSize(viewSize, holder); - /// Find the nearest barRod for (var i = 0; i < _groupBarsPosition!.length; i++) { final groupBarPos = _groupBarsPosition![i]; @@ -524,17 +520,17 @@ class BarChartPainter extends AxisChartPainter { final isPositive = targetData.barGroups[i].barRods[j].toY > 0; if (isPositive) { barTopY = getPixelY( - targetData.barGroups[i].barRods[j].toY, chartViewSize, holder); - barBotY = getPixelY(0, chartViewSize, holder); + targetData.barGroups[i].barRods[j].toY, viewSize, holder); + barBotY = getPixelY(0, viewSize, holder); } else { - barTopY = getPixelY(0, chartViewSize, holder); + barTopY = getPixelY(0, viewSize, holder); barBotY = getPixelY( - targetData.barGroups[i].barRods[j].toY, chartViewSize, holder); + targetData.barGroups[i].barRods[j].toY, viewSize, holder); } final backDrawBarY = getPixelY( targetData.barGroups[i].barRods[j].backDrawRodData.toY, - chartViewSize, + viewSize, holder); final touchExtraThreshold = targetData.barTouchData.touchExtraThreshold; @@ -568,7 +564,7 @@ class BarChartPainter extends AxisChartPainter { final nearestSpot = FlSpot(nearestGroup.x.toDouble(), nearestBarRod.toY); final nearestSpotPos = - Offset(barX, getPixelY(nearestSpot.y, chartViewSize, holder)); + Offset(barX, getPixelY(nearestSpot.y, viewSize, holder)); var touchedStackIndex = -1; BarChartRodStackItem? touchedStack; @@ -576,8 +572,8 @@ class BarChartPainter extends AxisChartPainter { stackIndex < nearestBarRod.rodStackItems.length; stackIndex++) { final stackItem = nearestBarRod.rodStackItems[stackIndex]; - final fromPixel = getPixelY(stackItem.fromY, chartViewSize, holder); - final toPixel = getPixelY(stackItem.toY, chartViewSize, holder); + final fromPixel = getPixelY(stackItem.fromY, viewSize, holder); + final toPixel = getPixelY(stackItem.toY, viewSize, holder); if (touchedPoint.dy <= fromPixel && touchedPoint.dy >= toPixel) { touchedStackIndex = stackIndex; touchedStack = stackItem; diff --git a/lib/src/chart/base/axis_chart/axis_chart_painter.dart b/lib/src/chart/base/axis_chart/axis_chart_painter.dart index c8106b6fce..d166f8fd01 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_painter.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_painter.dart @@ -46,12 +46,11 @@ abstract class AxisChartPainter return; } final viewSize = canvasWrapper.size; - final usableViewSize = getChartUsableDrawSize(viewSize, holder); // Show Vertical Grid if (data.gridData.drawVerticalLine) { final verticalInterval = data.gridData.verticalInterval ?? Utils().getEfficientInterval( - usableViewSize.width, + viewSize.width, data.horizontalDiff, ); AxisChartHelper().iterateThroughAxis( @@ -68,11 +67,11 @@ abstract class AxisChartPainter _gridPaint.strokeWidth = flLineStyle.strokeWidth; _gridPaint.transparentIfWidthIsZero(); - final bothX = getPixelX(axisValue, usableViewSize, holder); + final bothX = getPixelX(axisValue, viewSize, holder); final x1 = bothX; - final y1 = 0 + getTopOffsetDrawSize(holder); + const y1 = 0.0; final x2 = bothX; - final y2 = usableViewSize.height + getTopOffsetDrawSize(holder); + final y2 = viewSize.height; canvasWrapper.drawDashedLine(Offset(x1, y1), Offset(x2, y2), _gridPaint, flLineStyle.dashArray); } @@ -83,8 +82,7 @@ abstract class AxisChartPainter // Show Horizontal Grid if (data.gridData.drawHorizontalLine) { final horizontalInterval = data.gridData.horizontalInterval ?? - Utils() - .getEfficientInterval(usableViewSize.height, data.verticalDiff); + Utils().getEfficientInterval(viewSize.height, data.verticalDiff); AxisChartHelper().iterateThroughAxis( min: data.minY, @@ -100,10 +98,10 @@ abstract class AxisChartPainter _gridPaint.strokeWidth = flLine.strokeWidth; _gridPaint.transparentIfWidthIsZero(); - final bothY = getPixelY(axisValue, usableViewSize, holder); - final x1 = 0 + getLeftOffsetDrawSize(holder); + final bothY = getPixelY(axisValue, viewSize, holder); + const x1 = 0.0; final y1 = bothY; - final x2 = usableViewSize.width + getLeftOffsetDrawSize(holder); + final x2 = viewSize.width; final y2 = bothY; canvasWrapper.drawDashedLine( Offset(x1, y1), Offset(x2, y2), _gridPaint, flLine.dashArray); @@ -122,15 +120,9 @@ abstract class AxisChartPainter } final viewSize = canvasWrapper.size; - final usableViewSize = getChartUsableDrawSize(viewSize, holder); _backgroundPaint.color = data.backgroundColor; canvasWrapper.drawRect( - Rect.fromLTWH( - getLeftOffsetDrawSize(holder), - getTopOffsetDrawSize(holder), - usableViewSize.width, - usableViewSize.height, - ), + Rect.fromLTWH(0, 0, viewSize.width, viewSize.height), _backgroundPaint, ); } @@ -139,19 +131,13 @@ abstract class AxisChartPainter void drawRangeAnnotation(CanvasWrapper canvasWrapper, PaintHolder holder) { final data = holder.data; final viewSize = canvasWrapper.size; - final chartUsableSize = getChartUsableDrawSize(viewSize, holder); if (data.rangeAnnotations.verticalRangeAnnotations.isNotEmpty) { for (var annotation in data.rangeAnnotations.verticalRangeAnnotations) { - final topChartPadding = getTopOffsetDrawSize(holder); - final from = Offset( - getPixelX(annotation.x1, chartUsableSize, holder), topChartPadding); - - final bottomChartPadding = - getExtraNeededVerticalSpace(holder) - getTopOffsetDrawSize(holder); + final from = Offset(getPixelX(annotation.x1, viewSize, holder), 0.0); final to = Offset( - getPixelX(annotation.x2, chartUsableSize, holder), - viewSize.height - bottomChartPadding, + getPixelX(annotation.x2, viewSize, holder), + viewSize.height, ); final rect = Rect.fromPoints(from, to); @@ -164,15 +150,10 @@ abstract class AxisChartPainter if (data.rangeAnnotations.horizontalRangeAnnotations.isNotEmpty) { for (var annotation in data.rangeAnnotations.horizontalRangeAnnotations) { - final leftChartPadding = getLeftOffsetDrawSize(holder); - final from = Offset(leftChartPadding, - getPixelY(annotation.y1, chartUsableSize, holder)); - - final rightChartPadding = getExtraNeededHorizontalSpace(holder) - - getLeftOffsetDrawSize(holder); + final from = Offset(0.0, getPixelY(annotation.y1, viewSize, holder)); final to = Offset( - viewSize.width - rightChartPadding, - getPixelY(annotation.y2, chartUsableSize, holder), + viewSize.width, + getPixelY(annotation.y2, viewSize, holder), ); final rect = Rect.fromPoints(from, to); @@ -187,27 +168,25 @@ abstract class AxisChartPainter /// With this function we can convert our [FlSpot] x /// to the view base axis x . /// the view 0, 0 is on the top/left, but the spots is bottom/left - double getPixelX(double spotX, Size chartUsableSize, PaintHolder holder) { + double getPixelX(double spotX, Size viewSize, PaintHolder holder) { final data = holder.data; final deltaX = data.maxX - data.minX; if (deltaX == 0.0) { - return getLeftOffsetDrawSize(holder); + return 0.0; } - return (((spotX - data.minX) / deltaX) * chartUsableSize.width) + - getLeftOffsetDrawSize(holder); + return ((spotX - data.minX) / deltaX) * viewSize.width; } /// With this function we can convert our [FlSpot] y /// to the view base axis y. - double getPixelY(double spotY, Size chartUsableSize, PaintHolder holder) { + double getPixelY(double spotY, Size viewSize, PaintHolder holder) { final data = holder.data; final deltaY = data.maxY - data.minY; if (deltaY == 0.0) { - return chartUsableSize.height + getTopOffsetDrawSize(holder); + return viewSize.height; } - - var y = ((spotY - data.minY) / deltaY) * chartUsableSize.height; - y = chartUsableSize.height - y; - return y + getTopOffsetDrawSize(holder); + var y = ((spotY - data.minY) / deltaY) * viewSize.height; + y = viewSize.height - y; + return y; } } diff --git a/lib/src/chart/base/base_chart/base_chart_painter.dart b/lib/src/chart/base/base_chart/base_chart_painter.dart index d1bf983c6d..671428b722 100644 --- a/lib/src/chart/base/base_chart/base_chart_painter.dart +++ b/lib/src/chart/base/base_chart/base_chart_painter.dart @@ -32,17 +32,11 @@ class BaseChartPainter { } final viewSize = canvasWrapper.size; - final chartViewSize = getChartUsableDrawSize(viewSize, holder); - final topLeft = - Offset(getLeftOffsetDrawSize(holder), getTopOffsetDrawSize(holder)); - final topRight = Offset(getLeftOffsetDrawSize(holder) + chartViewSize.width, - getTopOffsetDrawSize(holder)); - final bottomLeft = Offset(getLeftOffsetDrawSize(holder), - getTopOffsetDrawSize(holder) + chartViewSize.height); - final bottomRight = Offset( - getLeftOffsetDrawSize(holder) + chartViewSize.width, - getTopOffsetDrawSize(holder) + chartViewSize.height); + const topLeft = Offset(0, 0); + final topRight = Offset(viewSize.width, 0); + final bottomLeft = Offset(0, viewSize.height); + final bottomRight = Offset(viewSize.width, viewSize.height); /// Draw Top Line final topBorder = borderData.border.top; @@ -80,36 +74,6 @@ class BaseChartPainter { canvasWrapper.drawLine(bottomLeft, topLeft, _borderPaint); } } - - /// Calculate the size that we can draw our chart's main content. - /// [getExtraNeededHorizontalSpace] and [getExtraNeededVerticalSpace] - /// is the needed space to draw horizontal and vertical - /// stuff around our chart. - /// then we subtract them from raw [viewSize] - @Deprecated("It can be removed, we need to use [viewSize] directly") - Size getChartUsableDrawSize(Size viewSize, PaintHolder holder) => viewSize; - - /// Extra space needed to show horizontal contents around the chart, - /// like: left, right padding, left, right titles, and so on, - @Deprecated("We don't need it anymore, because there is no titles to paint") - double getExtraNeededHorizontalSpace(PaintHolder holder) => 0; - - /// Extra space needed to show vertical contents around the chart, - /// like: top, bottom padding, top, bottom titles, and so on, - @Deprecated("We don't need it anymore, because there is no titles to paint") - double getExtraNeededVerticalSpace(PaintHolder holder) => 0; - - /// Left offset to draw the chart's main content - /// we should use this to offset our x axis when we drawing the chart, - /// and the width space we can use to draw chart is[getChartUsableDrawSize.width] - @Deprecated("We don't need it anymore, because there is no titles to paint") - double getLeftOffsetDrawSize(PaintHolder holder) => 0; - - /// Top offset to draw the chart's main content - /// we should use this to offset our y axis when we drawing the chart, - /// and the height space we can use to draw chart is[getChartUsableDrawSize.height] - @Deprecated("We don't need it anymore, because there is no titles to paint") - double getTopOffsetDrawSize(PaintHolder holder) => 0; } /// Holds data for painting on canvas diff --git a/lib/src/chart/line_chart/line_chart_painter.dart b/lib/src/chart/line_chart/line_chart_painter.dart index 04255797e9..f70c7b4477 100644 --- a/lib/src/chart/line_chart/line_chart_painter.dart +++ b/lib/src/chart/line_chart/line_chart_painter.dart @@ -141,33 +141,30 @@ class LineChartPainter extends AxisChartPainter { void clipToBorder( CanvasWrapper canvasWrapper, PaintHolder holder) { final data = holder.data; - final size = canvasWrapper.size; + final viewSize = canvasWrapper.size; final clip = data.clipData; - final usableSize = getChartUsableDrawSize(size, holder); final border = data.borderData.show ? data.borderData.border : null; var left = 0.0; var top = 0.0; - var right = size.width; - var bottom = size.height; + var right = viewSize.width; + var bottom = viewSize.height; if (clip.left) { final borderWidth = border?.left.width ?? 0; - left = getLeftOffsetDrawSize(holder) + (borderWidth / 2); + left = borderWidth / 2; } if (clip.top) { final borderWidth = border?.top.width ?? 0; - top = getTopOffsetDrawSize(holder) + (borderWidth / 2); + top = borderWidth / 2; } if (clip.right) { final borderWidth = border?.right.width ?? 0; - right = - getLeftOffsetDrawSize(holder) + usableSize.width - (borderWidth / 2); + right = viewSize.width - (borderWidth / 2); } if (clip.bottom) { final borderWidth = border?.bottom.width ?? 0; - bottom = - getTopOffsetDrawSize(holder) + usableSize.height - (borderWidth / 2); + bottom = viewSize.height - (borderWidth / 2); } canvasWrapper.clipRect(Rect.fromLTRB(left, top, right, bottom)); @@ -247,10 +244,10 @@ class LineChartPainter extends AxisChartPainter { toBarData.mostBottomSpot.y, ); final aroundRect = Rect.fromLTRB( - getPixelX(left, getChartUsableDrawSize(viewSize, holder), holder), - getPixelY(top, getChartUsableDrawSize(viewSize, holder), holder), - getPixelX(right, getChartUsableDrawSize(viewSize, holder), holder), - getPixelY(bottom, getChartUsableDrawSize(viewSize, holder), holder), + getPixelX(left, viewSize, holder), + getPixelY(top, viewSize, holder), + getPixelX(right, viewSize, holder), + getPixelY(bottom, viewSize, holder), ); drawBetweenBar( @@ -272,7 +269,7 @@ class LineChartPainter extends AxisChartPainter { if (!barData.dotData.show || barData.spots.isEmpty) { return; } - final viewSize = getChartUsableDrawSize(canvasWrapper.size, holder); + final viewSize = canvasWrapper.size; final barXDelta = getBarLineXLength(barData, viewSize, holder); @@ -281,10 +278,7 @@ class LineChartPainter extends AxisChartPainter { if (spot.isNotNull() && barData.dotData.checkToShowDot(spot, barData)) { final x = getPixelX(spot.x, viewSize, holder); final y = getPixelY(spot.y, viewSize, holder); - - final xPercentInLine = - ((x - getLeftOffsetDrawSize(holder)) / barXDelta) * 100; - + final xPercentInLine = (x / barXDelta) * 100; final painter = barData.dotData.getDotPainter(spot, xPercentInLine, barData, i); @@ -303,7 +297,6 @@ class LineChartPainter extends AxisChartPainter { return; } final viewSize = canvasWrapper.size; - final chartViewSize = getChartUsableDrawSize(viewSize, holder); final barXDelta = getBarLineXLength(barData, viewSize, holder); @@ -328,8 +321,8 @@ class LineChartPainter extends AxisChartPainter { continue; } - final touchedSpot = Offset(getPixelX(spot.x, chartViewSize, holder), - getPixelY(spot.y, chartViewSize, holder)); + final touchedSpot = Offset(getPixelX(spot.x, viewSize, holder), + getPixelY(spot.y, viewSize, holder)); /// For drawing the dot final showingDots = indicatorData.touchedSpotDotData.show; @@ -337,9 +330,7 @@ class LineChartPainter extends AxisChartPainter { late FlDotPainter dotPainter; if (showingDots) { - final xPercentInLine = - ((touchedSpot.dx - getLeftOffsetDrawSize(holder)) / barXDelta) * - 100; + final xPercentInLine = (touchedSpot.dx / barXDelta) * 100; dotPainter = indicatorData.touchedSpotDotData .getDotPainter(spot, xPercentInLine, barData, index); dotHeight = dotPainter.getSize(spot).height; @@ -351,9 +342,9 @@ class LineChartPainter extends AxisChartPainter { final lineEndY = min(data.maxY, max(data.minY, data.lineTouchData.getTouchLineEnd(barData, index))); final lineStart = - Offset(touchedSpot.dx, getPixelY(lineStartY, chartViewSize, holder)); + Offset(touchedSpot.dx, getPixelY(lineStartY, viewSize, holder)); var lineEnd = - Offset(touchedSpot.dx, getPixelY(lineEndY, chartViewSize, holder)); + Offset(touchedSpot.dx, getPixelY(lineEndY, viewSize, holder)); /// If line end is inside the dot, adjust it so that it doesn't overlap with the dot. final dotMinY = touchedSpot.dy - dotHeight / 2; @@ -407,7 +398,6 @@ class LineChartPainter extends AxisChartPainter { Path generateNormalBarPath(Size viewSize, LineChartBarData barData, List barSpots, PaintHolder holder, {Path? appendToPath}) { - viewSize = getChartUsableDrawSize(viewSize, holder); final path = appendToPath ?? Path(); final size = barSpots.length; @@ -481,7 +471,6 @@ class LineChartPainter extends AxisChartPainter { Path generateStepBarPath(Size viewSize, LineChartBarData barData, List barSpots, PaintHolder holder, {Path? appendToPath}) { - viewSize = getChartUsableDrawSize(viewSize, holder); final path = appendToPath ?? Path(); final size = barSpots.length; @@ -532,30 +521,28 @@ class LineChartPainter extends AxisChartPainter { {bool fillCompletely = false}) { final belowBarPath = Path.from(barPath); - final chartViewSize = getChartUsableDrawSize(viewSize, holder); - /// Line To Bottom Right - var x = getPixelX(barSpots[barSpots.length - 1].x, chartViewSize, holder); + var x = getPixelX(barSpots[barSpots.length - 1].x, viewSize, holder); double y; if (!fillCompletely && barData.belowBarData.applyCutOffY) { - y = getPixelY(barData.belowBarData.cutOffY, chartViewSize, holder); + y = getPixelY(barData.belowBarData.cutOffY, viewSize, holder); } else { - y = chartViewSize.height + getTopOffsetDrawSize(holder); + y = viewSize.height; } belowBarPath.lineTo(x, y); /// Line To Bottom Left - x = getPixelX(barSpots[0].x, chartViewSize, holder); + x = getPixelX(barSpots[0].x, viewSize, holder); if (!fillCompletely && barData.belowBarData.applyCutOffY) { - y = getPixelY(barData.belowBarData.cutOffY, chartViewSize, holder); + y = getPixelY(barData.belowBarData.cutOffY, viewSize, holder); } else { - y = chartViewSize.height + getTopOffsetDrawSize(holder); + y = viewSize.height; } belowBarPath.lineTo(x, y); /// Line To Top Left - x = getPixelX(barSpots[0].x, chartViewSize, holder); - y = getPixelY(barSpots[0].y, chartViewSize, holder); + x = getPixelX(barSpots[0].x, viewSize, holder); + y = getPixelY(barSpots[0].y, viewSize, holder); belowBarPath.lineTo(x, y); belowBarPath.close(); @@ -572,30 +559,28 @@ class LineChartPainter extends AxisChartPainter { {bool fillCompletely = false}) { final aboveBarPath = Path.from(barPath); - final chartViewSize = getChartUsableDrawSize(viewSize, holder); - /// Line To Top Right - var x = getPixelX(barSpots[barSpots.length - 1].x, chartViewSize, holder); + var x = getPixelX(barSpots[barSpots.length - 1].x, viewSize, holder); double y; if (!fillCompletely && barData.aboveBarData.applyCutOffY) { - y = getPixelY(barData.aboveBarData.cutOffY, chartViewSize, holder); + y = getPixelY(barData.aboveBarData.cutOffY, viewSize, holder); } else { - y = getTopOffsetDrawSize(holder); + y = 0.0; } aboveBarPath.lineTo(x, y); /// Line To Top Left - x = getPixelX(barSpots[0].x, chartViewSize, holder); + x = getPixelX(barSpots[0].x, viewSize, holder); if (!fillCompletely && barData.aboveBarData.applyCutOffY) { - y = getPixelY(barData.aboveBarData.cutOffY, chartViewSize, holder); + y = getPixelY(barData.aboveBarData.cutOffY, viewSize, holder); } else { - y = getTopOffsetDrawSize(holder); + y = 0.0; } aboveBarPath.lineTo(x, y); /// Line To Bottom Left - x = getPixelX(barSpots[0].x, chartViewSize, holder); - y = getPixelY(barSpots[0].y, chartViewSize, holder); + x = getPixelX(barSpots[0].x, viewSize, holder); + y = getPixelY(barSpots[0].y, viewSize, holder); aboveBarPath.lineTo(x, y); aboveBarPath.close(); @@ -617,15 +602,12 @@ class LineChartPainter extends AxisChartPainter { } final viewSize = canvasWrapper.size; - final chartViewSize = getChartUsableDrawSize(viewSize, holder); final belowBarLargestRect = Rect.fromLTRB( - getPixelX(barData.mostLeftSpot.x, chartViewSize, holder), - getPixelY(barData.mostTopSpot.y, chartViewSize, holder), - getPixelX(barData.mostRightSpot.x, chartViewSize, holder), - viewSize.height - - getExtraNeededVerticalSpace(holder) - - getTopOffsetDrawSize(holder), + getPixelX(barData.mostLeftSpot.x, viewSize, holder), + getPixelY(barData.mostTopSpot.y, viewSize, holder), + getPixelX(barData.mostRightSpot.x, viewSize, holder), + viewSize.height, ); final belowBar = barData.belowBarData; @@ -653,25 +635,23 @@ class LineChartPainter extends AxisChartPainter { for (var spot in barData.spots) { if (barData.belowBarData.spotsLine.checkToShowSpotLine(spot)) { final from = Offset( - getPixelX(spot.x, chartViewSize, holder), - getPixelY(spot.y, chartViewSize, holder), + getPixelX(spot.x, viewSize, holder), + getPixelY(spot.y, viewSize, holder), ); - final bottomPadding = getExtraNeededVerticalSpace(holder) - - getTopOffsetDrawSize(holder); Offset to; // Check applyCutOffY if (barData.belowBarData.spotsLine.applyCutOffY && barData.belowBarData.applyCutOffY) { to = Offset( - getPixelX(spot.x, chartViewSize, holder), - getPixelY(barData.belowBarData.cutOffY, chartViewSize, holder), + getPixelX(spot.x, viewSize, holder), + getPixelY(barData.belowBarData.cutOffY, viewSize, holder), ); } else { to = Offset( - getPixelX(spot.x, chartViewSize, holder), - viewSize.height - bottomPadding, + getPixelX(spot.x, viewSize, holder), + viewSize.height, ); } @@ -703,13 +683,12 @@ class LineChartPainter extends AxisChartPainter { } final viewSize = canvasWrapper.size; - final chartViewSize = getChartUsableDrawSize(viewSize, holder); final aboveBarLargestRect = Rect.fromLTRB( - getPixelX(barData.mostLeftSpot.x, chartViewSize, holder), - getTopOffsetDrawSize(holder), - getPixelX(barData.mostRightSpot.x, chartViewSize, holder), - getPixelY(barData.mostBottomSpot.y, chartViewSize, holder), + getPixelX(barData.mostLeftSpot.x, viewSize, holder), + 0, + getPixelX(barData.mostRightSpot.x, viewSize, holder), + getPixelY(barData.mostBottomSpot.y, viewSize, holder), ); final aboveBar = barData.aboveBarData; @@ -737,8 +716,8 @@ class LineChartPainter extends AxisChartPainter { for (var spot in barData.spots) { if (barData.aboveBarData.spotsLine.checkToShowSpotLine(spot)) { final from = Offset( - getPixelX(spot.x, chartViewSize, holder), - getPixelY(spot.y, chartViewSize, holder), + getPixelX(spot.x, viewSize, holder), + getPixelY(spot.y, viewSize, holder), ); Offset to; @@ -747,13 +726,13 @@ class LineChartPainter extends AxisChartPainter { if (barData.aboveBarData.spotsLine.applyCutOffY && barData.aboveBarData.applyCutOffY) { to = Offset( - getPixelX(spot.x, chartViewSize, holder), - getPixelY(barData.aboveBarData.cutOffY, chartViewSize, holder), + getPixelX(spot.x, viewSize, holder), + getPixelY(barData.aboveBarData.cutOffY, viewSize, holder), ); } else { to = Offset( - getPixelX(spot.x, chartViewSize, holder), - getTopOffsetDrawSize(holder), + getPixelX(spot.x, viewSize, holder), + 0.0, ); } @@ -833,16 +812,15 @@ class LineChartPainter extends AxisChartPainter { return; } final viewSize = canvasWrapper.size; - final chartViewSize = getChartUsableDrawSize(viewSize, holder); _barPaint.strokeCap = barData.isStrokeCapRound ? StrokeCap.round : StrokeCap.butt; final rectAroundTheLine = Rect.fromLTRB( - getPixelX(barData.mostLeftSpot.x, chartViewSize, holder), - getPixelY(barData.mostTopSpot.y, chartViewSize, holder), - getPixelX(barData.mostRightSpot.x, chartViewSize, holder), - getPixelY(barData.mostBottomSpot.y, chartViewSize, holder), + getPixelX(barData.mostLeftSpot.x, viewSize, holder), + getPixelY(barData.mostTopSpot.y, viewSize, holder), + getPixelX(barData.mostRightSpot.x, viewSize, holder), + getPixelY(barData.mostBottomSpot.y, viewSize, holder), ); _barPaint.setColorOrGradient( barData.color, @@ -863,18 +841,11 @@ class LineChartPainter extends AxisChartPainter { PaintHolder holder) { final data = holder.data; final viewSize = canvasWrapper.size; - final chartUsableSize = getChartUsableDrawSize(viewSize, holder); if (data.extraLinesData.horizontalLines.isNotEmpty) { for (var line in data.extraLinesData.horizontalLines) { - final leftChartPadding = getLeftOffsetDrawSize(holder); - final from = Offset( - leftChartPadding, getPixelY(line.y, chartUsableSize, holder)); - - final rightChartPadding = getExtraNeededHorizontalSpace(holder) - - getLeftOffsetDrawSize(holder); - final to = Offset(viewSize.width - rightChartPadding, - getPixelY(line.y, chartUsableSize, holder)); + final from = Offset(0.0, getPixelY(line.y, viewSize, holder)); + final to = Offset(viewSize.width, getPixelY(line.y, viewSize, holder)); _extraLinesPaint.color = line.color; _extraLinesPaint.strokeWidth = line.strokeWidth; @@ -886,7 +857,7 @@ class LineChartPainter extends AxisChartPainter { if (line.sizedPicture != null) { final centerX = line.sizedPicture!.width / 2; final centerY = line.sizedPicture!.height / 2; - final xPosition = leftChartPadding - centerX; + final xPosition = centerX; final yPosition = to.dy - centerY; canvasWrapper.save(); @@ -898,8 +869,7 @@ class LineChartPainter extends AxisChartPainter { if (line.image != null) { final centerX = line.image!.width / 2; final centerY = line.image!.height / 2; - final centeredImageOffset = - Offset(leftChartPadding - centerX, to.dy - centerY); + final centeredImageOffset = Offset(centerX, to.dy - centerY); canvasWrapper.drawImage( line.image!, centeredImageOffset, _imagePaint); } @@ -937,16 +907,8 @@ class LineChartPainter extends AxisChartPainter { if (data.extraLinesData.verticalLines.isNotEmpty) { for (var line in data.extraLinesData.verticalLines) { - final topChartPadding = getTopOffsetDrawSize(holder); - final from = - Offset(getPixelX(line.x, chartUsableSize, holder), topChartPadding); - - final bottomChartPadding = - getExtraNeededVerticalSpace(holder) - getTopOffsetDrawSize(holder); - final to = Offset( - getPixelX(line.x, chartUsableSize, holder), - viewSize.height - bottomChartPadding, - ); + final from = Offset(getPixelX(line.x, viewSize, holder), 0.0); + final to = Offset(getPixelX(line.x, viewSize, holder), viewSize.height); _extraLinesPaint.color = line.color; _extraLinesPaint.strokeWidth = line.strokeWidth; @@ -959,7 +921,7 @@ class LineChartPainter extends AxisChartPainter { final centerX = line.sizedPicture!.width / 2; final centerY = line.sizedPicture!.height / 2; final xPosition = to.dx - centerX; - final yPosition = viewSize.height - bottomChartPadding - centerY; + final yPosition = viewSize.height - centerY; canvasWrapper.save(); canvasWrapper.translate(xPosition, yPosition); @@ -969,8 +931,8 @@ class LineChartPainter extends AxisChartPainter { if (line.image != null) { final centerX = line.image!.width / 2; final centerY = line.image!.height / 2; - final centeredImageOffset = Offset( - to.dx - centerX, viewSize.height - bottomChartPadding - centerY); + final centeredImageOffset = + Offset(to.dx - centerX, viewSize.height - centerY); canvasWrapper.drawImage( line.image!, centeredImageOffset, _imagePaint); } @@ -998,9 +960,9 @@ class LineChartPainter extends AxisChartPainter { label.alignment.withinRect( Rect.fromLTRB( to.dx - padding.right - tp.width, - from.dy + padding.top - topChartPadding, + from.dy + padding.top, from.dx + padding.left, - to.dy - padding.bottom + bottomChartPadding, + to.dy - padding.bottom, ), ), ); @@ -1018,7 +980,6 @@ class LineChartPainter extends AxisChartPainter { ShowingTooltipIndicators showingTooltipSpots, PaintHolder holder) { final viewSize = canvasWrapper.size; - final chartUsableSize = getChartUsableDrawSize(viewSize, holder); const textsBelowMargin = 4; @@ -1076,8 +1037,8 @@ class LineChartPainter extends AxisChartPainter { /// there are more than one FlCandidate on touch area, /// we should get the most top FlSpot Offset to draw the tooltip on top of it final mostTopOffset = Offset( - getPixelX(showOnSpot.x, chartUsableSize, holder), - getPixelY(showOnSpot.y, chartUsableSize, holder), + getPixelX(showOnSpot.x, viewSize, holder), + getPixelY(showOnSpot.y, viewSize, holder), ); final tooltipWidth = biggerWidth + tooltipData.tooltipPadding.horizontal; @@ -1275,8 +1236,6 @@ class LineChartPainter extends AxisChartPainter { return null; } - final chartViewSize = getChartUsableDrawSize(viewSize, holder); - /// Find the nearest spot (based on distanceCalculator) final sortedSpots = []; double? smallestDistance; @@ -1285,8 +1244,8 @@ class LineChartPainter extends AxisChartPainter { final distance = data.lineTouchData.distanceCalculator( touchedPoint, Offset( - getPixelX(spot.x, chartViewSize, holder), - getPixelY(spot.y, chartViewSize, holder), + getPixelX(spot.x, viewSize, holder), + getPixelY(spot.y, viewSize, holder), )); if (distance <= data.lineTouchData.touchSpotThreshold) { diff --git a/lib/src/chart/scatter_chart/scatter_chart_painter.dart b/lib/src/chart/scatter_chart/scatter_chart_painter.dart index a8b9c11b66..f4df6291fe 100644 --- a/lib/src/chart/scatter_chart/scatter_chart_painter.dart +++ b/lib/src/chart/scatter_chart/scatter_chart_painter.dart @@ -45,7 +45,6 @@ class ScatterChartPainter extends AxisChartPainter { ) { final data = holder.data; final viewSize = canvasWrapper.size; - final chartUsableSize = getChartUsableDrawSize(viewSize, holder); final clip = data.clipData; final border = data.borderData.show ? data.borderData.border : null; @@ -67,23 +66,19 @@ class ScatterChartPainter extends AxisChartPainter { if (clip.left) { final borderWidth = border?.left.width ?? 0; - left = getLeftOffsetDrawSize(holder) + (borderWidth / 2); + left = borderWidth / 2; } if (clip.top) { final borderWidth = border?.top.width ?? 0; - top = getTopOffsetDrawSize(holder) + (borderWidth / 2); + top = borderWidth / 2; } if (clip.right) { final borderWidth = border?.right.width ?? 0; - right = getLeftOffsetDrawSize(holder) + - chartUsableSize.width - - (borderWidth / 2); + right = viewSize.width - (borderWidth / 2); } if (clip.bottom) { final borderWidth = border?.bottom.width ?? 0; - bottom = getTopOffsetDrawSize(holder) + - chartUsableSize.height - - (borderWidth / 2); + bottom = viewSize.height - (borderWidth / 2); } canvasWrapper.clipRect(Rect.fromLTRB(left, top, right, bottom)); @@ -96,8 +91,8 @@ class ScatterChartPainter extends AxisChartPainter { if (!scatterSpot.show) { continue; } - final pixelX = getPixelX(scatterSpot.x, chartUsableSize, holder); - final pixelY = getPixelY(scatterSpot.y, chartUsableSize, holder); + final pixelX = getPixelX(scatterSpot.x, viewSize, holder); + final pixelY = getPixelY(scatterSpot.y, viewSize, holder); _spotsPaint.color = scatterSpot.color; @@ -138,18 +133,17 @@ class ScatterChartPainter extends AxisChartPainter { textScaleFactor: holder.textScale, ); - tp.layout(maxWidth: chartUsableSize.width); + tp.layout(maxWidth: viewSize.width); - final pixelX = getPixelX(scatterSpot.x, chartUsableSize, holder); - final pixelY = getPixelY(scatterSpot.y, chartUsableSize, holder); + final pixelX = getPixelX(scatterSpot.x, viewSize, holder); + final pixelY = getPixelY(scatterSpot.y, viewSize, holder); double newPixelY; /// To ensure the label is centered horizontally with respect to the spot. double newPixelX = pixelX - tp.width / 2; - double centerChartY = - getTopOffsetDrawSize(holder) + chartUsableSize.height / 2; + double centerChartY = viewSize.height / 2; /// if the spot is in the lower half of the chart, then draw the label either in the center or above the spot, /// if the spot is in upper half of the chart, then draw the label either in the center or below the spot. @@ -212,7 +206,6 @@ class ScatterChartPainter extends AxisChartPainter { ScatterSpot showOnSpot, PaintHolder holder) { final viewSize = canvasWrapper.size; - final chartUsableSize = getChartUsableDrawSize(viewSize, holder); final tooltipItem = tooltipData.getTooltipItems(showOnSpot); @@ -240,8 +233,8 @@ class ScatterChartPainter extends AxisChartPainter { /// there are more than one FlCandidate on touch area, /// we should get the most top FlSpot Offset to draw the tooltip on top of it final mostTopOffset = Offset( - getPixelX(showOnSpot.x, chartUsableSize, holder), - getPixelY(showOnSpot.y, chartUsableSize, holder), + getPixelX(showOnSpot.x, viewSize, holder), + getPixelY(showOnSpot.y, viewSize, holder), ); final tooltipWidth = width + tooltipData.tooltipPadding.horizontal; @@ -346,17 +339,16 @@ class ScatterChartPainter extends AxisChartPainter { /// Returns null if finds nothing! ScatterTouchedSpot? handleTouch( Offset localPosition, - Size size, + Size viewSize, PaintHolder holder, ) { final data = holder.data; - final chartViewSize = getChartUsableDrawSize(size, holder); for (var i = 0; i < data.scatterSpots.length; i++) { final spot = data.scatterSpots[i]; - final spotPixelX = getPixelX(spot.x, chartViewSize, holder); - final spotPixelY = getPixelY(spot.y, chartViewSize, holder); + final spotPixelX = getPixelX(spot.x, viewSize, holder); + final spotPixelY = getPixelY(spot.y, viewSize, holder); final distance = (localPosition - Offset(spotPixelX, spotPixelY)).distance; diff --git a/test/chart/bar_chart/bar_chart_painter_test.dart b/test/chart/bar_chart/bar_chart_painter_test.dart index 6d7c2d0b9e..e4977ba7dc 100644 --- a/test/chart/bar_chart/bar_chart_painter_test.dart +++ b/test/chart/bar_chart/bar_chart_painter_test.dart @@ -16,106 +16,6 @@ import 'bar_chart_painter_test.mocks.dart'; void main() { const tolerance = 0.01; - group('BarChart usable size', () { - test('test 1', () { - const viewSize = Size(728, 728); - - final BarChartData data = BarChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 12, showTitles: true)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 44, showTitles: true)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - ), - ); - - final BarChartPainter barChartPainter = BarChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(728, 728)); - }); - - test('test 2', () { - const viewSize = Size(2020, 2020); - - final BarChartData data = BarChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 44, showTitles: true)), - rightTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - )); - - final BarChartPainter barChartPainter = BarChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(2020, 2020)); - }); - - test('test 3', () { - const viewSize = Size(1000, 1000); - - final BarChartData data = BarChartData( - titlesData: FlTitlesData( - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 500, showTitles: true)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - ), - ); - - final BarChartPainter barChartPainter = BarChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(1000, 1000)); - }); - - test('test 4', () { - const viewSize = Size(800, 1000); - - final BarChartData data = BarChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 10, showTitles: true)), - topTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 240, showTitles: true)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 322, showTitles: true)), - ), - ); - - final BarChartPainter barChartPainter = BarChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(800, 1000)); - }); - - test('test 5', () { - const viewSize = Size(600, 400); - - final BarChartData data = BarChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 0, showTitles: true)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 342134133, showTitles: false)), - topTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 80, showTitles: true)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 322, showTitles: false)), - )); - - final BarChartPainter barChartPainter = BarChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(600, 400)); - }); - }); - group('calculateGroupsX()', () { test('test 1', () { const viewSize = Size(200, 100); diff --git a/test/chart/data_pool.dart b/test/chart/data_pool.dart index 2c7c13059f..ed18ed4642 100644 --- a/test/chart/data_pool.dart +++ b/test/chart/data_pool.dart @@ -2485,6 +2485,154 @@ final ScatterChartData scatterChartData1Clone = ScatterChartData( getLabelFunction: getLabel, ), ); +final ScatterChartData scatterChartData1Clone = ScatterChartData( + minY: 0, + maxY: 12, + maxX: 22, + minX: 11, + gridData: FlGridData( + show: false, + getDrawingHorizontalLine: gridGetDrawingLine, + getDrawingVerticalLine: gridGetDrawingLine, + checkToShowHorizontalLine: gridCheckToShowLine, + checkToShowVerticalLine: gridCheckToShowLine, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 33, + verticalInterval: 1, + ), + backgroundColor: Colors.black, + clipData: FlClipData.none(), + borderData: FlBorderData( + show: true, + border: Border.all( + color: Colors.white, + ), + ), + scatterSpots: [ + ScatterSpot(0, 0, show: false, radius: 33, color: Colors.yellow), + ScatterSpot(2, 2, show: false, radius: 11, color: Colors.purple), + ScatterSpot(1, 2, show: false, radius: 11, color: Colors.white), + ], + scatterTouchData: ScatterTouchData( + enabled: true, + touchTooltipData: ScatterTouchTooltipData( + getTooltipItems: scatterChartGetTooltipItems, + fitInsideHorizontally: true, + fitInsideVertically: false, + maxContentWidth: 33, + tooltipBgColor: Colors.white, + tooltipPadding: const EdgeInsets.all(23), + tooltipRoundedRadius: 534, + ), + handleBuiltInTouches: false, + touchCallback: scatterTouchCallback, + touchSpotThreshold: 12, + ), + showingTooltipIndicators: [0, 1, 2], + titlesData: FlTitlesData( + show: true, + leftTitles: AxisTitles( + axisNameSize: 33, + axisName: MockData.widget1, + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + axisNameSize: 1326, + axisName: MockData.widget3, + sideTitles: SideTitles(reservedSize: 500, showTitles: true), + ), + topTitles: AxisTitles( + axisNameSize: 34, + axisName: MockData.widget4, + sideTitles: SideTitles(showTitles: false), + ), + bottomTitles: AxisTitles( + axisNameSize: 22, + axisName: MockData.widget2, + sideTitles: SideTitles(showTitles: false), + ), + ), + scatterLabelSettings: ScatterLabelSettings( + showLabel: true, + getLabelTextStyleFunction: getLabelTextStyle, + getLabelFunction: getLabel, + ), +); +final ScatterChartData scatterChartData1Clone = ScatterChartData( + minY: 0, + maxY: 12, + maxX: 22, + minX: 11, + gridData: FlGridData( + show: false, + getDrawingHorizontalLine: gridGetDrawingLine, + getDrawingVerticalLine: gridGetDrawingLine, + checkToShowHorizontalLine: gridCheckToShowLine, + checkToShowVerticalLine: gridCheckToShowLine, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 33, + verticalInterval: 1, + ), + backgroundColor: Colors.black, + clipData: FlClipData.none(), + borderData: FlBorderData( + show: true, + border: Border.all( + color: Colors.white, + ), + ), + scatterSpots: [ + ScatterSpot(0, 0, show: false, radius: 33, color: Colors.yellow), + ScatterSpot(2, 2, show: false, radius: 11, color: Colors.purple), + ScatterSpot(1, 2, show: false, radius: 11, color: Colors.white), + ], + scatterTouchData: ScatterTouchData( + enabled: true, + touchTooltipData: ScatterTouchTooltipData( + getTooltipItems: scatterChartGetTooltipItems, + fitInsideHorizontally: true, + fitInsideVertically: false, + maxContentWidth: 33, + tooltipBgColor: Colors.white, + tooltipPadding: const EdgeInsets.all(23), + tooltipRoundedRadius: 534, + ), + handleBuiltInTouches: false, + touchCallback: scatterTouchCallback, + touchSpotThreshold: 12, + ), + showingTooltipIndicators: [0, 1, 2], + titlesData: FlTitlesData( + show: true, + leftTitles: AxisTitles( + axisNameSize: 33, + axisName: MockData.widget1, + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + axisNameSize: 1326, + axisName: MockData.widget3, + sideTitles: SideTitles(reservedSize: 500, showTitles: true), + ), + topTitles: AxisTitles( + axisNameSize: 34, + axisName: MockData.widget4, + sideTitles: SideTitles(showTitles: false), + ), + bottomTitles: AxisTitles( + axisNameSize: 22, + axisName: MockData.widget2, + sideTitles: SideTitles(showTitles: false), + ), + ), + scatterLabelSettings: ScatterLabelSettings( + showLabel: true, + getLabelTextStyleFunction: getLabelTextStyle, + getLabelFunction: getLabel, + ), +); final ScatterChartData scatterChartData1Clone = scatterChartData1.copyWith(); final BarChartRodStackItem barChartRodStackItem1 = BarChartRodStackItem( 1, diff --git a/test/chart/line_chart/line_chart_painter_test.dart b/test/chart/line_chart/line_chart_painter_test.dart index 5ddc5e1bad..2517607d24 100644 --- a/test/chart/line_chart/line_chart_painter_test.dart +++ b/test/chart/line_chart/line_chart_painter_test.dart @@ -16,118 +16,6 @@ import 'dart:ui' as ui show Gradient; @GenerateMocks([Canvas, CanvasWrapper, BuildContext, Utils, LineChartPainter]) void main() { - group('LineChart usable size', () { - test('test 1', () { - const viewSize = Size(728, 728); - - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 20, showTitles: true)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 64, showTitles: true)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - )); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(728, 728)); - }); - - test('test 2', () { - const viewSize = Size(2020, 2020); - - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 62, showTitles: true)), - rightTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - )); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(2020, 2020)); - }); - - test('test 3', () { - const viewSize = Size(1000, 1000); - - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 500, showTitles: true)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - )); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(1000, 1000)); - }); - - test('test 4', () { - const viewSize = Size(800, 1000); - - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 10, showTitles: true)), - topTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 240, showTitles: true)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 322, showTitles: true)), - )); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(800, 1000)); - }); - - test('test 5', () { - const viewSize = Size(600, 400); - - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 0, showTitles: true)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 342134133, showTitles: false)), - topTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 80, showTitles: true)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 322, showTitles: false)), - )); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(lineChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(600, 400)); - }); - - test('test 6', () { - const viewSize = Size(600, 400); - final LineChartData data = LineChartData( - titlesData: FlTitlesData(show: false), - minY: 0, - maxY: 0, - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(lineChartPainter.getPixelX(0, viewSize, holder), 0); - expect(lineChartPainter.getPixelY(0, viewSize, holder), 400); - }); - }); - group('clipToBorder()', () { test('test 1', () { const viewSize = Size(400, 400); @@ -1984,195 +1872,6 @@ void main() { }); }); - group('getExtraNeededHorizontalSpace()', () { - test('test 1', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: false, - ), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getExtraNeededHorizontalSpace(holder); - expect(result, 0); - }); - - test('test 2', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: true, - leftTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false, reservedSize: 10)), - ), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getExtraNeededHorizontalSpace(holder); - expect(result, 0); - }); - - test('test 3', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: true, - leftTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - ), - ); - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getExtraNeededHorizontalSpace(holder); - expect(result, 0); - }); - }); - - group('getExtraNeededVerticalSpace()', () { - test('test 1', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData(show: false), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getExtraNeededVerticalSpace(holder); - expect(result, 0); - }); - - test('test 2', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: true, - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false, reservedSize: 10)), - ), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getExtraNeededVerticalSpace(holder); - expect(result, 0); - }); - - test('test 3', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: true, - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - ), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getExtraNeededVerticalSpace(holder); - expect(result, 0); - }); - }); - - group('getLeftOffsetDrawSize()', () { - test('test 1', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData(show: false), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getLeftOffsetDrawSize(holder); - expect(result, 0); - }); - - test('test 2', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: true, - leftTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false, reservedSize: 10)), - ), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getLeftOffsetDrawSize(holder); - expect(result, 0); - }); - - test('test 3', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: true, - leftTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - ), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getLeftOffsetDrawSize(holder); - expect(result, 0); - }); - }); - - group('getTopOffsetDrawSize()', () { - test('test 1', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData(show: false), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getTopOffsetDrawSize(holder); - expect(result, 0); - }); - - test('test 2', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: true, - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 10)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false, reservedSize: 10)), - ), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getTopOffsetDrawSize(holder); - expect(result, 0); - }); - - test('test 3', () { - final LineChartData data = LineChartData( - titlesData: FlTitlesData( - show: true, - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(showTitles: true, reservedSize: 12)), - ), - ); - - final LineChartPainter lineChartPainter = LineChartPainter(); - final holder = PaintHolder(data, data, 1.0); - final result = lineChartPainter.getTopOffsetDrawSize(holder); - expect(result, 0); - }); - }); - group('handleTouch()', () { test('test 1', () { const viewSize = Size(100, 100); diff --git a/test/chart/pie_chart/pie_chart_painter_test.dart b/test/chart/pie_chart/pie_chart_painter_test.dart index 50b59d801a..5e93052eb7 100644 --- a/test/chart/pie_chart/pie_chart_painter_test.dart +++ b/test/chart/pie_chart/pie_chart_painter_test.dart @@ -14,22 +14,6 @@ import 'pie_chart_painter_test.mocks.dart'; @GenerateMocks([Canvas, CanvasWrapper, BuildContext, Utils]) void main() { - group('PieChart usable size', () { - test('test 1', () { - const viewSize = Size(728, 728); - - final data = PieChartData(sections: [ - PieChartSectionData(), - PieChartSectionData(), - PieChartSectionData(), - ]); - final barChartPainter = PieChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(barChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(728, 728)); - }); - }); - group('calculateSectionsAngle()', () { test('test 1', () { final sections = [ diff --git a/test/chart/radar_chart/radar_chart_painter_test.dart b/test/chart/radar_chart/radar_chart_painter_test.dart index 45630533ab..9951b195d2 100644 --- a/test/chart/radar_chart/radar_chart_painter_test.dart +++ b/test/chart/radar_chart/radar_chart_painter_test.dart @@ -12,21 +12,6 @@ import 'radar_chart_painter_test.mocks.dart'; @GenerateMocks([Canvas, CanvasWrapper, BuildContext, Utils]) void main() { - group('RadarChart usable size', () { - test('test 1', () { - const viewSize = Size(728, 728); - - final RadarChartData data = RadarChartData(dataSets: [ - RadarDataSet(), - ]); - - final RadarChartPainter radarChartPainter = RadarChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(radarChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(728, 728)); - }); - }); - group('drawTicks()', () { test('test 1', () { const viewSize = Size(400, 300); diff --git a/test/chart/scatter_chart/scatter_chart_painter_test.dart b/test/chart/scatter_chart/scatter_chart_painter_test.dart index 82d8500555..9e7bceae05 100644 --- a/test/chart/scatter_chart/scatter_chart_painter_test.dart +++ b/test/chart/scatter_chart/scatter_chart_painter_test.dart @@ -15,104 +15,6 @@ import 'scatter_chart_painter_test.mocks.dart'; @GenerateMocks([Canvas, CanvasWrapper, BuildContext, Utils]) void main() { - group('ScatterChart usable size', () { - test('test 1', () { - const viewSize = Size(728, 728); - - final ScatterChartData data = ScatterChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 20, showTitles: true)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 64, showTitles: true)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - )); - - final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(728, 728)); - }); - - test('test 2', () { - const viewSize = Size(2020, 2020); - - final ScatterChartData data = ScatterChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 62, showTitles: true)), - rightTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - )); - - final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(2020, 2020)); - }); - - test('test 3', () { - const viewSize = Size(1000, 1000); - - final ScatterChartData data = ScatterChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 500, showTitles: true)), - topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - )); - - final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(1000, 1000)); - }); - - test('test 4', () { - const viewSize = Size(800, 1000); - - final ScatterChartData data = ScatterChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 10, showTitles: true)), - topTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 240, showTitles: true)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 322, showTitles: true)), - )); - - final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(800, 1000)); - }); - - test('test 5', () { - const viewSize = Size(600, 400); - - final ScatterChartData data = ScatterChartData( - titlesData: FlTitlesData( - leftTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 0, showTitles: true)), - rightTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 342134133, showTitles: false)), - topTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 80, showTitles: true)), - bottomTitles: AxisTitles( - sideTitles: SideTitles(reservedSize: 322, showTitles: false)), - )); - - final ScatterChartPainter scatterChartPainter = ScatterChartPainter(); - final holder = PaintHolder(data, data, 1.0); - expect(scatterChartPainter.getChartUsableDrawSize(viewSize, holder), - const Size(600, 400)); - }); - }); - group('drawSpots()', () { test('test 1', () { const viewSize = Size(100, 100);