Skip to content

Commit

Permalink
Write some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Mar 24, 2022
1 parent 6d6c191 commit fc23d16
Show file tree
Hide file tree
Showing 5 changed files with 936 additions and 93 deletions.
76 changes: 1 addition & 75 deletions lib/src/chart/base/axis_chart/side_titles/side_titles_flex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,72 +94,8 @@ class AxisSideTitlesRenderFlex extends RenderBox
}
}

bool get _canComputeIntrinsics => false;

double _getIntrinsicSize({
required Axis sizingDirection,
required double extent,
required _ChildSizingFunction childSize,
}) {
if (!_canComputeIntrinsics) {
assert(
RenderObject.debugCheckingIntrinsics,
'Intrinsics are not available for CrossAxisAlignment.baseline.',
);
return 0.0;
}
double totalFlex = 0.0;
double inflexibleSpace = 0.0;
double maxFlexFractionSoFar = 0.0;
RenderBox? child = firstChild;
while (child != null) {
inflexibleSpace += childSize(child, extent);
final FlexParentData childParentData =
child.parentData! as FlexParentData;
child = childParentData.nextSibling;
}
return maxFlexFractionSoFar * totalFlex + inflexibleSpace;
}

@override
double computeMinIntrinsicWidth(double height) {
return _getIntrinsicSize(
sizingDirection: Axis.horizontal,
extent: height,
childSize: (RenderBox child, double extent) =>
child.getMinIntrinsicWidth(extent),
);
}

@override
double computeMaxIntrinsicWidth(double height) {
return _getIntrinsicSize(
sizingDirection: Axis.horizontal,
extent: height,
childSize: (RenderBox child, double extent) =>
child.getMaxIntrinsicWidth(extent),
);
}

@override
double computeMinIntrinsicHeight(double width) {
return _getIntrinsicSize(
sizingDirection: Axis.vertical,
extent: width,
childSize: (RenderBox child, double extent) =>
child.getMinIntrinsicHeight(extent),
);
}

@override
double computeMaxIntrinsicHeight(double width) {
return _getIntrinsicSize(
sizingDirection: Axis.vertical,
extent: width,
childSize: (RenderBox child, double extent) =>
child.getMaxIntrinsicHeight(extent),
);
}
bool get debugNeedsLayout => false;

@override
double? computeDistanceToActualBaseline(TextBaseline baseline) {
Expand Down Expand Up @@ -189,14 +125,6 @@ class AxisSideTitlesRenderFlex extends RenderBox

@override
Size computeDryLayout(BoxConstraints constraints) {
if (!_canComputeIntrinsics) {
assert(debugCannotComputeDryLayout(
reason:
'Dry layout cannot be computed for CrossAxisAlignment.baseline, which requires a full layout.',
));
return Size.zero;
}

final _LayoutSizes sizes = _computeSizes(
layoutChild: ChildLayoutHelper.dryLayoutChild,
constraints: constraints,
Expand Down Expand Up @@ -340,8 +268,6 @@ class AxisSideTitlesRenderFlex extends RenderBox
}
}

typedef _ChildSizingFunction = double Function(RenderBox child, double extent);

class _LayoutSizes {
const _LayoutSizes({
required this.mainSize,
Expand Down
21 changes: 3 additions & 18 deletions lib/src/chart/base/axis_chart/side_titles/side_titles_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ class SideTitlesWidget extends StatelessWidget {

FlTitlesData get titlesData => axisChartData.titlesData;

AxisTitles get leftTitles => titlesData.leftTitles;

AxisTitles get topTitles => titlesData.topTitles;

AxisTitles get rightTitles => titlesData.rightTitles;

AxisTitles get bottomTitles => titlesData.bottomTitles;

bool get isLeftOrTop => side == TitlesSide.left || side == TitlesSide.top;

bool get isRightOrBottom =>
Expand All @@ -69,8 +61,6 @@ class SideTitlesWidget extends StatelessWidget {
return titlesData.rightTitles;
case TitlesSide.bottom:
return titlesData.bottomTitles;
default:
throw StateError("Side is not valid $side");
}
}

Expand All @@ -90,8 +80,6 @@ class SideTitlesWidget extends StatelessWidget {
return Alignment.centerRight;
case TitlesSide.bottom:
return Alignment.bottomCenter;
default:
throw StateError("Side is not valid $side");
}
}

Expand All @@ -103,8 +91,6 @@ class SideTitlesWidget extends StatelessWidget {
case TitlesSide.top:
case TitlesSide.bottom:
return titlesData.allSidesPadding.onlyLeftRight;
default:
throw StateError("Side is not valid $side");
}
}

Expand All @@ -116,8 +102,6 @@ class SideTitlesWidget extends StatelessWidget {
case TitlesSide.top:
case TitlesSide.bottom:
return titlesData.allSidesPadding.horizontal;
default:
throw StateError("Side is not valid $side");
}
}

Expand Down Expand Up @@ -179,6 +163,9 @@ class SideTitlesWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (!axisTitles.showAxisTitles && !axisTitles.showSideTitles) {
return Container();
}
final axisViewSize = isHorizontal ? parentSize.width : parentSize.height;
return Align(
alignment: alignment,
Expand Down Expand Up @@ -245,8 +232,6 @@ class _AxisTitleWidget extends StatelessWidget {
return 0;
case TitlesSide.bottom:
return 0;
default:
throw StateError("Side is not valid $side");
}
}

Expand Down
Loading

0 comments on commit fc23d16

Please sign in to comment.