Fix round: readable selected segments, panels that fit, smaller fonts

- A selected segment is the accent with white text, in both themes.
- At three columns the row of "Where compiles went", "By language" and
  "Problems" is one modest height; the reasons table is its own panel,
  "Why compiles were not cacheable", stacked under "Speed" beside
  "Over time" and as tall together as it is. In the two-column and
  one-column layouts it follows "Where compiles went".
- Raw counters use every column; each value follows its key by 16 px,
  and a key ends in "..." only where the two do not fit.
- No blank row between a table's head and its first row.
- The five embedded fonts are subset to Latin text and the symbols the
  page uses with pyftsubset (hinting dropped); the wasm goes from
  5.49 MB to 4.11 MB.
This commit is contained in:
swaits committed 2026-11-28 13:40:27 -07:00
1 parent 03ffdf887a
commit 7e864ad749
11 files changed
+173 -106

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+62 -21
View File
@@ -523,27 +523,30 @@ fn single(ui: &mut egui::Ui, title: &str, body: impl FnOnce(&mut egui::Ui)) {
close_row(ui, &[taken]);
}
/// How tall a panel is that holds `rows` table rows under its title.
fn table_height(fixed: f32, rows: usize) -> f32 {
fixed + rows as f32 * theme::space::ROW
}
/// How tall the row of "Where compiles went", "By language" and "Problems" is:
/// enough for the tallest of the three, and never less than the usual height.
fn triptych_height(view: &View) -> f32 {
use theme::layout as l;
let languages = l::LANGUAGES_FIXED_HEIGHT + view.languages.len() as f32 * theme::space::ROW + 2.0 * theme::space::PANEL_PADDING;
let problems = l::PROBLEMS_FIXED_HEIGHT + view.problems.len() as f32 * l::PROBLEM_HEIGHT + 2.0 * theme::space::PANEL_PADDING;
l::TRIPTYCH_HEIGHT
.max(where_went::height(view.not_cached.len()))
.max(languages)
.max(problems)
.max(l::WHERE_FIXED_HEIGHT)
.max(table_height(l::LANGUAGES_FIXED_HEIGHT, view.languages.len()))
.max(problems_height(view))
}
/// How tall a panel with `histograms` build-time histograms in it is.
/// How tall "Speed" is.
fn speed_height(view: &View) -> f32 {
use theme::layout as l;
let with_histograms = view
.build_times
.iter()
.filter(|times| times.compiles > 0 && !times.bins.is_empty())
.count() as f32;
l::SPEED_FIXED_HEIGHT + with_histograms * l::HISTOGRAM_HEIGHT
.count();
table_height(l::SPEED_FIXED_HEIGHT, 0) + with_histograms as f32 * l::HISTOGRAM_HEIGHT
}
fn problems_height(view: &View) -> f32 {
@@ -551,17 +554,35 @@ fn problems_height(view: &View) -> f32 {
if view.problems.is_empty() {
88.0
} else {
l::PROBLEMS_FIXED_HEIGHT + view.problems.len() as f32 * l::PROBLEM_HEIGHT + 2.0 * theme::space::PANEL_PADDING
table_height(l::PROBLEMS_FIXED_HEIGHT, 0) + view.problems.len() as f32 * l::PROBLEM_HEIGHT
}
}
/// How tall the row of "Over time" is when "Speed" and "Why compiles were not
/// cacheable" are stacked beside it: the taller of the two sides.
fn charts_height(view: &View) -> f32 {
use theme::layout as l;
let stacked = speed_height(view)
+ theme::space::PANEL_GAP
+ where_went::reasons_height(view.not_cached.len());
l::CHARTS_HEIGHT.max(stacked)
}
/// How tall each chart of "Over time" is in a row `height` tall: the usual
/// height, plus the room a taller row leaves.
fn chart_height(height: f32) -> f32 {
let extra = (height - theme::layout::CHARTS_HEIGHT).max(0.0);
theme::drawing::CHART_HEIGHT + (extra / 2.0 - 2.0 * theme::space::LINE).max(0.0)
}
/// The whole page below the controls: a grid of panels.
fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec<String>) {
let p = theme::ui(ui);
use theme::layout as l;
let gap = theme::space::PANEL_GAP;
if let Some(error) = &view.server.error {
style::banner(ui, egui::RichText::new(format!("sccache is not working: {error}")), p.bad);
ui.add_space(theme::space::PANEL_GAP);
ui.add_space(gap);
}
let columns = theme::columns(ui.available_rect_before_wrap().width());
@@ -582,32 +603,52 @@ fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec
let (_, b) = style::panel(ui, b, "By language", |ui| where_went::languages(ui, view));
let (_, c) = style::panel(ui, c, "Problems", |ui| problems::section(ui, view));
close_row(ui, &[a, b, c]);
let [a, b] = row(ui, l::CHARTS_HEIGHT, &[2, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Over time", |ui| overtime::section(ui, view, hidden_languages));
let (_, b) = style::panel(ui, b, "Speed", |ui| speed::section(ui, view));
close_row(ui, &[a, b]);
// "Over time" over two columns; "Speed" and the reasons stacked in the third, together as tall.
let height = charts_height(view);
let [wide, side] = row(ui, height, &[2, 1]).try_into().expect("two panels");
let speed = speed_height(view);
let speed_rect = egui::Rect::from_min_max(side.min, egui::pos2(side.right(), side.top() + speed));
let reasons_rect = egui::Rect::from_min_max(egui::pos2(side.left(), side.top() + speed + gap), side.max);
let (_, wide) = style::panel(ui, wide, "Over time", |ui| {
overtime::section(ui, view, hidden_languages, chart_height(height))
});
let (_, speed) = style::panel(ui, speed_rect, "Speed", |ui| speed::section(ui, view));
let (_, reasons) = style::panel(ui, reasons_rect, "Why compiles were not cacheable", |ui| {
where_went::reasons(ui, view)
});
close_row(ui, &[wide, speed, reasons]);
}
2 => {
let height = triptych_height(view);
let reasons = where_went::reasons_height(view.not_cached.len());
let height = l::TRIPTYCH_HEIGHT.max(l::WHERE_FIXED_HEIGHT).max(reasons);
let [a, b] = row(ui, height, &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Where compiles went", |ui| where_went::section(ui, view));
let (_, b) = style::panel(ui, b, "By language", |ui| where_went::languages(ui, view));
let (_, b) = style::panel(ui, b, "Why compiles were not cacheable", |ui| where_went::reasons(ui, view));
close_row(ui, &[a, b]);
let height = l::TRIPTYCH_HEIGHT.min(360.0).max(problems_height(view)).max(speed_height(view));
let height = l::TRIPTYCH_HEIGHT
.max(table_height(l::LANGUAGES_FIXED_HEIGHT, view.languages.len()))
.max(problems_height(view));
let [a, b] = row(ui, height, &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Problems", |ui| problems::section(ui, view));
let (_, b) = style::panel(ui, b, "Speed", |ui| speed::section(ui, view));
let (_, a) = style::panel(ui, a, "By language", |ui| where_went::languages(ui, view));
let (_, b) = style::panel(ui, b, "Problems", |ui| problems::section(ui, view));
close_row(ui, &[a, b]);
let [a] = row(ui, l::CHARTS_HEIGHT, &[2]).try_into().expect("one panel");
let (_, a) = style::panel(ui, a, "Over time", |ui| overtime::section(ui, view, hidden_languages));
let (_, a) = style::panel(ui, a, "Over time", |ui| {
overtime::section(ui, view, hidden_languages, theme::drawing::CHART_HEIGHT)
});
close_row(ui, &[a]);
single(ui, "Speed", |ui| speed::section(ui, view));
}
_ => {
// One column: the phone's order, each panel as tall as what it holds.
single(ui, "Problems", |ui| problems::section(ui, view));
single(ui, "Where compiles went", |ui| where_went::section(ui, view));
single(ui, "Why compiles were not cacheable", |ui| where_went::reasons(ui, view));
single(ui, "By language", |ui| where_went::languages(ui, view));
single(ui, "Over time", |ui| overtime::section(ui, view, hidden_languages));
single(ui, "Over time", |ui| {
overtime::section(ui, view, hidden_languages, theme::drawing::CHART_HEIGHT)
});
single(ui, "Speed", |ui| speed::section(ui, view));
}
}
+9 -6
View File
@@ -18,7 +18,7 @@ pub fn hit_rate(hits: u64, misses: u64) -> Option<f64> {
(hits + misses > 0).then(|| hits as f64 / (hits + misses) as f64)
}
pub fn section(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) {
pub fn section(ui: &mut Ui, view: &View, hidden: &mut Vec<String>, chart_height: f32) {
let p = theme::ui(ui);
filter(ui, view, hidden);
@@ -33,11 +33,11 @@ pub fn section(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) {
ui.add_space(theme::space::BETWEEN_PARTS);
part_title(ui, "Hit rate");
hit_rate_chart(ui, view, hidden, axes);
hit_rate_chart(ui, view, hidden, axes, chart_height);
ui.add_space(theme::space::BETWEEN_PARTS);
part_title(ui, "Compiles");
volume_chart(ui, view, hidden, axes);
volume_chart(ui, view, hidden, axes, chart_height);
}
/// The title of one part of a panel, in the style of a panel title.
@@ -154,6 +154,7 @@ struct Axes {
fn time_plot<'a>(
name: &'static str,
axes: Axes,
height: f32,
readout: impl Fn(&PlotPoint) -> String + 'a,
) -> Plot<'a> {
let (first, last) = (axes.window.0 + axes.tz, axes.window.1 + axes.tz);
@@ -164,7 +165,7 @@ fn time_plot<'a>(
let label_color = theme::of(axes.dark).muted;
let (from, to) = (first, last);
Plot::new(name)
.height(theme::drawing::CHART_HEIGHT)
.height(height)
.show_background(false)
.grid_color(theme::of(axes.dark).grid)
.allow_scroll(false)
@@ -263,7 +264,7 @@ fn split(bucket: &Bucket, hidden: &[String]) -> (u64, u64) {
}
}
fn hit_rate_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
fn hit_rate_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes, height: f32) {
let p = theme::ui(ui);
// One line per stretch of buckets that have a hit rate.
let mut runs: Vec<Vec<PlotPoint>> = Vec::new();
@@ -286,6 +287,7 @@ fn hit_rate_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
let plot = time_plot(
"hit-rate-chart",
axes,
height,
|point| format!("{} · {:.0}%", fmt::moment_text(point.x.round() as i64), point.y),
)
.default_y_bounds(0.0, 100.0)
@@ -323,7 +325,7 @@ fn hit_rate_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
style::legend(ui, entries);
}
fn volume_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
fn volume_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes, height: f32) {
let p = theme::ui(ui);
// The tallest stack of one bucket, with a little air above it.
let top = view
@@ -338,6 +340,7 @@ fn volume_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
let plot = time_plot(
"volume-chart",
axes,
height,
|point| fmt::moment_text(point.x.round() as i64),
)
.default_y_bounds(0.0, top)
+61 -50
View File
@@ -35,14 +35,14 @@ fn leaves(value: &serde_json::Value, path: String, out: &mut Vec<(String, String
}
}
/// How many lines a panel `width` wide runs its key/value lines in.
fn columns(width: f32) -> usize {
/// How many columns of key/value lines fit in a panel's `inner` width.
fn columns(inner: f32) -> usize {
let gap = theme::space::PANEL_GAP + 4.0;
let inner = width - 2.0 * (theme::space::PANEL_PADDING + 1.0);
(((inner + gap) / (theme::layout::RAW_LINE_WIDTH + gap)) as usize).max(1)
(((inner + gap) / (theme::layout::RAW_LINE_WIDTH + gap)) as usize).clamp(1, 3)
}
/// How tall the panel is at `width`: its title and, when open, its lines.
/// How tall the panel is when it is `width` wide: its title and, when open,
/// its lines.
pub fn height(view: &View, width: f32, open: bool) -> f32 {
let title = theme::space::ROW + theme::space::UNDER_TITLE + 2.0 * (theme::space::PANEL_PADDING + 1.0);
if !open {
@@ -54,7 +54,8 @@ pub fn height(view: &View, width: f32, open: bool) -> f32 {
leaves(&view.raw, String::new(), &mut out);
lines = out.len();
}
title + lines.div_ceil(columns(width)) as f32 * theme::space::ROW
let inner = width - 2.0 * (theme::space::PANEL_PADDING + 1.0);
title + lines.div_ceil(columns(inner)) as f32 * theme::space::ROW
}
/// The panel at `rect`; its title opens and closes it. Returns the rect it took.
@@ -90,57 +91,67 @@ pub fn section(ui: &mut Ui, view: &View, rect: Rect) -> Rect {
taken
}
/// Key/value lines in as many columns of the raw line width as fit, read left
/// to right and then down: each line in its own cell, the key in small print at
/// the left and the value in mono at the right.
/// Key/value lines in as many columns of the raw line width as fit, filled
/// left to right and then down: each line in its own cell, the key in small
/// print and the value in mono right after it.
fn flow(ui: &mut Ui, lines: &[(String, String)]) {
let p = theme::ui(ui);
let width = ui.available_rect_before_wrap().width();
let gap = theme::space::PANEL_GAP + 4.0;
let columns = columns(width + 2.0 * (theme::space::PANEL_PADDING + 1.0));
let columns = columns(width);
let cell = (width - gap * (columns - 1) as f32) / columns as f32;
let font = egui::FontId::proportional(theme::px::SMALL);
let mono = theme::number_font(theme::px::SMALL);
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = egui::vec2(gap, 0.0);
for (key, value) in lines {
let (rect, response) =
ui.allocate_exact_size(egui::vec2(cell, theme::space::ROW), Sense::hover());
let painter = ui.painter();
let value_galley = painter.layout_no_wrap(value.clone(), mono.clone(), p.text);
let value_width = value_galley.size().x;
painter.galley(
Pos2::new(rect.right() - value_width, rect.center().y - value_galley.size().y / 2.0),
value_galley,
p.text,
);
// The key ends in "…" when it would touch the value; all of it shows on hover.
let key_clip = Rect::from_min_max(
rect.min,
Pos2::new(rect.right() - value_width - theme::space::ITEM, rect.bottom()),
);
let key_galley = painter.layout_no_wrap(key.clone(), font.clone(), p.muted);
let key_width = key_galley.size().x;
let cut = key_width > key_clip.width();
let key_galley = if cut {
let mut chars = key.chars().count();
loop {
chars -= 1;
let shorter: String = key.chars().take(chars).collect::<String>() + "…";
let galley = painter.layout_no_wrap(shorter, font.clone(), p.muted);
if galley.size().x <= key_clip.width() || chars <= 1 {
break galley;
for line in lines.chunks(columns) {
// One exact row of cells: a row is laid out, never wrapped, so every column is used.
ui.allocate_ui_with_layout(
egui::vec2(width, theme::space::ROW),
egui::Layout::left_to_right(egui::Align::Center),
|ui| {
ui.spacing_mut().item_spacing.x = gap;
for (key, value) in line {
let (rect, response) =
ui.allocate_exact_size(egui::vec2(cell, theme::space::ROW), Sense::hover());
let painter = ui.painter();
let clip = rect.intersect(ui.clip_rect());
let value_galley = painter.layout_no_wrap(value.clone(), mono.clone(), p.text);
let value_width = value_galley.size().x;
// The value follows its key by the key/value gap, not pushed to the cell's edge;
// where the two do not fit, the key ends in "…" and all of it shows on hover.
let key_room = (rect.width() - theme::space::KEY_VALUE_GAP - value_width).max(0.0);
let key_galley = painter.layout_no_wrap(key.clone(), font.clone(), p.muted);
let key_width = key_galley.size().x;
let cut = key_width > key_room;
let key_galley = if cut {
let mut chars = key.chars().count();
loop {
chars -= 1;
let shorter: String = key.chars().take(chars).collect::<String>() + "…";
let galley = painter.layout_no_wrap(shorter, font.clone(), p.muted);
if galley.size().x <= key_room || chars <= 1 {
break galley;
}
}
} else {
key_galley
};
let key_width = key_galley.size().x;
painter.with_clip_rect(clip).galley(
Pos2::new(rect.left(), rect.center().y - key_galley.size().y / 2.0),
key_galley,
p.muted,
);
let value_left = rect.left() + key_width + theme::space::KEY_VALUE_GAP;
painter.with_clip_rect(clip).galley(
Pos2::new(value_left, rect.center().y - value_galley.size().y / 2.0),
value_galley,
p.text,
);
if cut || value_left + value_width > rect.right() {
response.on_hover_text(format!("{key} {value}"));
}
}
} else {
key_galley
};
painter
.with_clip_rect(key_clip.intersect(ui.clip_rect()))
.galley(Pos2::new(rect.left(), rect.center().y - key_galley.size().y / 2.0), key_galley, p.muted);
if cut {
response.on_hover_text(format!("{key} {value}"));
}
}
});
},
);
}
}
+4 -4
View File
@@ -270,7 +270,7 @@ pub fn segmented(ui: &mut Ui, id_salt: &'static str, labels: &[&str], chosen: us
.on_hover_cursor(egui::CursorIcon::PointingHand);
let selected = index == chosen;
let fill = if selected {
tint(p.accent, 0.22)
p.accent
} else if response.hovered() {
p.hover
} else {
@@ -283,7 +283,7 @@ pub fn segmented(ui: &mut Ui, id_salt: &'static str, labels: &[&str], chosen: us
painter.vline(segment.left() + 0.5, segment.y_range().shrink(7.0), Stroke::new(1.0, p.border));
}
let color = if selected {
p.accent
p.on_accent
} else if response.hovered() {
p.text
} else {
@@ -419,8 +419,8 @@ pub fn table(ui: &mut Ui, head: &[&str], rows: &[Vec<Cell>]) {
top += space::ROW;
}
// Without a head the rows start at the top; with one, under it.
let first = top + if head.is_empty() { 0.0 } else { space::ROW };
// The rows start under the head, or at the top when there is none.
let first = top;
for (index, (row, line)) in rows.iter().zip(&galleys).enumerate() {
top = first + index as f32 * space::ROW;
if index + 1 < rows.len() {
+13 -5
View File
@@ -42,6 +42,8 @@ pub struct Palette {
pub not_compile: Color32,
/// Selected controls.
pub accent: Color32,
/// Text on the accent: what a selected control says.
pub on_accent: Color32,
/// The tint over time nothing was recorded in.
pub unrecorded: Color32,
/// The line of the mean, the median and the p90 on a build-time histogram.
@@ -69,6 +71,7 @@ pub const DARK: Palette = Palette {
unsupported: rgb(0xb08cf0),
not_compile: rgb(0x4fb3bf),
accent: rgb(0x5b8def),
on_accent: rgb(0xffffff),
unrecorded: Color32::from_rgba_premultiplied(14, 14, 14, 14),
mean: rgb(0xe6e9ef),
median: rgb(0xb08cf0),
@@ -94,6 +97,7 @@ pub const LIGHT: Palette = Palette {
unsupported: rgb(0x7c5cd6),
not_compile: rgb(0x1f8a9b),
accent: rgb(0x3a6fd8),
on_accent: rgb(0xffffff),
unrecorded: Color32::from_rgba_premultiplied(0, 0, 0, 18),
mean: rgb(0x1b2029),
median: rgb(0x7c5cd6),
@@ -162,6 +166,8 @@ pub mod space {
pub const CONTROL_PAD: f32 = 10.0;
pub const TITLE_SPACING: f32 = 0.8;
pub const TOOLBAR_NOTE_WIDTH: f32 = 150.0;
/// Between a raw counter's key and its value.
pub const KEY_VALUE_GAP: f32 = 16.0;
/// Room under a title before the panel's content.
pub const UNDER_TITLE: f32 = 8.0;
/// Room between titled parts of one panel.
@@ -186,23 +192,25 @@ pub mod layout {
pub const CARD_HEIGHT: f32 = 104.0;
/// The row of "Where compiles went", "By language" and "Problems". It grows
/// only when the tables have more rows than this height holds.
pub const TRIPTYCH_HEIGHT: f32 = 420.0;
pub const TRIPTYCH_HEIGHT: f32 = 232.0;
/// The row of "Over time" and "Speed".
pub const CHARTS_HEIGHT: f32 = 516.0;
/// "Where compiles went" needs this much beside its reasons table.
pub const WHERE_FIXED_HEIGHT: f32 = 304.0;
/// "Where compiles went": its bar, legend and the "of the built" line.
pub const WHERE_FIXED_HEIGHT: f32 = 244.0;
/// "Why compiles were not cacheable" needs this much beside its rows.
pub const REASONS_FIXED_HEIGHT: f32 = 90.0;
/// From this panel width the "By language" table has room for its hit-rate bars.
pub const LANGUAGE_BARS_FROM: f32 = 380.0;
/// "By language" needs this much beside its rows.
pub const LANGUAGES_FIXED_HEIGHT: f32 = 60.0;
/// "Speed" needs this much beside its histograms.
pub const SPEED_FIXED_HEIGHT: f32 = 270.0;
pub const SPEED_FIXED_HEIGHT: f32 = 250.0;
/// "Problems" needs this much beside its problems.
pub const PROBLEMS_FIXED_HEIGHT: f32 = 60.0;
/// "Problems" needs this much per problem.
pub const PROBLEM_HEIGHT: f32 = 62.0;
/// "Speed" needs this much per language with a histogram.
pub const HISTOGRAM_HEIGHT: f32 = 90.0;
pub const HISTOGRAM_HEIGHT: f32 = 85.0;
}
/// Drawings inside panels, in pixels.
+24 -20
View File
@@ -52,28 +52,32 @@ pub fn section(ui: &mut Ui, view: &View) {
),
),
));
if !view.not_cached.is_empty() {
ui.add_space(theme::space::BETWEEN_PARTS);
crate::overtime::part_title(ui, "Why compiles could not be cached");
let rows: Vec<Vec<Cell>> = view
.not_cached
.iter()
.map(|(reason, count)| {
vec![
Cell::Text(theme::body(reason.clone())),
Cell::Text(theme::number(fmt::count(*count))),
Cell::Text(theme::number(fmt::share(*count, totals.not_cacheable))),
]
})
.collect();
style::table(ui, &["Reason", "Compiles", "Share"], &rows);
}
}
/// How tall the panel is with `reasons` rows in its table.
pub fn height(reasons: usize) -> f32 {
theme::layout::WHERE_FIXED_HEIGHT + reasons as f32 * theme::space::ROW
/// "Why compiles were not cacheable": the reasons table, one row per reason.
pub fn reasons(ui: &mut Ui, view: &View) {
if view.not_cached.is_empty() {
ui.label(theme::small(ui, "Every compile could be cached in this range."));
return;
}
let rows: Vec<Vec<Cell>> = view
.not_cached
.iter()
.map(|(reason, count)| {
vec![
Cell::Text(theme::body(reason.clone())),
Cell::Text(theme::number(fmt::count(*count))),
Cell::Text(theme::number(fmt::share(*count, view.totals.not_cacheable))),
]
})
.collect();
style::table(ui, &["Reason", "Compiles", "Share"], &rows);
}
/// How tall "Why compiles were not cacheable" is with `rows` reasons.
pub fn reasons_height(rows: usize) -> f32 {
let rows = rows.max(1);
theme::layout::REASONS_FIXED_HEIGHT + rows as f32 * theme::space::ROW
}
/// "By language": one row per language, with hits, misses, errors, the hit rate