Skip to content

Commit

Permalink
Update goldens
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaknezic committed Oct 13, 2023
1 parent 078daa9 commit fdc8522
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
part of charts_painter;

class ChartDecorationRenderer<T> extends LeafRenderObjectWidget {
ChartDecorationRenderer(this.chartState, this.decorationPainter, {Key? key})
: super(key: key);
ChartDecorationRenderer(this.chartState, this.decorationPainter, {Key? key}) : super(key: key);

final ChartState<T?> chartState;
final DecorationPainter decorationPainter;
Expand All @@ -13,8 +12,7 @@ class ChartDecorationRenderer<T> extends LeafRenderObjectWidget {
}

@override
void updateRenderObject(
BuildContext context, _RenderChartDecoration renderObject) {
void updateRenderObject(BuildContext context, _RenderChartDecoration renderObject) {
renderObject
..chartState = chartState
..item = decorationPainter;
Expand Down Expand Up @@ -84,12 +82,10 @@ class _RenderChartDecoration<T> extends RenderBox {
canvas.save();

// Clip out of bounds decorations
if (size.contains(offset)) {
canvas.translate(offset.dx, offset.dy);
canvas.translate(offset.dx, offset.dy);

_decoration.draw(canvas, size, _chartState);
_decoration.draw(canvas, size, _chartState);

canvas.restore();
}
canvas.restore();
}
}
99 changes: 28 additions & 71 deletions lib/chart/render/decorations/target_decoration.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
part of charts_painter;

/// Check iv item is inside the target
bool _isInTarget(double? max,
{double? min,
double? targetMin,
double? targetMax,
bool inclusive = true}) {
bool _isInTarget(double? max, {double? min, double? targetMin, double? targetMax, bool inclusive = true}) {
if (targetMin == null && targetMax == null) {
return true;
}

final _min = min ?? max;

if ((targetMin != null && _min! <= targetMin) ||
(targetMax != null && max! >= targetMax)) {
if ((targetMin != null && _min! <= targetMin) || (targetMax != null && max! >= targetMax)) {
// Check if target is inclusive, don't show error color in that case
if (inclusive && (_min == targetMin || max == targetMax)) {
return true;
Expand All @@ -25,14 +20,10 @@ bool _isInTarget(double? max,
return true;
}

Color _getColorForTarget(Color color, Color? colorOverTarget,
bool isTargetInclusive, double? targetMin, double? targetMax, double? max,
Color _getColorForTarget(
Color color, Color? colorOverTarget, bool isTargetInclusive, double? targetMin, double? targetMax, double? max,
[double? min]) {
return _isInTarget(max,
min: min,
targetMax: targetMax,
targetMin: targetMin,
inclusive: isTargetInclusive)
return _isInTarget(max, min: min, targetMax: targetMax, targetMin: targetMin, inclusive: isTargetInclusive)
? color
: (colorOverTarget ?? color);
}
Expand All @@ -44,8 +35,7 @@ Color _getColorForTarget(Color color, Color? colorOverTarget,
///
/// In order to change the color of item when it didn't meet the target
/// criteria, you will need to add [getTargetItemColor] to [ItemOptions.colorForValue]
@Deprecated(
'You can make this decoration and much more using WidgetDecoration. Check migration guide for more info')
@Deprecated('You can make this decoration and much more using WidgetDecoration. Check migration guide for more info')
class TargetLineDecoration extends DecorationPainter {
/// Constructor for target line decoration
///
Expand Down Expand Up @@ -86,31 +76,22 @@ class TargetLineDecoration extends DecorationPainter {
/// Pass this to [ItemOptions.colorForValue] and chart will update item colors
/// based on target line
Color getTargetItemColor(Color defaultColor, ChartItem item) =>
_getColorForTarget(defaultColor, colorOverTarget, isTargetInclusive,
target, null, item.max, item.min);
_getColorForTarget(defaultColor, colorOverTarget, isTargetInclusive, target, null, item.max, item.min);

@override
Offset applyPaintTransform(ChartState state, Size size) {
final _size =
(state.defaultPadding + state.defaultMargin).deflateSize(size);
final _size = (state.defaultPadding + state.defaultMargin).deflateSize(size);
final _maxValue = state.data.maxValue - state.data.minValue;
final scale = _size.height / _maxValue;
final _minValue = state.data.minValue * scale;

return Offset(
state.defaultMargin.left,
(_size.height - (lineWidth / 2)) -
scale * (target ?? 0) +
_minValue +
state.defaultMargin.top);
return Offset(state.defaultMargin.left,
(_size.height - (lineWidth / 2)) - scale * (target ?? 0) + _minValue + state.defaultMargin.top);
}

@override
Size layoutSize(BoxConstraints constraints, ChartState state) {
return Size(
(constraints.maxWidth -
(state.defaultPadding.horizontal + state.defaultMargin.horizontal)),
lineWidth);
return Size((constraints.maxWidth - (state.defaultPadding.horizontal + state.defaultMargin.horizontal)), lineWidth);
}

@override
Expand Down Expand Up @@ -141,13 +122,11 @@ class TargetLineDecoration extends DecorationPainter {
TargetLineDecoration animateTo(DecorationPainter endValue, double t) {
if (endValue is TargetLineDecoration) {
return TargetLineDecoration(
targetLineColor:
Color.lerp(targetLineColor, endValue.targetLineColor, t),
targetLineColor: Color.lerp(targetLineColor, endValue.targetLineColor, t),
lineWidth: lerpDouble(lineWidth, endValue.lineWidth, t) ?? 2.0,
dashArray: t < 0.5 ? dashArray : endValue.dashArray,
target: lerpDouble(target, endValue.target, t),
colorOverTarget:
Color.lerp(colorOverTarget, endValue.colorOverTarget, t),
colorOverTarget: Color.lerp(colorOverTarget, endValue.colorOverTarget, t),
);
}

Expand All @@ -174,8 +153,7 @@ class TargetAreaDecoration extends DecorationPainter {
this.areaPadding = EdgeInsets.zero,
this.targetAreaRadius,
this.targetAreaFillColor,
}) : assert(areaPadding.vertical == 0,
'Vertical padding cannot be applied here!');
}) : assert(areaPadding.vertical == 0, 'Vertical padding cannot be applied here!');

/// Dash pattern for the line, if left empty line will be solid
final List<double>? dashArray;
Expand Down Expand Up @@ -214,48 +192,36 @@ class TargetAreaDecoration extends DecorationPainter {
/// Pass this to [ItemOptions.colorForValue] and chart will update item colors
/// based on target area
Color getTargetItemColor(Color defaultColor, ChartItem item) =>
_getColorForTarget(defaultColor, colorOverTarget, isTargetInclusive,
targetMin, targetMax, item.max, item.min);
_getColorForTarget(defaultColor, colorOverTarget, isTargetInclusive, targetMin, targetMax, item.max, item.min);

@override
Size layoutSize(BoxConstraints constraints, ChartState state) {
final _size = (state.defaultPadding + state.defaultMargin)
.deflateSize(constraints.biggest);
final _size = (state.defaultPadding + state.defaultMargin).deflateSize(constraints.biggest);
final _maxValue = state.data.maxValue - state.data.minValue;
final scale = _size.height / _maxValue;
final _minValue = state.data.minValue * scale;

final rect = Rect.fromPoints(
Offset(
constraints.maxWidth,
-scale * (max(state.data.minValue, targetMin)) +
_minValue +
areaPadding.vertical),
Offset(constraints.maxWidth, -scale * (max(state.data.minValue, targetMin)) + _minValue + areaPadding.vertical),
Offset(0.0, -scale * targetMax + _minValue + areaPadding.vertical),
);

return Size(
constraints.maxWidth -
(state.defaultPadding.horizontal + state.defaultMargin.horizontal),
(state.defaultPadding.horizontal + state.defaultMargin.horizontal - marginNeeded().horizontal),
min(rect.size.height, constraints.maxHeight),
);
}

@override
Offset applyPaintTransform(ChartState state, Size size) {
final _size =
(state.defaultPadding + state.defaultMargin).deflateSize(size);
final _size = (state.defaultPadding + state.defaultMargin).deflateSize(size);
final _maxValue = state.data.maxValue - state.data.minValue;
final scale = _size.height / _maxValue;
final _minValue = state.data.minValue * scale;

return Offset(
areaPadding.left,
_size.height -
scale * targetMax +
_minValue +
state.defaultMargin.top +
state.defaultPadding.top);
return Offset(areaPadding.left,
_size.height - scale * targetMax + _minValue + state.defaultMargin.top + state.defaultPadding.top);
}

@override
Expand Down Expand Up @@ -314,24 +280,15 @@ class TargetAreaDecoration extends DecorationPainter {
TargetAreaDecoration animateTo(DecorationPainter endValue, double t) {
if (endValue is TargetAreaDecoration) {
return TargetAreaDecoration(
targetLineColor:
Color.lerp(targetLineColor, endValue.targetLineColor, t) ??
endValue.targetLineColor,
lineWidth:
lerpDouble(lineWidth, endValue.lineWidth, t) ?? endValue.lineWidth,
targetLineColor: Color.lerp(targetLineColor, endValue.targetLineColor, t) ?? endValue.targetLineColor,
lineWidth: lerpDouble(lineWidth, endValue.lineWidth, t) ?? endValue.lineWidth,
dashArray: t < 0.5 ? dashArray : endValue.dashArray,
targetAreaFillColor:
Color.lerp(targetAreaFillColor, endValue.targetAreaFillColor, t),
targetAreaRadius:
BorderRadius.lerp(targetAreaRadius, endValue.targetAreaRadius, t),
targetAreaFillColor: Color.lerp(targetAreaFillColor, endValue.targetAreaFillColor, t),
targetAreaRadius: BorderRadius.lerp(targetAreaRadius, endValue.targetAreaRadius, t),
areaPadding: EdgeInsets.lerp(areaPadding, endValue.areaPadding, t)!,
targetMin:
lerpDouble(targetMin, endValue.targetMin, t) ?? endValue.targetMin,
targetMax:
lerpDouble(targetMax, endValue.targetMax, t) ?? endValue.targetMax,
colorOverTarget:
Color.lerp(colorOverTarget, endValue.colorOverTarget, t) ??
endValue.colorOverTarget,
targetMin: lerpDouble(targetMin, endValue.targetMin, t) ?? endValue.targetMin,
targetMax: lerpDouble(targetMax, endValue.targetMax, t) ?? endValue.targetMax,
colorOverTarget: Color.lerp(colorOverTarget, endValue.colorOverTarget, t) ?? endValue.colorOverTarget,
);
}

Expand Down
Binary file modified test/golden/complex/goldens/macos/complex_multi_charts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/complex/goldens/macos/showcase_charts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/decoration/goldens/macos/grid_decoration_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/decoration/goldens/macos/widget_decoration_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/examples/goldens/macos/bar_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/examples/goldens/macos/line_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/examples/goldens/macos/multi_line_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/examples/goldens/macos/simple_line_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/geometry/goldens/macos/bubble_geometry_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/issues/goldens/macos/issue_94.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/issues/goldens/macos/issue_94_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fdc8522

Please sign in to comment.