Skip to content

Commit 26fbb75

Browse files
authored
Trigger re-layout when resizing CPU flame chart (#9915)
1 parent 86d7bcb commit 26fbb75

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

packages/devtools_app/lib/src/shared/charts/flame_chart.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ abstract class FlameChartState<
269269
verticalControllerGroup.resetScroll();
270270
zoomController.reset();
271271
verticalExtentDelegate.recompute();
272+
} else if (widget.containerWidth != oldWidget.containerWidth) {
273+
initFlameChartElements();
274+
verticalExtentDelegate.recompute();
272275
}
273276
FocusScope.of(context).requestFocus(focusNode);
274277
super.didUpdateWidget(oldWidget);

packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ TODO: Remove this section if there are not any updates.
2727

2828
## CPU profiler updates
2929

30-
TODO: Remove this section if there are not any updates.
30+
* Fixed a bug where resizing the CPU flame chart changes the timing values
31+
across the top of the chart.
32+
[#9915](https://github.com/flutter/devtools/pull/9915)
3133

3234
## Memory updates
3335

@@ -40,7 +42,7 @@ TODO: Remove this section if there are not any updates.
4042

4143
## Network profiler updates
4244

43-
- Fixed exported response status in HAR files so that they parse as integers
45+
* Fixed exported response status in HAR files so that they parse as integers
4446
instead of strings. [#9900](https://github.com/flutter/devtools/pull/9900)
4547

4648
## Logging updates

packages/devtools_app/test/shared/charts/flame_chart_test.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
44

55
import 'package:devtools_app/devtools_app.dart';
6+
import 'package:devtools_app/src/screens/profiler/cpu_profile_transformer.dart';
67
import 'package:devtools_app/src/screens/profiler/cpu_profiler_controller.dart';
78
import 'package:devtools_app/src/screens/profiler/panes/cpu_flame_chart.dart';
89
import 'package:devtools_app/src/shared/charts/flame_chart.dart';
@@ -624,6 +625,56 @@ void main() {
624625
);
625626
});
626627
});
628+
629+
testWidgets('re-lays out elements when container width changes', (
630+
WidgetTester tester,
631+
) async {
632+
final transformer = CpuProfileTransformer();
633+
final cpuProfileData = CpuProfileData.fromJson(cpuProfileResponseJson);
634+
await tester.runAsync(() async {
635+
await transformer.processData(cpuProfileData, processId: 'test');
636+
});
637+
638+
flameChart = CpuProfileFlameChart(
639+
data: cpuProfileData,
640+
width: 1000.0,
641+
height: 1000.0,
642+
selectionNotifier: ValueNotifier<CpuStackFrame?>(null),
643+
searchMatchesNotifier: controller.searchMatches,
644+
activeSearchMatchNotifier: controller.activeSearchMatch,
645+
onDataSelected: (_) {},
646+
);
647+
648+
await pumpFlameChart(tester);
649+
expect(find.byWidget(flameChart), findsOneWidget);
650+
final FlameChartState state = tester.state(find.byWidget(flameChart));
651+
652+
// Find first row that has nodes.
653+
final rowWithNodes = state.rows.firstWhere((row) => row.nodes.isNotEmpty);
654+
final node = rowWithNodes.nodes[0];
655+
final initialNodeWidth = node.rect.width;
656+
expect(initialNodeWidth, greaterThan(0.0));
657+
658+
// Update the flame chart with a new width.
659+
flameChart = CpuProfileFlameChart(
660+
data: cpuProfileData,
661+
width: 2000.0,
662+
height: 1000.0,
663+
selectionNotifier: ValueNotifier<CpuStackFrame?>(null),
664+
searchMatchesNotifier: controller.searchMatches,
665+
activeSearchMatchNotifier: controller.activeSearchMatch,
666+
onDataSelected: (_) {},
667+
);
668+
await pumpFlameChart(tester);
669+
await tester.pumpAndSettle();
670+
671+
final updatedRowWithNodes = state.rows.firstWhere(
672+
(row) => row.nodes.isNotEmpty,
673+
);
674+
final updatedNode = updatedRowWithNodes.nodes[0];
675+
expect(updatedNode.rect.width, isNot(equals(initialNodeWidth)));
676+
expect(updatedNode.rect.width, greaterThan(initialNodeWidth));
677+
});
627678
});
628679

629680
group('ScrollingFlameChartRow', () {

0 commit comments

Comments
 (0)