Skip to main content

ringkernel_procint/gui/panels/
dfg_panel.rs

1//! DFG statistics panel.
2
3use crate::analytics::DFGMetrics;
4use crate::gui::{section_header, styled_panel, Theme};
5use eframe::egui::{self, Ui};
6
7/// DFG statistics panel.
8pub struct DfgPanel;
9
10impl Default for DfgPanel {
11    fn default() -> Self {
12        Self
13    }
14}
15
16impl DfgPanel {
17    /// Render the panel.
18    pub fn render(&mut self, ui: &mut Ui, theme: &Theme, metrics: &DFGMetrics) {
19        styled_panel(ui, theme, |ui| {
20            section_header(ui, theme, "DFG METRICS");
21
22            // Basic counts
23            ui.horizontal(|ui| {
24                ui.vertical(|ui| {
25                    ui.label(
26                        egui::RichText::new("Nodes")
27                            .size(11.0)
28                            .color(theme.text_muted),
29                    );
30                    ui.label(
31                        egui::RichText::new(format!("{}", metrics.node_count))
32                            .size(16.0)
33                            .strong(),
34                    );
35                });
36                ui.add_space(20.0);
37                ui.vertical(|ui| {
38                    ui.label(
39                        egui::RichText::new("Edges")
40                            .size(11.0)
41                            .color(theme.text_muted),
42                    );
43                    ui.label(
44                        egui::RichText::new(format!("{}", metrics.edge_count))
45                            .size(16.0)
46                            .strong(),
47                    );
48                });
49            });
50
51            ui.add_space(12.0);
52
53            // Graph properties
54            ui.collapsing("Graph Properties", |ui| {
55                ui.label(format!("Density: {:.3}", metrics.density));
56                ui.label(format!("Avg Degree: {:.2}", metrics.avg_degree));
57                ui.label(format!("Max In-Degree: {}", metrics.max_in_degree));
58                ui.label(format!("Max Out-Degree: {}", metrics.max_out_degree));
59                ui.label(format!("Parallelism: {:.2}", metrics.parallelism_factor));
60            });
61
62            ui.add_space(8.0);
63
64            // Performance metrics
65            ui.collapsing("Performance", |ui| {
66                ui.label(format!("Total Events: {}", metrics.total_events));
67                ui.label(format!(
68                    "Avg Events/Node: {:.1}",
69                    metrics.avg_events_per_node
70                ));
71                ui.label(format!("Avg Duration: {:.0}ms", metrics.avg_duration_ms));
72                ui.label(format!("Total Cost: ${:.2}", metrics.total_cost));
73            });
74
75            ui.add_space(8.0);
76
77            // Bottleneck indicator
78            let bottleneck_color = if metrics.bottleneck_score > 0.7 {
79                theme.error
80            } else if metrics.bottleneck_score > 0.3 {
81                theme.warning
82            } else {
83                theme.success
84            };
85
86            ui.horizontal(|ui| {
87                ui.label("Bottleneck Risk:");
88                ui.label(
89                    egui::RichText::new(format!("{:.0}%", metrics.bottleneck_score * 100.0))
90                        .color(bottleneck_color),
91                );
92            });
93
94            // Complexity score
95            let complexity = metrics.complexity_score();
96            ui.horizontal(|ui| {
97                ui.label("Complexity:");
98                ui.label(egui::RichText::new(format!("{:.2}", complexity)).color(
99                    if complexity > 0.7 {
100                        theme.warning
101                    } else {
102                        theme.text
103                    },
104                ));
105            });
106        });
107    }
108}