Skip to content

Commit 8bf18c4

Browse files
committed
fix(ui): Perfect symmetry for implosion animation by removing opacity tricks
1 parent cc399e4 commit 8bf18c4

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

lib/flutter_circle_pack_chart_painter.dart

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,16 @@ class FlutterCirclePackChartPainter extends CustomPainter {
8080
void _drawImplodingNode(Canvas canvas, PackedNode node, Color parentColor) {
8181
final Color color = node.node.color ?? parentColor;
8282

83-
// Staggered threshold: children merge and stay solid until 85% of animation.
84-
// This prevents the parent circle from showing through while they are still separate.
85-
const double threshold = 0.85;
86-
87-
final double childOpacity = (1.0 - (animationValue - threshold) / (1.0 - threshold)).clamp(0.0, 1.0);
88-
final double parentOpacity = ((animationValue - threshold) / (1.0 - threshold)).clamp(0.0, 1.0);
89-
83+
// Exact inverse of the explosion:
84+
// Children move from their packed positions back to the parent's center
85+
// and grow to match the parent's radius.
9086
for (final child in node.children) {
91-
// Move children from their packed positions back to parent center (node.x, node.y)
9287
final double x = child.x + (node.x - child.x) * animationValue;
9388
final double y = child.y + (node.y - child.y) * animationValue;
94-
// Grow from child.r to parent.r (node.r)
9589
final double r = lerpDouble(child.r, node.r, animationValue)!;
9690

97-
_drawLeaf(canvas, x, y, r, child.node, color, opacity: childOpacity);
91+
_drawLeaf(canvas, x, y, r, child.node, color, opacity: 1.0);
9892
}
99-
100-
// Parent circle fades in only at the very end of the implosion
101-
_drawLeaf(canvas, node.x, node.y, node.r, node.node, color, opacity: parentOpacity);
10293
}
10394

10495
void _drawLeaf(

0 commit comments

Comments
 (0)