Redesign the page: a grid of panels with an instrument-panel look
Every colour, size, spacing and font now lives in crates/ui/src/theme.rs. At 1100 px and wider the page is three columns of panels, at 700 px two, below that one: a toolbar with the range as one segmented control, a headline panel, six stat cards in one row, three panels side by side, then Over time beside Speed, then Raw counters as key/value lines. The type is Inter and JetBrains Mono (SIL Open Font License, licence files beside the fonts). Tables size their columns to what they hold, charts keep their time labels inside the plot and tint unrecorded time, and the hit-rate bars leave the language table where there is no room. Behaviour is unchanged: ranges, refresh, theme switch, Copy summary, Export JSON, Zero stats with its question, the language filter and the remembered settings work as before.
This commit is contained in:
1 parent
72fcf8f976
commit
a7d836d45a
19 files changed
+2214
-979
No files matched your search
@@ -0,0 +1,92 @@
|
||||
Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION AND CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,93 @@
|
||||
Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Binary file not shown.
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="color-scheme" content="dark light" />
|
||||
<title>sccache dash</title>
|
||||
<link data-trunk rel="rust" data-bin="sccache-dash-ui" />
|
||||
<style>
|
||||
@@ -13,7 +14,14 @@
|
||||
height: 100dvh;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #111;
|
||||
/* The page colour of each theme (crates/ui/src/theme.rs), so nothing flashes while the page loads. */
|
||||
background: #0e1116;
|
||||
}
|
||||
@media (prefers-color-scheme: light) {
|
||||
html,
|
||||
body {
|
||||
background: #f5f6f8;
|
||||
}
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
|
||||
+521
-294
@@ -6,6 +6,7 @@ use eframe::egui;
|
||||
use sccache_dash_api::{Range, View};
|
||||
|
||||
use crate::fmt;
|
||||
use crate::theme;
|
||||
use crate::{cards, extras, net, overtime, problems, raw, speed, style, where_went};
|
||||
|
||||
/// Refresh intervals offered, in seconds; zero means off.
|
||||
@@ -86,12 +87,7 @@ impl Dashboard {
|
||||
};
|
||||
let ctx = &cc.egui_ctx;
|
||||
ctx.set_theme(dashboard.theme.preference());
|
||||
ctx.all_styles_mut(|style| {
|
||||
style
|
||||
.text_styles
|
||||
.insert(egui::TextStyle::Small, egui::FontId::proportional(11.5));
|
||||
style.spacing.item_spacing = egui::vec2(8.0, 4.0);
|
||||
});
|
||||
theme::install(ctx);
|
||||
dashboard
|
||||
}
|
||||
|
||||
@@ -179,6 +175,10 @@ impl eframe::App for Dashboard {
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
// The whole window in the page colour first: the toolbar sits outside the
|
||||
// scrolling panel, and the browser's own canvas colour must never show.
|
||||
ui.painter()
|
||||
.rect_filled(ui.max_rect(), 0.0, theme::ctx(ui.ctx()).page);
|
||||
controls(self, ui);
|
||||
if let (Some(view), Some(error)) = (&self.view, &self.error) {
|
||||
lost_contact(
|
||||
@@ -188,23 +188,31 @@ impl eframe::App for Dashboard {
|
||||
ui.available_rect_before_wrap().width(),
|
||||
);
|
||||
}
|
||||
egui::CentralPanel::default().show(ui, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false; 2])
|
||||
.show(ui, |ui| {
|
||||
ui.add_space(8.0);
|
||||
let Self {
|
||||
range,
|
||||
view,
|
||||
hidden_languages,
|
||||
..
|
||||
} = self;
|
||||
match view {
|
||||
None => waiting(ui, self.error.as_deref(), self.refresh_secs),
|
||||
Some(view) => page(ui, view, *range, hidden_languages),
|
||||
}
|
||||
});
|
||||
});
|
||||
egui::CentralPanel::default()
|
||||
.frame(
|
||||
egui::Frame::NONE
|
||||
.fill(theme::ctx(ui.ctx()).page)
|
||||
.inner_margin(egui::Margin::symmetric(
|
||||
theme::space::PAGE_MARGIN as i8,
|
||||
theme::space::PAGE_MARGIN as i8,
|
||||
)),
|
||||
)
|
||||
.show(ui, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false; 2])
|
||||
.show(ui, |ui| {
|
||||
let Self {
|
||||
range,
|
||||
view,
|
||||
hidden_languages,
|
||||
..
|
||||
} = self;
|
||||
match view {
|
||||
None => waiting(ui, self.error.as_deref(), self.refresh_secs),
|
||||
Some(view) => page(ui, view, *range, hidden_languages),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if self.asking_zero {
|
||||
zero_question(self, ui.ctx());
|
||||
@@ -237,114 +245,176 @@ fn remembered<T: serde::de::DeserializeOwned>(
|
||||
storage.and_then(|storage| eframe::get_value(storage, key))
|
||||
}
|
||||
|
||||
/// The row of controls that stays at the top of the page.
|
||||
fn theme_labels() -> [&'static str; 3] {
|
||||
ThemeChoice::ALL.map(|theme| theme.name())
|
||||
}
|
||||
|
||||
/// About how wide the row of actions is, from the width of its labels.
|
||||
fn actions_width(ui: &egui::Ui) -> f32 {
|
||||
let medium = theme::medium(theme::px::BODY);
|
||||
let label = |text: &str| style::text_width(ui, text, medium.clone()) + 22.0;
|
||||
let gaps = theme::space::PANEL_GAP;
|
||||
label(&fmt::refresh_label(30)) + label("Refresh")
|
||||
+ theme_labels().iter().map(|text| style::text_width(ui, text, medium.clone()) + 2.0 * theme::space::CONTROL_PAD).sum::<f32>()
|
||||
+ label("Copy summary") + label("Export JSON") + label("Zero stats")
|
||||
+ theme::space::TOOLBAR_NOTE_WIDTH
|
||||
+ gaps * 7.0
|
||||
}
|
||||
|
||||
/// The row of controls that stays at the top of the page: the range as one
|
||||
/// segmented control at the left; the actions at the right, on their own lines
|
||||
/// where there is no room beside the range.
|
||||
fn controls(dashboard: &mut Dashboard, ui: &mut egui::Ui) {
|
||||
let ctx = ui.ctx().clone();
|
||||
let now = Dashboard::now(&ctx);
|
||||
egui::Panel::top("controls").show(ui, |ui| {
|
||||
ui.add_space(6.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for range in Range::ALL {
|
||||
if ui
|
||||
.add(egui::Button::selectable(
|
||||
dashboard.range == range,
|
||||
range.code(),
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
dashboard.range = range;
|
||||
dashboard.settings_changed = true;
|
||||
dashboard.send(&ctx, Ask::View);
|
||||
}
|
||||
}
|
||||
let gap = theme::space::PANEL_GAP;
|
||||
let margin = theme::space::PAGE_MARGIN;
|
||||
ui.add_space(margin);
|
||||
let width = ui.available_rect_before_wrap().width() - 2.0 * margin;
|
||||
let medium = theme::medium(theme::px::BODY);
|
||||
let range_width: f32 = Range::ALL
|
||||
.iter()
|
||||
.map(|range| style::text_width(ui, range.code(), medium.clone()) + 2.0 * theme::space::CONTROL_PAD)
|
||||
.sum();
|
||||
let beside = width >= theme::layout::TOOLBAR_TWO_LINES_BELOW;
|
||||
let one_line = beside && range_width + gap + actions_width(ui) <= width;
|
||||
let phone = width + 2.0 * theme::space::PAGE_MARGIN < theme::layout::TWO_COLUMNS_FROM;
|
||||
|
||||
ui.add_space(8.0);
|
||||
let mut refresh_secs = dashboard.refresh_secs;
|
||||
egui::ComboBox::from_id_salt("refresh")
|
||||
.selected_text(fmt::refresh_label(refresh_secs))
|
||||
.show_ui(ui, |ui| {
|
||||
for secs in REFRESH_CHOICES {
|
||||
ui.selectable_value(&mut refresh_secs, secs, fmt::refresh_label(secs));
|
||||
}
|
||||
});
|
||||
if refresh_secs != dashboard.refresh_secs {
|
||||
dashboard.refresh_secs = refresh_secs;
|
||||
let labels: Vec<&str> = Range::ALL.iter().map(|range| range.code()).collect();
|
||||
let chosen = Range::ALL.iter().position(|range| *range == dashboard.range).unwrap_or(0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = gap;
|
||||
ui.add_space(margin);
|
||||
if let Some(index) = style::segmented(ui, "range", &labels, chosen) {
|
||||
if index != chosen {
|
||||
dashboard.range = Range::ALL[index];
|
||||
dashboard.settings_changed = true;
|
||||
}
|
||||
if ui.button("Refresh").clicked() {
|
||||
dashboard.send(&ctx, Ask::View);
|
||||
}
|
||||
|
||||
ui.add_space(8.0);
|
||||
for theme in ThemeChoice::ALL {
|
||||
if ui
|
||||
.add(egui::Button::selectable(dashboard.theme == theme, theme.name()))
|
||||
.clicked()
|
||||
{
|
||||
dashboard.theme = theme;
|
||||
dashboard.settings_changed = true;
|
||||
ctx.set_theme(theme.preference());
|
||||
}
|
||||
}
|
||||
|
||||
ui.add_space(8.0);
|
||||
let online = dashboard.view.is_some();
|
||||
let copy = ui.add_enabled(online, egui::Button::new("Copy summary"));
|
||||
if copy.clicked() {
|
||||
if let Some(view) = &dashboard.view {
|
||||
ctx.copy_text(view.summary_markdown.clone());
|
||||
}
|
||||
dashboard.flash("Summary copied", now);
|
||||
}
|
||||
let export = ui.add_enabled(online, egui::Button::new("Export JSON"));
|
||||
if export.clicked() {
|
||||
let note = net::download("/api/export").map_or_else(
|
||||
|error| format!("Export failed: {error}"),
|
||||
|()| "Export started".to_owned(),
|
||||
}
|
||||
if one_line {
|
||||
ui.add_space((ui.available_width() - actions_width(ui)).max(0.0));
|
||||
ui.allocate_ui_with_layout(
|
||||
egui::vec2(actions_width(ui), theme::layout::TOOLBAR_HEIGHT),
|
||||
egui::Layout::left_to_right(egui::Align::Center),
|
||||
|ui| actions(dashboard, ui, &ctx, now, gap),
|
||||
);
|
||||
}
|
||||
});
|
||||
if !one_line {
|
||||
let height = theme::layout::TOOLBAR_HEIGHT;
|
||||
ui.add_space(margin);
|
||||
let room = ui.available_rect_before_wrap().width();
|
||||
let group_width = if phone { room } else { actions_width(ui).min(room) };
|
||||
// On a phone the actions wrap at the left; on a narrower window they sit
|
||||
// on a second line, at the right.
|
||||
let layout = if phone {
|
||||
egui::Layout::left_to_right(egui::Align::Center).with_main_wrap(true)
|
||||
} else {
|
||||
egui::Layout::right_to_left(egui::Align::Center)
|
||||
};
|
||||
ui.allocate_ui_with_layout(egui::vec2(room, height), layout, |ui| {
|
||||
if !phone {
|
||||
ui.allocate_ui_with_layout(
|
||||
egui::vec2(group_width, height),
|
||||
egui::Layout::left_to_right(egui::Align::Center),
|
||||
|ui| actions(dashboard, ui, &ctx, now, gap),
|
||||
);
|
||||
dashboard.flash(note, now);
|
||||
} else {
|
||||
ui.spacing_mut().item_spacing = egui::vec2(gap, gap);
|
||||
actions(dashboard, ui, &ctx, now, gap);
|
||||
}
|
||||
let zeroing = dashboard
|
||||
});
|
||||
}
|
||||
ui.add_space(gap - theme::space::LINE);
|
||||
}
|
||||
|
||||
/// Refresh, theme, Copy summary, Export JSON, Zero stats, and the message slot.
|
||||
fn actions(dashboard: &mut Dashboard, ui: &mut egui::Ui, ctx: &egui::Context, now: f64, gap: f32) {
|
||||
ui.spacing_mut().item_spacing.x = gap;
|
||||
let mut refresh_secs = dashboard.refresh_secs;
|
||||
egui::ComboBox::from_id_salt("refresh")
|
||||
.selected_text(fmt::refresh_label(refresh_secs))
|
||||
.show_ui(ui, |ui| {
|
||||
for secs in REFRESH_CHOICES {
|
||||
ui.selectable_value(&mut refresh_secs, secs, fmt::refresh_label(secs));
|
||||
}
|
||||
});
|
||||
if refresh_secs != dashboard.refresh_secs {
|
||||
dashboard.refresh_secs = refresh_secs;
|
||||
dashboard.settings_changed = true;
|
||||
}
|
||||
if ui.button("Refresh").clicked() {
|
||||
dashboard.send(ctx, Ask::View);
|
||||
}
|
||||
|
||||
let theme_chosen = ThemeChoice::ALL
|
||||
.iter()
|
||||
.position(|theme| *theme == dashboard.theme)
|
||||
.unwrap_or(0);
|
||||
if let Some(index) = style::segmented(ui, "theme", &theme_labels(), theme_chosen) {
|
||||
let theme = ThemeChoice::ALL[index];
|
||||
dashboard.theme = theme;
|
||||
dashboard.settings_changed = true;
|
||||
ctx.set_theme(theme.preference());
|
||||
}
|
||||
|
||||
let online = dashboard.view.is_some();
|
||||
let copy = ui.add_enabled(online, egui::Button::new("Copy summary"));
|
||||
if copy.clicked() {
|
||||
if let Some(view) = &dashboard.view {
|
||||
ctx.copy_text(view.summary_markdown.clone());
|
||||
}
|
||||
dashboard.flash("Summary copied", now);
|
||||
}
|
||||
let export = ui.add_enabled(online, egui::Button::new("Export JSON"));
|
||||
if export.clicked() {
|
||||
let note = net::download("/api/export").map_or_else(
|
||||
|error| format!("Export failed: {error}"),
|
||||
|()| "Export started".to_owned(),
|
||||
);
|
||||
dashboard.flash(note, now);
|
||||
}
|
||||
let zeroing = dashboard
|
||||
.pending
|
||||
.as_ref()
|
||||
.is_some_and(|(ask, _)| *ask == Ask::Zero);
|
||||
let zero = ui.add_enabled(online && !zeroing, egui::Button::new("Zero stats"));
|
||||
if zero.clicked() {
|
||||
dashboard.asking_zero = true;
|
||||
}
|
||||
|
||||
// A fixed-size slot, so that messages come and go without moving the controls.
|
||||
ui.allocate_ui_with_layout(
|
||||
egui::vec2(theme::space::TOOLBAR_NOTE_WIDTH, theme::layout::TOOLBAR_HEIGHT),
|
||||
egui::Layout::left_to_right(egui::Align::Center),
|
||||
|ui| {
|
||||
if dashboard
|
||||
.pending
|
||||
.as_ref()
|
||||
.is_some_and(|(ask, _)| *ask == Ask::Zero);
|
||||
let zero = ui.add_enabled(online && !zeroing, egui::Button::new("Zero stats"));
|
||||
if zero.clicked() {
|
||||
dashboard.asking_zero = true;
|
||||
.is_some_and(|(ask, _)| *ask == Ask::View)
|
||||
{
|
||||
ui.spinner();
|
||||
ui.add(egui::Label::new(theme::small(ui, "Updating")).truncate());
|
||||
} else if let Some((note, _)) = &dashboard.note {
|
||||
ui.add(egui::Label::new(theme::small(ui, note.clone())).truncate());
|
||||
}
|
||||
|
||||
// A fixed-size slot, so that messages come and go without moving the controls.
|
||||
ui.add_space(8.0);
|
||||
ui.allocate_ui_with_layout(
|
||||
egui::vec2(120.0, 20.0),
|
||||
egui::Layout::left_to_right(egui::Align::Center),
|
||||
|ui| {
|
||||
if dashboard
|
||||
.pending
|
||||
.as_ref()
|
||||
.is_some_and(|(ask, _)| *ask == Ask::View)
|
||||
{
|
||||
ui.spinner();
|
||||
ui.label(egui::RichText::new("Updating").small());
|
||||
} else if let Some((note, _)) = &dashboard.note {
|
||||
ui.add(egui::Label::new(egui::RichText::new(note).small()).truncate());
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Ask before zeroing: it can't be undone.
|
||||
fn zero_question(dashboard: &mut Dashboard, ctx: &egui::Context) {
|
||||
let modal = egui::Modal::new(egui::Id::unique("zero-stats-question")).show(ctx, |ui| {
|
||||
ui.set_max_width(360.0);
|
||||
ui.label(egui::RichText::new("Zero sccache's stats?").strong());
|
||||
ui.add(egui::Label::new(
|
||||
ui.add(egui::Label::new(theme::strong("Zero sccache's stats?")).wrap());
|
||||
ui.add_space(theme::space::ITEM);
|
||||
ui.add(egui::Label::new(theme::body(
|
||||
"The counters go back to zero. The saved history stays, so the charts keep their \
|
||||
older data. This can't be undone.",
|
||||
).wrap());
|
||||
))
|
||||
.wrap());
|
||||
ui.add_space(theme::space::PANEL_GAP);
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Zero stats").clicked() {
|
||||
Some(true)
|
||||
@@ -368,7 +438,7 @@ fn zero_question(dashboard: &mut Dashboard, ctx: &egui::Context) {
|
||||
|
||||
/// What the page says while no view has arrived yet.
|
||||
fn waiting(ui: &mut egui::Ui, error: Option<&str>, refresh_secs: u64) {
|
||||
let [_, _, bad] = style::marks(ui.visuals().dark_mode);
|
||||
let p = theme::ui(ui);
|
||||
let retry = if refresh_secs > 0 {
|
||||
format!("Trying again every {refresh_secs} seconds.")
|
||||
} else {
|
||||
@@ -380,86 +450,213 @@ fn waiting(ui: &mut egui::Ui, error: Option<&str>, refresh_secs: u64) {
|
||||
format!(
|
||||
"{error}.\n\nCheck that sccache-dash is running on this machine. {retry}"
|
||||
),
|
||||
bad,
|
||||
p.bad,
|
||||
),
|
||||
None => (
|
||||
"Waiting for the first figures".to_owned(),
|
||||
"Asking the server for your cache numbers.".to_owned(),
|
||||
ui.visuals().text_color(),
|
||||
p.text,
|
||||
),
|
||||
};
|
||||
// The same height the headline and cards take, so the page doesn't jump when they arrive.
|
||||
ui.allocate_ui_with_layout(
|
||||
egui::vec2(ui.available_rect_before_wrap().width(), 250.0),
|
||||
egui::Layout::centered_and_justified(egui::Direction::TopDown),
|
||||
|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.label(egui::RichText::new(heading).size(20.0).color(color));
|
||||
ui.add(egui::Label::new(body).wrap());
|
||||
});
|
||||
},
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let height = theme::layout::HEADLINE_HEIGHT + theme::space::PANEL_GAP + theme::layout::CARD_HEIGHT * 2.0;
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, height), egui::Sense::hover());
|
||||
let mut place = ui.new_child(
|
||||
egui::UiBuilder::new()
|
||||
.max_rect(rect)
|
||||
.layout(egui::Layout::centered_and_justified(egui::Direction::TopDown)),
|
||||
);
|
||||
place.vertical(|ui| {
|
||||
ui.add(egui::Label::new(theme::strong(heading).color(color)).wrap());
|
||||
ui.add(egui::Label::new(theme::small(ui, body)).wrap());
|
||||
});
|
||||
}
|
||||
|
||||
/// The whole page below the controls.
|
||||
/// A notice that the server can't be reached, shown over the page rather than
|
||||
/// in it, so what is already on screen keeps its place and height.
|
||||
fn lost_contact(ctx: &egui::Context, error: &str, from: i64, page_width: f32) {
|
||||
let [_, _, bad] = style::marks(ctx.theme() == egui::Theme::Dark);
|
||||
let p = theme::ctx(ctx);
|
||||
let when = fmt::moment_text(from + fmt::local_offset());
|
||||
egui::Area::new(egui::Id::unique("lost-contact"))
|
||||
.anchor(egui::Align2::RIGHT_TOP, egui::vec2(-8.0, 52.0))
|
||||
.anchor(
|
||||
egui::Align2::RIGHT_TOP,
|
||||
egui::vec2(-theme::space::PAGE_MARGIN, theme::layout::TOOLBAR_HEIGHT + 2.0 * theme::space::PAGE_MARGIN),
|
||||
)
|
||||
.order(egui::Order::Foreground)
|
||||
.show(ctx, |ui| {
|
||||
let width = (page_width - 16.0).min(440.0);
|
||||
let width = (page_width - 2.0 * theme::space::PAGE_MARGIN).min(440.0);
|
||||
egui::Frame::NONE
|
||||
.fill(bad.gamma_multiply(0.25))
|
||||
.stroke(egui::Stroke::new(1.0, bad))
|
||||
.corner_radius(6.0)
|
||||
.inner_margin(8.0)
|
||||
.fill(p.panel)
|
||||
.stroke(egui::Stroke::new(1.0, p.bad))
|
||||
.corner_radius(theme::space::PANEL_RADIUS)
|
||||
.inner_margin(theme::space::PANEL_PADDING)
|
||||
.show(ui, |ui| {
|
||||
ui.set_max_width(width);
|
||||
ui.set_max_width(width - 2.0 * theme::space::PANEL_PADDING);
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
egui::RichText::new(format!(
|
||||
theme::strong(format!(
|
||||
"Can't reach the server: {error}. These figures are from {when}."
|
||||
))
|
||||
.strong(),
|
||||
)
|
||||
.wrap(),
|
||||
.color(p.bad),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// The rectangles of one row of the grid: each entry of `spans` is how many
|
||||
/// columns that panel takes; all are at least `height` tall.
|
||||
fn row(ui: &egui::Ui, height: f32, spans: &[usize]) -> Vec<egui::Rect> {
|
||||
style::cells(ui, height, spans)
|
||||
}
|
||||
|
||||
/// Close the row: the cursor moves below the tallest of its panels.
|
||||
fn close_row(ui: &mut egui::Ui, taken: &[egui::Rect]) {
|
||||
style::end_row(ui, taken);
|
||||
}
|
||||
|
||||
/// One panel across the whole page, as tall as what it holds.
|
||||
fn single(ui: &mut egui::Ui, title: &str, body: impl FnOnce(&mut egui::Ui)) {
|
||||
let [rect] = row(ui, 0.0, &[1]).try_into().expect("one panel");
|
||||
let (_, taken) = style::panel(ui, rect, title, body);
|
||||
close_row(ui, &[taken]);
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
/// How tall a panel with `histograms` build-time histograms in it 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
|
||||
}
|
||||
|
||||
fn problems_height(view: &View) -> f32 {
|
||||
use theme::layout as l;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 dark = ui.visuals().dark_mode;
|
||||
let [_, _, bad] = style::marks(dark);
|
||||
let p = theme::ui(ui);
|
||||
use theme::layout as l;
|
||||
if let Some(error) = &view.server.error {
|
||||
style::banner(ui, format!("sccache is not working: {error}"), bad);
|
||||
style::banner(ui, egui::RichText::new(format!("sccache is not working: {error}")), p.bad);
|
||||
ui.add_space(theme::space::PANEL_GAP);
|
||||
}
|
||||
let columns = theme::columns(ui.available_rect_before_wrap().width());
|
||||
|
||||
headline(ui, view, asked);
|
||||
|
||||
// Six cards in one row on a wide screen; three in the two-column layout; two on a phone.
|
||||
let per_row = match columns {
|
||||
3 => 6,
|
||||
2 => 3,
|
||||
_ => 2,
|
||||
};
|
||||
cards::row(ui, view, per_row);
|
||||
|
||||
match columns {
|
||||
3 => {
|
||||
let [a, b, c] = row(ui, triptych_height(view), &[1, 1, 1]).try_into().expect("three 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 (_, 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]);
|
||||
}
|
||||
2 => {
|
||||
let height = triptych_height(view);
|
||||
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));
|
||||
close_row(ui, &[a, b]);
|
||||
let height = l::TRIPTYCH_HEIGHT.min(360.0).max(problems_height(view)).max(speed_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));
|
||||
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));
|
||||
close_row(ui, &[a]);
|
||||
}
|
||||
_ => {
|
||||
// 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, "By language", |ui| where_went::languages(ui, view));
|
||||
single(ui, "Over time", |ui| overtime::section(ui, view, hidden_languages));
|
||||
single(ui, "Speed", |ui| speed::section(ui, view));
|
||||
}
|
||||
}
|
||||
|
||||
extras(ui, view);
|
||||
|
||||
let open = ui
|
||||
.ctx()
|
||||
.data_mut(|data| data.get_temp::<bool>(egui::Id::unique("raw-counters-open")))
|
||||
.unwrap_or(true);
|
||||
let full = style::span_width(ui, columns, columns);
|
||||
let [rect] = row(ui, raw::height(view, full, open), &[columns]).try_into().expect("one panel");
|
||||
let taken = raw::section(ui, view, rect);
|
||||
close_row(ui, &[taken]);
|
||||
ui.add_space(theme::space::PAGE_MARGIN);
|
||||
}
|
||||
|
||||
/// The "Extras" panels, side by side where there are several.
|
||||
fn extras(ui: &mut egui::Ui, view: &View) {
|
||||
if view.extras.is_empty() {
|
||||
return;
|
||||
}
|
||||
let columns = theme::columns(ui.available_rect_before_wrap().width());
|
||||
let per_row = columns.min(view.extras.len()).max(1);
|
||||
for line in view.extras.chunks(per_row) {
|
||||
let spans: Vec<usize> = line.iter().map(|_| 1).collect();
|
||||
let height = theme::space::ROW * (line.iter().map(|extra| extra.rows.len()).max().unwrap_or(0) + 1) as f32
|
||||
+ theme::space::PANEL_PADDING * 2.0 + theme::space::UNDER_TITLE + 12.0;
|
||||
let cells = style::cells(ui, height, &spans);
|
||||
let mut taken = Vec::with_capacity(cells.len());
|
||||
for (rect, extra) in cells.iter().zip(line) {
|
||||
let title: &str = Box::leak(extra.title.clone().into_boxed_str());
|
||||
let (_, rect) = style::panel(ui, *rect, title, |ui| extras::section(ui, view));
|
||||
taken.push(rect);
|
||||
}
|
||||
close_row(ui, &taken);
|
||||
}
|
||||
headline(ui, view, asked, dark);
|
||||
ui.add_space(10.0);
|
||||
cards::row(ui, view, dark);
|
||||
problems::section(ui, view, dark);
|
||||
where_went::section(ui, view, dark);
|
||||
overtime::section(ui, view, hidden_languages, dark);
|
||||
speed::section(ui, view);
|
||||
extras::section(ui, view);
|
||||
raw::section(ui, view);
|
||||
ui.add_space(12.0);
|
||||
}
|
||||
|
||||
/// One of the three big figures.
|
||||
struct Figure<'a> {
|
||||
value: String,
|
||||
/// How big the figure is written: 30 for numbers, less for words.
|
||||
/// The size of the figure's text: a number, or words at the card size.
|
||||
size: f32,
|
||||
color: egui::Color32,
|
||||
caption: String,
|
||||
/// Smaller print under the figure.
|
||||
small: String,
|
||||
/// A second line of smaller print, kept so the block's height never changes.
|
||||
/// A second line of smaller print; the block keeps its height when it is empty.
|
||||
small2: String,
|
||||
/// A trend line and the value it is drawn against.
|
||||
trend: Option<(&'a [Option<f64>], f64)>,
|
||||
@@ -469,25 +666,27 @@ struct Figure<'a> {
|
||||
impl Figure<'_> {
|
||||
/// Draw in a column `width` wide and always the same height.
|
||||
fn draw(self, ui: &mut egui::Ui, width: f32) {
|
||||
let gap = ui.spacing().item_spacing.y;
|
||||
let gap = theme::space::LINE;
|
||||
let block = ui.allocate_ui_with_layout(
|
||||
egui::vec2(width, FIGURE_HEIGHT),
|
||||
egui::vec2(width, theme::layout::FIGURE_HEIGHT),
|
||||
egui::Layout::top_down(egui::Align::Min),
|
||||
|ui| {
|
||||
ui.set_width(width);
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
egui::RichText::new(&self.value).size(self.size).color(self.color),
|
||||
)
|
||||
.truncate(),
|
||||
);
|
||||
ui.add(egui::Label::new(egui::RichText::new(&self.caption).small()).truncate());
|
||||
ui.spacing_mut().item_spacing = egui::vec2(gap, gap);
|
||||
let value = egui::Label::new(
|
||||
egui::RichText::new(&self.value)
|
||||
.font(theme::number_font(self.size))
|
||||
.color(self.color),
|
||||
)
|
||||
.truncate();
|
||||
ui.add(value.sense(egui::Sense::hover())).on_hover_text(&self.value);
|
||||
ui.add(egui::Label::new(theme::small(ui, self.caption.clone())).truncate());
|
||||
match self.trend {
|
||||
Some((values, top)) => style::sparkline(ui, TREND_HEIGHT, values, top, self.color),
|
||||
None => ui.add_space(TREND_HEIGHT + gap),
|
||||
Some((values, top)) => style::sparkline(ui, theme::drawing::SPARKLINE, values, top, self.color),
|
||||
None => ui.add_space(theme::drawing::SPARKLINE + gap),
|
||||
}
|
||||
ui.add(egui::Label::new(egui::RichText::new(&self.small).small().weak()).truncate());
|
||||
ui.add(egui::Label::new(egui::RichText::new(&self.small2).small().weak()).truncate());
|
||||
ui.add(egui::Label::new(theme::small(ui, self.small.clone())).truncate());
|
||||
ui.add(egui::Label::new(theme::small(ui, self.small2.clone())).truncate());
|
||||
},
|
||||
);
|
||||
if let Some(hover) = self.hover {
|
||||
@@ -496,14 +695,11 @@ impl Figure<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
const TREND_HEIGHT: f32 = 22.0;
|
||||
const FIGURE_HEIGHT: f32 = 120.0;
|
||||
|
||||
/// The big numbers, what they mean, and where the cache lives.
|
||||
fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
|
||||
fn headline(ui: &mut egui::Ui, view: &View, asked: Range) {
|
||||
let range = view.range.unwrap_or(asked);
|
||||
let totals = &view.totals;
|
||||
let text_color = ui.visuals().text_color();
|
||||
let p = theme::ui(ui);
|
||||
|
||||
let rates: Vec<Option<f64>> = view
|
||||
.buckets
|
||||
@@ -520,135 +716,166 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
|
||||
let problems = view.problems.len();
|
||||
let worst = view.problems.first();
|
||||
let problem_color = match worst.map(|problem| problem.severity) {
|
||||
Some(sccache_dash_api::Severity::Error) => style::marks(dark)[2],
|
||||
Some(sccache_dash_api::Severity::Warning) => style::marks(dark)[1],
|
||||
None => text_color,
|
||||
Some(sccache_dash_api::Severity::Error) => p.bad,
|
||||
Some(sccache_dash_api::Severity::Warning) => p.warn,
|
||||
None => p.text,
|
||||
};
|
||||
|
||||
ui.label(egui::RichText::new(range.label().to_uppercase()).strong());
|
||||
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let spacing = ui.spacing().item_spacing.x;
|
||||
// Side by side where there is room; one under another on a phone.
|
||||
let columns = if width >= 600.0 { 3.0 } else { 1.0 };
|
||||
let column = (width - spacing * (columns - 1.0)) / columns;
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
Figure {
|
||||
value: fmt::percent(totals.hit_rate()),
|
||||
size: 30.0,
|
||||
color: style::hit_rate_color(totals.hit_rate(), dark),
|
||||
caption: "from cache".into(),
|
||||
small: format!("{} of all compiler calls", fmt::percent(totals.hit_rate_of_all())),
|
||||
trend: Some((&rates, 1.0)),
|
||||
hover: None,
|
||||
small2: String::new(),
|
||||
}
|
||||
.draw(ui, column);
|
||||
// A saving is never written in milliseconds; and when no language's build time is
|
||||
// known yet, the figure says so instead of showing nothing.
|
||||
let seconds = view.time_saved.seconds;
|
||||
let left_out = view.time_saved.hits_left_out;
|
||||
let left_out_line = if left_out > 0 {
|
||||
format!("{} hits left out of this figure", fmt::count(left_out))
|
||||
} else {
|
||||
"every hit counted".to_owned()
|
||||
};
|
||||
let interval = view
|
||||
.time_saved
|
||||
.interval_90
|
||||
.map(|(low, high)| format!("{} – {} (90% range)", fmt::duration(low), fmt::duration(high)));
|
||||
let (value, size, small, small2) = if seconds >= 1.0 {
|
||||
(format!("~{}", fmt::duration(seconds)), 30.0, interval.unwrap_or_default(), left_out_line)
|
||||
} else if seconds > 0.0 {
|
||||
("~under 1 s".to_owned(), 30.0, interval.unwrap_or_default(), left_out_line)
|
||||
} else if left_out > 0 {
|
||||
(
|
||||
"not enough data yet".to_owned(),
|
||||
22.0,
|
||||
String::new(),
|
||||
format!(
|
||||
"{} hits not counted: no build time known yet for their language",
|
||||
fmt::count(left_out)
|
||||
),
|
||||
)
|
||||
} else {
|
||||
("nothing saved yet".to_owned(), 22.0, String::new(), String::new())
|
||||
};
|
||||
Figure {
|
||||
value,
|
||||
size,
|
||||
color: text_color,
|
||||
caption: "saved (rough)".into(),
|
||||
small,
|
||||
small2,
|
||||
trend: Some((&saved, saved_top)),
|
||||
hover: Some(view.time_saved.note.clone()),
|
||||
}
|
||||
.draw(ui, column);
|
||||
Figure {
|
||||
value: if problems == 1 {
|
||||
"1 problem".into()
|
||||
} else if problems == 0 {
|
||||
"No problems".into()
|
||||
} else {
|
||||
format!("{} problems", fmt::count(problems as u64))
|
||||
},
|
||||
size: 30.0,
|
||||
color: problem_color,
|
||||
caption: worst
|
||||
.map(|problem| problem.title.clone())
|
||||
.unwrap_or_else(|| "Nothing needs attention".into()),
|
||||
small: String::new(),
|
||||
small2: String::new(),
|
||||
trend: None,
|
||||
hover: None,
|
||||
}
|
||||
.draw(ui, column);
|
||||
});
|
||||
|
||||
// Timeouts, cache errors and forced recaches are inside the built count, as sccache counts them.
|
||||
let built = totals.misses;
|
||||
ui.add(egui::Label::new(format!(
|
||||
let counts = format!(
|
||||
"{} compiles · {} from cache · {} built",
|
||||
fmt::count(totals.requests),
|
||||
fmt::count(totals.hits),
|
||||
fmt::count(built)
|
||||
)).wrap());
|
||||
|
||||
let server = &view.server;
|
||||
let mut parts = Vec::new();
|
||||
if let Some(location) = &server.cache_location {
|
||||
// sccache words it `Local disk: "/home/me/.cache/sccache"`; the kind is enough here.
|
||||
let kind = location.split(':').next().unwrap_or(location);
|
||||
let kind = if kind.eq_ignore_ascii_case("LOCAL DISK") {
|
||||
"local disk".to_owned()
|
||||
} else {
|
||||
kind.to_owned()
|
||||
};
|
||||
parts.push(kind);
|
||||
}
|
||||
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
|
||||
parts.push(format!("{} of {}", fmt::bytes(size), fmt::bytes(max)));
|
||||
}
|
||||
if let Some(version) = server.version.as_deref().or(server.client_version.as_deref()) {
|
||||
parts.push(format!("sccache {version}"));
|
||||
}
|
||||
parts.push(
|
||||
match server.status {
|
||||
sccache_dash_api::Status::Running => "running",
|
||||
sccache_dash_api::Status::Idle => "idle",
|
||||
sccache_dash_api::Status::NotRunning => "not running",
|
||||
}
|
||||
.to_owned(),
|
||||
fmt::count(totals.misses)
|
||||
);
|
||||
let line = format!("Cache: {}", parts.join(" · "));
|
||||
let response = ui.add(egui::Label::new(line).wrap());
|
||||
if let Some(location) = &server.cache_location {
|
||||
response.on_hover_text(location.clone());
|
||||
}
|
||||
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
|
||||
let full = if max > 0 { size as f64 / max as f64 } else { 0.0 };
|
||||
let color = if full >= 0.95 { style::marks(dark)[2] } else { style::CACHE };
|
||||
style::meter(ui, 6.0, full, color);
|
||||
}
|
||||
let title_text = theme::title(ui, range.label()).text().to_owned();
|
||||
let counts_text = counts.clone();
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let rect = egui::Rect::from_min_size(
|
||||
ui.cursor().min,
|
||||
egui::vec2(width, theme::layout::HEADLINE_HEIGHT),
|
||||
);
|
||||
let (_, taken) = style::panel_titled(
|
||||
ui,
|
||||
rect,
|
||||
|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(egui::Label::new(theme::title(ui, title_text)).truncate());
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.add(egui::Label::new(theme::small(ui, counts_text)).truncate());
|
||||
});
|
||||
});
|
||||
},
|
||||
|ui| {
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let spacing = theme::space::PANEL_GAP;
|
||||
// Side by side where there is room; one under another on a phone.
|
||||
let side_by_side = width >= 600.0;
|
||||
let columns = if side_by_side { 3.0 } else { 1.0 };
|
||||
let column = (width - spacing * (columns - 1.0)) / columns;
|
||||
let draw = |ui: &mut egui::Ui, figure: Figure<'_>| figure.draw(ui, column);
|
||||
// Timeouts, cache errors and forced recaches are inside the built count, as sccache counts them.
|
||||
let first = Figure {
|
||||
value: fmt::percent(totals.hit_rate()),
|
||||
size: theme::px::HEADLINE,
|
||||
color: theme::hit_rate_color(totals.hit_rate(), p),
|
||||
caption: "from cache".into(),
|
||||
small: format!("{} of all compiler calls", fmt::percent(totals.hit_rate_of_all())),
|
||||
trend: Some((&rates, 1.0)),
|
||||
hover: None,
|
||||
small2: String::new(),
|
||||
};
|
||||
// A saving is never written in milliseconds; and when no language's build time is
|
||||
// known yet, the figure says so instead of showing nothing.
|
||||
let seconds = view.time_saved.seconds;
|
||||
let left_out = view.time_saved.hits_left_out;
|
||||
let left_out_line = if left_out > 0 {
|
||||
format!("{} hits left out of this figure", fmt::count(left_out))
|
||||
} else {
|
||||
"every hit counted".to_owned()
|
||||
};
|
||||
let interval = view
|
||||
.time_saved
|
||||
.interval_90
|
||||
.map(|(low, high)| format!("{} – {} (90% range)", fmt::duration(low), fmt::duration(high)));
|
||||
let (value, size, small, small2) = if seconds >= 1.0 {
|
||||
(format!("~{}", fmt::duration(seconds)), theme::px::HEADLINE, interval.unwrap_or_default(), left_out_line)
|
||||
} else if seconds > 0.0 {
|
||||
("~under 1 s".to_owned(), theme::px::HEADLINE, interval.unwrap_or_default(), left_out_line)
|
||||
} else if left_out > 0 {
|
||||
(
|
||||
"not enough data yet".to_owned(),
|
||||
theme::px::CARD_NUMBER,
|
||||
String::new(),
|
||||
format!(
|
||||
"{} hits not counted: no build time known yet for their language",
|
||||
fmt::count(left_out)
|
||||
),
|
||||
)
|
||||
} else {
|
||||
("nothing saved yet".to_owned(), theme::px::CARD_NUMBER, String::new(), String::new())
|
||||
};
|
||||
let second = Figure {
|
||||
value,
|
||||
size,
|
||||
color: p.text,
|
||||
caption: "saved (rough)".into(),
|
||||
small,
|
||||
small2,
|
||||
trend: Some((&saved, saved_top)),
|
||||
hover: Some(view.time_saved.note.clone()),
|
||||
};
|
||||
let third = Figure {
|
||||
value: if problems == 1 {
|
||||
"1 problem".into()
|
||||
} else if problems == 0 {
|
||||
"No problems".into()
|
||||
} else {
|
||||
format!("{} problems", fmt::count(problems as u64))
|
||||
},
|
||||
size: theme::px::CARD_NUMBER,
|
||||
color: problem_color,
|
||||
caption: worst
|
||||
.map(|problem| problem.title.clone())
|
||||
.unwrap_or_else(|| "Nothing needs attention".into()),
|
||||
small: String::new(),
|
||||
small2: String::new(),
|
||||
trend: None,
|
||||
hover: None,
|
||||
};
|
||||
if side_by_side {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = spacing;
|
||||
draw(ui, first);
|
||||
draw(ui, second);
|
||||
draw(ui, third);
|
||||
});
|
||||
} else {
|
||||
draw(ui, first);
|
||||
draw(ui, second);
|
||||
draw(ui, third);
|
||||
}
|
||||
|
||||
style::rule(ui);
|
||||
ui.add_space(theme::space::PANEL_GAP);
|
||||
|
||||
let server = &view.server;
|
||||
let mut parts = Vec::new();
|
||||
if let Some(location) = &server.cache_location {
|
||||
// sccache words it `Local disk: "/home/me/.cache/sccache"`; the kind is enough here.
|
||||
let kind = location.split(':').next().unwrap_or(location);
|
||||
let kind = if kind.eq_ignore_ascii_case("LOCAL DISK") {
|
||||
"local disk".to_owned()
|
||||
} else {
|
||||
kind.to_owned()
|
||||
};
|
||||
parts.push(kind);
|
||||
}
|
||||
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
|
||||
parts.push(format!("{} of {}", fmt::bytes(size), fmt::bytes(max)));
|
||||
}
|
||||
if let Some(version) = server.version.as_deref().or(server.client_version.as_deref()) {
|
||||
parts.push(format!("sccache {version}"));
|
||||
}
|
||||
parts.push(
|
||||
match server.status {
|
||||
sccache_dash_api::Status::Running => "running",
|
||||
sccache_dash_api::Status::Idle => "idle",
|
||||
sccache_dash_api::Status::NotRunning => "not running",
|
||||
}
|
||||
.to_owned(),
|
||||
);
|
||||
let line = format!("Cache: {}", parts.join(" · "));
|
||||
let response = ui.add(egui::Label::new(theme::small(ui, line)).wrap());
|
||||
if let Some(location) = &server.cache_location {
|
||||
response.on_hover_text(location.clone());
|
||||
}
|
||||
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
|
||||
let full = if max > 0 { size as f64 / max as f64 } else { 0.0 };
|
||||
let color = if full >= theme::state::CACHE_FULL { p.bad } else { p.from_cache };
|
||||
style::meter(ui, theme::drawing::USAGE_BAR, full, color);
|
||||
}
|
||||
},
|
||||
);
|
||||
ui.allocate_rect(taken, egui::Sense::hover());
|
||||
ui.add_space(theme::space::PANEL_GAP);
|
||||
}
|
||||
+44
-66
@@ -1,20 +1,20 @@
|
||||
//! The six compact cards under the headline: all the same size, tops in a line.
|
||||
//! The six stat cards under the headline: all the same size, tops in a line.
|
||||
|
||||
use eframe::egui::{self, Color32, Pos2, Rect, RichText};
|
||||
|
||||
use eframe::egui::{self, Color32, RichText, Sense, StrokeKind, Ui};
|
||||
use sccache_dash_api::{Range, View};
|
||||
|
||||
use crate::fmt;
|
||||
use crate::style;
|
||||
use crate::theme;
|
||||
|
||||
/// Every card is exactly this tall and as wide as its share of the row.
|
||||
const HEIGHT: f32 = 78.0;
|
||||
const MARGIN: f32 = 8.0;
|
||||
|
||||
pub fn row(ui: &mut Ui, view: &View, dark: bool) {
|
||||
/// The cards in `per_row` per row: six in one row on a wide screen, three in
|
||||
/// the two-column layout, two on a phone.
|
||||
pub fn row(ui: &mut egui::Ui, view: &View, per_row: usize) {
|
||||
let totals = &view.totals;
|
||||
let previous = view.previous.as_ref();
|
||||
let range = view.range.unwrap_or(Range::Day);
|
||||
let [good, _, bad] = style::marks(dark);
|
||||
let p = theme::ui(ui);
|
||||
let requests = totals.requests;
|
||||
let cache_errors = totals.errors();
|
||||
let cards = [
|
||||
@@ -37,7 +37,7 @@ pub fn row(ui: &mut Ui, view: &View, dark: bool) {
|
||||
Card {
|
||||
title: "Timeouts",
|
||||
count: totals.timeouts,
|
||||
color: (totals.timeouts > 0).then_some(bad),
|
||||
color: (totals.timeouts > 0).then_some(p.bad),
|
||||
detail: String::new(),
|
||||
previous: previous.map(|previous| previous.timeouts),
|
||||
good_when_up: false,
|
||||
@@ -45,7 +45,7 @@ pub fn row(ui: &mut Ui, view: &View, dark: bool) {
|
||||
Card {
|
||||
title: "Cache errors",
|
||||
count: cache_errors,
|
||||
color: (cache_errors > 0).then_some(bad),
|
||||
color: (cache_errors > 0).then_some(p.bad),
|
||||
detail: format!(
|
||||
"{} read · {} write · {} other",
|
||||
fmt::count(totals.read_errors),
|
||||
@@ -73,16 +73,29 @@ pub fn row(ui: &mut Ui, view: &View, dark: bool) {
|
||||
},
|
||||
];
|
||||
|
||||
let per_row = per_row.max(1);
|
||||
let left = ui.cursor().left();
|
||||
let mut top = ui.cursor().top();
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let spacing = ui.spacing().item_spacing.x;
|
||||
// Three across where there is room, two on a phone.
|
||||
let per_row = if width >= 700.0 { 3.0 } else { 2.0 };
|
||||
let card_width = (width - spacing * (per_row - 1.0)) / per_row;
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for card in cards {
|
||||
card.draw(ui, card_width, range, [good, bad]);
|
||||
let card_width = (width - theme::space::PANEL_GAP * (per_row - 1) as f32) / per_row as f32;
|
||||
for line in cards.chunks(per_row) {
|
||||
let mut x = left;
|
||||
for card in line {
|
||||
let change = change(card.count, card.previous, range, card.good_when_up, p);
|
||||
style::card(
|
||||
ui,
|
||||
Rect::from_min_size(Pos2::new(x, top), egui::vec2(card_width, theme::layout::CARD_HEIGHT)),
|
||||
card.title,
|
||||
&fmt::count(card.count),
|
||||
&card.detail,
|
||||
change,
|
||||
card.color.unwrap_or(p.text),
|
||||
);
|
||||
x += card_width + theme::space::PANEL_GAP;
|
||||
}
|
||||
});
|
||||
top += theme::layout::CARD_HEIGHT + theme::space::PANEL_GAP;
|
||||
}
|
||||
ui.add_space(top - ui.cursor().top());
|
||||
}
|
||||
|
||||
struct Card {
|
||||
@@ -98,61 +111,26 @@ struct Card {
|
||||
good_when_up: bool,
|
||||
}
|
||||
|
||||
impl Card {
|
||||
/// A box of exactly `width` by `HEIGHT`, so every card lines up whatever it says.
|
||||
fn draw(self, ui: &mut Ui, width: f32, range: Range, [good, bad]: [Color32; 2]) {
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, HEIGHT), Sense::hover());
|
||||
let visuals = ui.visuals();
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
6.0,
|
||||
visuals.faint_bg_color,
|
||||
visuals.widgets.noninteractive.bg_stroke,
|
||||
StrokeKind::Inside,
|
||||
);
|
||||
let mut card = ui.new_child(
|
||||
egui::UiBuilder::new()
|
||||
.max_rect(rect.shrink(MARGIN))
|
||||
.layout(egui::Layout::top_down(egui::Align::Min)),
|
||||
);
|
||||
card.add(egui::Label::new(RichText::new(self.title).small()).truncate());
|
||||
let color = self.color.unwrap_or_else(|| card.visuals().text_color());
|
||||
card.add(
|
||||
egui::Label::new(RichText::new(fmt::count(self.count)).size(20.0).color(color)).truncate(),
|
||||
);
|
||||
let detail = card.add(
|
||||
egui::Label::new(RichText::new(&self.detail).small().weak()).truncate(),
|
||||
);
|
||||
if !self.detail.is_empty() {
|
||||
detail.on_hover_text(self.detail.clone());
|
||||
}
|
||||
let (change, color) = change(self.count, self.previous, range, self.good_when_up, [good, bad]);
|
||||
card.add(egui::Label::new(RichText::new(change).small().color(color)).truncate());
|
||||
}
|
||||
}
|
||||
|
||||
/// How a count compares with the period before, and the colour that change deserves.
|
||||
fn change(
|
||||
count: u64,
|
||||
previous: Option<u64>,
|
||||
range: Range,
|
||||
good_when_up: bool,
|
||||
[good, bad]: [Color32; 2],
|
||||
) -> (String, Color32) {
|
||||
let gray = Color32::GRAY;
|
||||
fn change(count: u64, previous: Option<u64>, range: Range, good_when_up: bool, p: &theme::Palette) -> RichText {
|
||||
let Some(previous) = previous else {
|
||||
return (String::new(), gray);
|
||||
return RichText::new("").font(egui::FontId::proportional(theme::px::SMALL));
|
||||
};
|
||||
if previous == 0 {
|
||||
return (if count == 0 { String::new() } else { "was 0 before".into() }, gray);
|
||||
return small_plain(p, if count == 0 { String::new() } else { "was 0 before".into() });
|
||||
}
|
||||
let change = (count as f64 - previous as f64) / previous as f64 * 100.0;
|
||||
if change.abs() < 0.5 {
|
||||
return ("no change".into(), gray);
|
||||
return small_plain(p, "no change".into());
|
||||
}
|
||||
let better = (change > 0.0) == good_when_up;
|
||||
(
|
||||
format!("{change:+.0}% vs {}", fmt::previous_label(range)),
|
||||
if better { good } else { bad },
|
||||
)
|
||||
RichText::new(format!("{change:+.0}% vs {}", fmt::previous_label(range)))
|
||||
.font(egui::FontId::proportional(theme::px::SMALL))
|
||||
.color(if better { p.good } else { p.bad })
|
||||
}
|
||||
|
||||
fn small_plain(p: &theme::Palette, text: String) -> RichText {
|
||||
RichText::new(text)
|
||||
.font(egui::FontId::proportional(theme::px::SMALL))
|
||||
.color(p.muted)
|
||||
}
|
||||
+16
-23
@@ -1,29 +1,22 @@
|
||||
//! Extras: the tables sccache only fills in for some setups.
|
||||
//! Extras: the tables sccache only fills in for some setups, one panel each.
|
||||
|
||||
use eframe::egui::{RichText, Ui};
|
||||
use sccache_dash_api::View;
|
||||
|
||||
use crate::style;
|
||||
use crate::style::{self, Cell};
|
||||
use crate::theme;
|
||||
|
||||
pub fn section(ui: &mut Ui, view: &View) {
|
||||
if view.extras.is_empty() {
|
||||
return;
|
||||
pub fn section(ui: &mut eframe::egui::Ui, view: &View) {
|
||||
for extra in &view.extras {
|
||||
let rows: Vec<Vec<Cell>> = extra
|
||||
.rows
|
||||
.iter()
|
||||
.map(|(label, value)| {
|
||||
vec![
|
||||
Cell::Text(theme::strong(label.clone())),
|
||||
Cell::Text(theme::number(value.clone())),
|
||||
]
|
||||
})
|
||||
.collect();
|
||||
style::table(ui, &[], &rows);
|
||||
}
|
||||
style::section(ui, "extras", "Extras", |ui| {
|
||||
for (index, extra) in view.extras.iter().enumerate() {
|
||||
if index > 0 {
|
||||
ui.add_space(6.0);
|
||||
}
|
||||
ui.label(RichText::new(&extra.title).strong());
|
||||
for (label, value) in &extra.rows {
|
||||
style::table_row(
|
||||
ui,
|
||||
vec![
|
||||
style::text_cell(RichText::new(label.as_str()).strong(), 0.3, false, false),
|
||||
style::text_cell(RichText::new(value.as_str()), f32::INFINITY, false, true),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -24,6 +24,8 @@ mod speed;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod style;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod theme;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod where_went;
|
||||
|
||||
/// The canvas in `index.html` the page is drawn on.
|
||||
|
||||
+83
-77
@@ -1,8 +1,8 @@
|
||||
//! Over time: hit rate and compile volume per bucket, with a language filter.
|
||||
//! Both charts always show the whole selected range; time nothing was recorded
|
||||
//! in is shaded and labelled once.
|
||||
//! in is tinted and labelled once.
|
||||
|
||||
use eframe::egui::{self, Color32, RichText, Stroke, Ui};
|
||||
use eframe::egui::{self, Stroke, Ui};
|
||||
use egui_plot::{
|
||||
Bar, BarChart, CoordinatesFormatter, Corner, GridInput, GridMark, Line, LineStyle, Plot,
|
||||
PlotBounds, PlotPoint, PlotPoints, PlotResponse, PlotUi, Span, VLine,
|
||||
@@ -11,39 +11,44 @@ use sccache_dash_api::{Bucket, Range, View};
|
||||
|
||||
use crate::fmt;
|
||||
use crate::style;
|
||||
|
||||
const CHART_HEIGHT: f32 = 170.0;
|
||||
use crate::theme;
|
||||
|
||||
/// Hits out of the cacheable compiles; `None` when there were none.
|
||||
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>, dark: bool) {
|
||||
style::section(ui, "overtime", "Over time", |ui| {
|
||||
filter(ui, view, hidden);
|
||||
pub fn section(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) {
|
||||
let p = theme::ui(ui);
|
||||
filter(ui, view, hidden);
|
||||
|
||||
let tz = fmt::local_offset() as f64;
|
||||
let step = bucket_step(&view.buckets, view.range);
|
||||
let axes = Axes {
|
||||
window: range_window(view, step),
|
||||
step,
|
||||
tz,
|
||||
dark,
|
||||
};
|
||||
let tz = fmt::local_offset() as f64;
|
||||
let step = bucket_step(&view.buckets, view.range);
|
||||
let axes = Axes {
|
||||
window: range_window(view, step),
|
||||
step,
|
||||
tz,
|
||||
dark: p.dark,
|
||||
};
|
||||
|
||||
ui.label(RichText::new("Hit rate").strong());
|
||||
hit_rate_chart(ui, view, hidden, axes);
|
||||
ui.add_space(theme::space::BETWEEN_PARTS);
|
||||
part_title(ui, "Hit rate");
|
||||
hit_rate_chart(ui, view, hidden, axes);
|
||||
|
||||
ui.add_space(6.0);
|
||||
ui.label(RichText::new("Compiles").strong());
|
||||
volume_chart(ui, view, hidden, axes);
|
||||
});
|
||||
ui.add_space(theme::space::BETWEEN_PARTS);
|
||||
part_title(ui, "Compiles");
|
||||
volume_chart(ui, view, hidden, axes);
|
||||
}
|
||||
|
||||
/// The title of one part of a panel, in the style of a panel title.
|
||||
pub fn part_title(ui: &mut Ui, text: &str) {
|
||||
ui.add(egui::Label::new(theme::title(ui, text)).truncate());
|
||||
}
|
||||
|
||||
/// Checkboxes that narrow both charts to some languages.
|
||||
fn filter(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::space::PANEL_GAP;
|
||||
let mut all = hidden.is_empty();
|
||||
if ui.checkbox(&mut all, "All languages").changed() {
|
||||
*hidden = if all {
|
||||
@@ -67,13 +72,14 @@ fn filter(ui: &mut Ui, view: &View, hidden: &mut Vec<String>) {
|
||||
}
|
||||
});
|
||||
if !hidden.is_empty() {
|
||||
ui.label(
|
||||
RichText::new(
|
||||
"Only the chosen languages are counted. The other outcomes can't be split by \
|
||||
language, so they're left out.",
|
||||
)
|
||||
.small()
|
||||
.weak(),
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
theme::small(
|
||||
ui,
|
||||
"Only the chosen languages are counted. The other outcomes can't be split by \
|
||||
language, so they're left out.",
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -143,23 +149,42 @@ struct Axes {
|
||||
/// A chart with a time axis over the whole range: clock times as ticks and a
|
||||
/// readout of where the pointer is. It can't be zoomed or dragged, so the wheel
|
||||
/// and a finger keep scrolling the page; that also means it can fit its data
|
||||
/// afresh every frame, so new buckets are never cut off.
|
||||
/// afresh every frame, so new buckets are never cut off. A little air either
|
||||
/// side keeps the first and last time label inside the plot.
|
||||
fn time_plot<'a>(
|
||||
name: &'static str,
|
||||
axes: Axes,
|
||||
readout: impl Fn(&PlotPoint) -> String + 'a,
|
||||
) -> Plot<'a> {
|
||||
let (first, last) = (axes.window.0 + axes.tz, axes.window.1 + axes.tz);
|
||||
let tick = fmt::tick_step(last - first);
|
||||
let span = last - first;
|
||||
let air = span * theme::drawing::CHART_SIDE_AIR;
|
||||
let tick = fmt::tick_step(span);
|
||||
let label_font = egui::FontId::proportional(theme::px::SMALL);
|
||||
let label_color = theme::of(axes.dark).muted;
|
||||
let (from, to) = (first, last);
|
||||
Plot::new(name)
|
||||
.height(CHART_HEIGHT)
|
||||
.height(theme::drawing::CHART_HEIGHT)
|
||||
.show_background(false)
|
||||
.grid_color(theme::of(axes.dark).grid)
|
||||
.allow_scroll(false)
|
||||
.allow_drag(false)
|
||||
.allow_zoom(false)
|
||||
.allow_boxed_zoom(false)
|
||||
// Exactly the range, edge to edge, with no air either side.
|
||||
.default_x_bounds(first, last)
|
||||
.x_grid_spacer(move |input: GridInput| ticks(input.bounds.0, input.bounds.1, tick))
|
||||
.custom_x_axes(vec![egui_plot::AxisHints::new_x()
|
||||
.tick_label_font(label_font.clone())
|
||||
.tick_label_color(label_color)])
|
||||
.custom_y_axes(vec![egui_plot::AxisHints::new_y()
|
||||
.tick_label_font(label_font)
|
||||
.tick_label_color(label_color)])
|
||||
// The range and a little air either side, so the edge labels are not cut off.
|
||||
.default_x_bounds(first - air, last + air)
|
||||
.x_grid_spacer(move |input: GridInput| {
|
||||
ticks(input.bounds.0, input.bounds.1, tick)
|
||||
.into_iter()
|
||||
.filter(|mark| mark.value >= from && mark.value <= to)
|
||||
.collect()
|
||||
})
|
||||
.x_axis_formatter(move |mark: GridMark, _range| {
|
||||
fmt::tick_label(mark.value.round() as i64, tick)
|
||||
})
|
||||
@@ -185,23 +210,14 @@ fn ticks(from: f64, to: f64, tick: i64) -> Vec<GridMark> {
|
||||
marks
|
||||
}
|
||||
|
||||
/// The shade for time nothing was recorded in.
|
||||
fn shade(dark: bool) -> Color32 {
|
||||
if dark {
|
||||
Color32::WHITE.gamma_multiply(0.14)
|
||||
} else {
|
||||
Color32::BLACK.gamma_multiply(0.12)
|
||||
}
|
||||
}
|
||||
|
||||
/// Resets as dashed lines, and everything unrecorded as one grey band per stretch.
|
||||
/// Resets as dashed lines, and everything unrecorded as one tinted band per stretch.
|
||||
fn marks(plot: &mut PlotUi<'_>, buckets: &[Bucket], axes: Axes) {
|
||||
let warn = style::marks(axes.dark)[1];
|
||||
let p = theme::of(axes.dark);
|
||||
for bucket in buckets {
|
||||
if bucket.reset {
|
||||
plot.vline(
|
||||
VLine::new("Reset", bucket.start as f64 + axes.tz)
|
||||
.stroke(Stroke::new(1.5, warn))
|
||||
.stroke(Stroke::new(1.5, p.warn))
|
||||
.style(LineStyle::Dashed { length: 12.0 }),
|
||||
);
|
||||
}
|
||||
@@ -209,7 +225,7 @@ fn marks(plot: &mut PlotUi<'_>, buckets: &[Bucket], axes: Axes) {
|
||||
for (from, to) in unrecorded(buckets, axes.window, axes.step) {
|
||||
plot.span(
|
||||
Span::new("Not recorded", (from + axes.tz)..=(to + axes.tz))
|
||||
.fill(shade(axes.dark))
|
||||
.fill(p.unrecorded)
|
||||
.border_width(0.0),
|
||||
);
|
||||
}
|
||||
@@ -222,25 +238,13 @@ fn marked(buckets: &[Bucket], axes: Axes) -> (bool, bool) {
|
||||
(any_reset, any_gap)
|
||||
}
|
||||
|
||||
/// The key to a chart, drawn under it so it never sits on the data.
|
||||
fn legend(ui: &mut Ui, entries: Vec<(style::Mark, &'static str)>) {
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 14.0;
|
||||
for (mark, text) in entries {
|
||||
style::key(ui, mark);
|
||||
ui.label(RichText::new(text).small().weak());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn overlay(ui: &mut Ui, chart: &PlotResponse<()>, text: &str) {
|
||||
ui.painter().text(
|
||||
chart.response.rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
text,
|
||||
egui::TextStyle::Body.resolve(ui.style()),
|
||||
ui.visuals().weak_text_color(),
|
||||
egui::FontId::proportional(theme::px::SMALL),
|
||||
theme::ui(ui).muted,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -260,6 +264,7 @@ fn split(bucket: &Bucket, hidden: &[String]) -> (u64, u64) {
|
||||
}
|
||||
|
||||
fn hit_rate_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
|
||||
let p = theme::ui(ui);
|
||||
// One line per stretch of buckets that have a hit rate.
|
||||
let mut runs: Vec<Vec<PlotPoint>> = Vec::new();
|
||||
let mut run: Vec<PlotPoint> = Vec::new();
|
||||
@@ -299,7 +304,7 @@ fn hit_rate_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
|
||||
for points in &runs {
|
||||
plot.line(
|
||||
Line::new("Hit rate", PlotPoints::Owned(points.clone()))
|
||||
.color(style::CACHE)
|
||||
.color(p.from_cache)
|
||||
.width(2.0),
|
||||
);
|
||||
}
|
||||
@@ -308,17 +313,18 @@ fn hit_rate_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
|
||||
overlay(ui, &chart, "No cacheable compiles in this range");
|
||||
}
|
||||
let (any_reset, any_gap) = marked(&view.buckets, axes);
|
||||
let mut entries = vec![(style::Mark::Line(style::CACHE), "Hit rate")];
|
||||
let mut entries = vec![(style::Mark::Line(p.from_cache), "Hit rate".to_owned())];
|
||||
if any_reset {
|
||||
entries.push((style::Mark::Dashed(style::marks(axes.dark)[1]), "Reset"));
|
||||
entries.push((style::Mark::Dashed(p.warn), "Reset".to_owned()));
|
||||
}
|
||||
if any_gap {
|
||||
entries.push((style::Mark::Band(axes.dark), "Not recorded"));
|
||||
entries.push((style::Mark::Band, "Not recorded".to_owned()));
|
||||
}
|
||||
legend(ui, entries);
|
||||
style::legend(ui, entries);
|
||||
}
|
||||
|
||||
fn volume_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
|
||||
let p = theme::ui(ui);
|
||||
// The tallest stack of one bucket, with a little air above it.
|
||||
let top = view
|
||||
.buckets
|
||||
@@ -359,15 +365,15 @@ fn volume_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
|
||||
marks(plot, &view.buckets, axes);
|
||||
let from_cache = BarChart::new("From cache", from_cache)
|
||||
.width(width)
|
||||
.color(style::CACHE);
|
||||
.color(p.from_cache);
|
||||
let built = BarChart::new("Built", built)
|
||||
.width(width)
|
||||
.color(style::BUILT)
|
||||
.stack_on(&[&from_cache]);
|
||||
.color(p.built);
|
||||
let other = BarChart::new("Not cacheable and other", other)
|
||||
.width(width)
|
||||
.color(style::NOT_CACHEABLE)
|
||||
.stack_on(&[&built]);
|
||||
.color(p.not_cacheable);
|
||||
let built = built.stack_on(&[&from_cache]);
|
||||
let other = other.stack_on(&[&built]);
|
||||
plot.bar_chart(from_cache);
|
||||
plot.bar_chart(built);
|
||||
if hidden.is_empty() {
|
||||
@@ -379,17 +385,17 @@ fn volume_chart(ui: &mut Ui, view: &View, hidden: &[String], axes: Axes) {
|
||||
}
|
||||
let (any_reset, any_gap) = marked(&view.buckets, axes);
|
||||
let mut entries = vec![
|
||||
(style::Mark::Fill(style::CACHE), "From cache"),
|
||||
(style::Mark::Fill(style::BUILT), "Built"),
|
||||
(style::Mark::Fill(p.from_cache), "From cache".to_owned()),
|
||||
(style::Mark::Fill(p.built), "Built".to_owned()),
|
||||
];
|
||||
if hidden.is_empty() {
|
||||
entries.push((style::Mark::Fill(style::NOT_CACHEABLE), "Not cacheable and other"));
|
||||
entries.push((style::Mark::Fill(p.not_cacheable), "Not cacheable and other".to_owned()));
|
||||
}
|
||||
if any_reset {
|
||||
entries.push((style::Mark::Dashed(style::marks(axes.dark)[1]), "Reset"));
|
||||
entries.push((style::Mark::Dashed(p.warn), "Reset".to_owned()));
|
||||
}
|
||||
if any_gap {
|
||||
entries.push((style::Mark::Band(axes.dark), "Not recorded"));
|
||||
entries.push((style::Mark::Band, "Not recorded".to_owned()));
|
||||
}
|
||||
legend(ui, entries);
|
||||
style::legend(ui, entries);
|
||||
}
|
||||
+34
-35
@@ -1,42 +1,41 @@
|
||||
//! Problems: what is wrong, most serious first.
|
||||
//! Problems: what is wrong, most serious first. A dot for how serious, the
|
||||
//! title, and the detail in small print.
|
||||
|
||||
use eframe::egui::{self, RichText, Stroke, Ui};
|
||||
use eframe::egui::{self, Ui};
|
||||
use sccache_dash_api::{Severity, View};
|
||||
|
||||
use crate::style;
|
||||
use crate::theme;
|
||||
|
||||
pub fn section(ui: &mut Ui, view: &View, dark: bool) {
|
||||
style::section(ui, "problems", "Problems", |ui| {
|
||||
if view.problems.is_empty() {
|
||||
ui.label("No problems.");
|
||||
return;
|
||||
pub fn section(ui: &mut Ui, view: &View) {
|
||||
let p = theme::ui(ui);
|
||||
if view.problems.is_empty() {
|
||||
// Nothing to alarm: a calm dot in the good colour and the words.
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::space::ITEM + 2.0;
|
||||
style::dot(ui, p.good);
|
||||
ui.label(theme::body("No problems"));
|
||||
});
|
||||
ui.add(egui::Label::new(theme::small(ui, "Nothing needs attention.")).wrap());
|
||||
return;
|
||||
}
|
||||
for (index, problem) in view.problems.iter().enumerate() {
|
||||
if index > 0 {
|
||||
ui.add_space(theme::space::BETWEEN_PARTS);
|
||||
}
|
||||
let [_, warn, bad] = style::marks(dark);
|
||||
for problem in &view.problems {
|
||||
let color = match problem.severity {
|
||||
Severity::Error => bad,
|
||||
Severity::Warning => warn,
|
||||
};
|
||||
let kind = match problem.severity {
|
||||
Severity::Error => "Error",
|
||||
Severity::Warning => "Warning",
|
||||
};
|
||||
// As wide as there is room, minus a little (see `banner`).
|
||||
let width = ui.available_rect_before_wrap().width() - 2.0 * 8.0;
|
||||
egui::Frame::NONE
|
||||
.fill(color.gamma_multiply(0.14))
|
||||
.stroke(Stroke::new(1.0, color))
|
||||
.corner_radius(6.0)
|
||||
.inner_margin(8.0)
|
||||
.show(ui, |ui| {
|
||||
ui.set_min_width(width - 6.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new(kind).small().strong().color(color));
|
||||
ui.label(RichText::new(&problem.title).strong());
|
||||
});
|
||||
ui.add(egui::Label::new(&problem.detail).wrap());
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
});
|
||||
let color = match problem.severity {
|
||||
Severity::Error => p.bad,
|
||||
Severity::Warning => p.warn,
|
||||
};
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::space::ITEM + 2.0;
|
||||
style::dot(ui, color);
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
theme::strong(problem.title.clone()).color(color),
|
||||
),
|
||||
);
|
||||
});
|
||||
ui.add(egui::Label::new(theme::small(ui, problem.detail.clone())).wrap());
|
||||
}
|
||||
}
|
||||
+123
-36
@@ -1,59 +1,146 @@
|
||||
//! Raw counters: the sccache stats exactly as the server read them.
|
||||
//! Raw counters: the sccache stats exactly as the server read them, as compact
|
||||
//! key/value lines that flow in columns. The panel opens and closes; it starts
|
||||
//! open.
|
||||
|
||||
use eframe::egui::{self, RichText, Ui};
|
||||
use std::cell::Cell;
|
||||
|
||||
use eframe::egui::{self, Pos2, Rect, Sense, Ui};
|
||||
use sccache_dash_api::View;
|
||||
|
||||
use crate::style;
|
||||
use crate::theme;
|
||||
|
||||
pub fn section(ui: &mut Ui, view: &View) {
|
||||
style::section(ui, "raw", "Raw counters", |ui| match &view.raw {
|
||||
serde_json::Value::Null => {
|
||||
ui.label("sccache's raw counters could not be read.");
|
||||
}
|
||||
value => tree(ui, value, "raw"),
|
||||
});
|
||||
}
|
||||
|
||||
/// A tree: one collapsible line per group, `name value` per counter.
|
||||
fn tree(ui: &mut Ui, value: &serde_json::Value, path: &str) {
|
||||
/// Every leaf of the JSON as its dotted path and its value as text.
|
||||
fn leaves(value: &serde_json::Value, path: String, out: &mut Vec<(String, String)>) {
|
||||
match value {
|
||||
serde_json::Value::Object(fields) => {
|
||||
for (name, value) in fields {
|
||||
branch(ui, name, value, path);
|
||||
let path = if path.is_empty() { name.clone() } else { format!("{path}.{name}") };
|
||||
leaves(value, path, out);
|
||||
}
|
||||
}
|
||||
serde_json::Value::Array(items) => {
|
||||
for (index, value) in items.iter().enumerate() {
|
||||
branch(ui, &index.to_string(), value, path);
|
||||
leaves(value, format!("{path}[{index}]"), out);
|
||||
}
|
||||
}
|
||||
leaf => counter(ui, "", leaf),
|
||||
leaf => out.push((
|
||||
path,
|
||||
match leaf {
|
||||
serde_json::Value::String(text) => text.clone(),
|
||||
serde_json::Value::Null => "null".to_owned(),
|
||||
number => number.to_string(),
|
||||
},
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn branch(ui: &mut Ui, name: &str, value: &serde_json::Value, path: &str) {
|
||||
let path = format!("{path}/{name}");
|
||||
if value.is_object() || value.is_array() {
|
||||
egui::CollapsingHeader::new(RichText::new(name).strong())
|
||||
.id_salt(path.clone())
|
||||
.default_open(true)
|
||||
.show(ui, |ui| tree(ui, value, &path));
|
||||
} else {
|
||||
counter(ui, name, value);
|
||||
}
|
||||
/// How many lines a panel `width` wide runs its key/value lines in.
|
||||
fn columns(width: 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)
|
||||
}
|
||||
|
||||
/// One counter as sccache prints its value.
|
||||
fn counter(ui: &mut Ui, name: &str, value: &serde_json::Value) {
|
||||
let text = match value {
|
||||
serde_json::Value::String(text) => text.clone(),
|
||||
serde_json::Value::Null => "null".to_owned(),
|
||||
number => number.to_string(),
|
||||
};
|
||||
/// How tall the panel is at `width`: 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 {
|
||||
return title - theme::space::UNDER_TITLE + theme::space::LINE;
|
||||
}
|
||||
let mut lines = 0;
|
||||
if !view.raw.is_null() {
|
||||
let mut out = Vec::new();
|
||||
leaves(&view.raw, String::new(), &mut out);
|
||||
lines = out.len();
|
||||
}
|
||||
title + lines.div_ceil(columns(width)) as f32 * theme::space::ROW
|
||||
}
|
||||
|
||||
/// The panel at `rect`; its title opens and closes it. Returns the rect it took.
|
||||
pub fn section(ui: &mut Ui, view: &View, rect: Rect) -> Rect {
|
||||
let id = egui::Id::unique("raw-counters-open");
|
||||
let open = Cell::new(ui.ctx().data_mut(|data| data.get_temp::<bool>(id)).unwrap_or(true));
|
||||
let (_, taken) = style::panel_titled(
|
||||
ui,
|
||||
rect,
|
||||
|ui| {
|
||||
let mut now = open.get();
|
||||
style::toggling_title(ui, "Raw counters", &mut now);
|
||||
open.set(now);
|
||||
},
|
||||
|ui| {
|
||||
let open = open.get();
|
||||
ui.ctx().data_mut(|data| data.insert_temp(id, open));
|
||||
if !open {
|
||||
return;
|
||||
}
|
||||
match &view.raw {
|
||||
serde_json::Value::Null => {
|
||||
ui.label(theme::body("sccache's raw counters could not be read."));
|
||||
}
|
||||
value => {
|
||||
let mut lines = Vec::new();
|
||||
leaves(value, String::new(), &mut lines);
|
||||
flow(ui, &lines);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
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.
|
||||
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 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| {
|
||||
if !name.is_empty() {
|
||||
ui.label(name);
|
||||
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;
|
||||
}
|
||||
}
|
||||
} 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}"));
|
||||
}
|
||||
}
|
||||
ui.label(RichText::new(text).weak());
|
||||
});
|
||||
}
|
||||
+110
-107
@@ -1,64 +1,84 @@
|
||||
//! Speed: how long a cache fetch, a cache write and a build take on average,
|
||||
//! and how build times spread for each language.
|
||||
|
||||
use eframe::egui::{self, Color32, Layout, RichText, Sense, Ui};
|
||||
use eframe::egui::{self, Pos2, Rect, Sense, Ui};
|
||||
use sccache_dash_api::{BuildTimes, View};
|
||||
|
||||
use crate::fmt;
|
||||
use crate::style;
|
||||
use crate::theme;
|
||||
|
||||
/// Every histogram is this tall, whatever it holds.
|
||||
const HISTOGRAM_HEIGHT: f32 = 44.0;
|
||||
/// The slowest build time the axis reaches, as log10 of milliseconds (1,000 s).
|
||||
const AXIS_TOP: f64 = 6.0;
|
||||
/// The width of the label and of the value beside each speed bar.
|
||||
const LABEL_WIDTH: f32 = 128.0;
|
||||
const VALUE_WIDTH: f32 = 60.0;
|
||||
|
||||
pub fn section(ui: &mut Ui, view: &View) {
|
||||
let p = theme::ui(ui);
|
||||
let timing = view.timing;
|
||||
style::section(ui, "speed", "Speed", |ui| {
|
||||
let rows = [
|
||||
("Cache fetch (a hit)", timing.avg_hit_read_ms, style::CACHE),
|
||||
("Cache write", timing.avg_cache_write_ms, style::BUILT),
|
||||
("Build (compile)", timing.avg_compile_ms, Color32::GRAY),
|
||||
];
|
||||
let label_width = if ui.available_rect_before_wrap().width() < 480.0 {
|
||||
124.0
|
||||
} else {
|
||||
170.0
|
||||
};
|
||||
for (label, ms, color) in rows {
|
||||
ui.horizontal(|ui| {
|
||||
cell(ui, label_width, Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
ui.add(egui::Label::new(label).truncate());
|
||||
});
|
||||
let text = ms.map_or("—".into(), |ms| fmt::duration(ms / 1000.0));
|
||||
cell(ui, 72.0, Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.label(RichText::new(text).strong());
|
||||
});
|
||||
style::meter(ui, 12.0, ms.map_or(0.0, style::log_fraction), color);
|
||||
});
|
||||
}
|
||||
let hit = timing.avg_hit_read_ms;
|
||||
let write = timing.avg_cache_write_ms;
|
||||
let build = timing.avg_compile_ms;
|
||||
let sentence = if let Some(times) = faster(build, hit) {
|
||||
format!("A cache hit is about {times}x faster than building.")
|
||||
} else if let Some(times) = faster(build, write) {
|
||||
format!("Writing to the cache is about {times}x faster than building.")
|
||||
} else {
|
||||
"There are no timings to compare in this range.".to_owned()
|
||||
};
|
||||
ui.label(sentence);
|
||||
ui.label(
|
||||
RichText::new(
|
||||
"The bars use a log scale, so a fraction of a millisecond and several \
|
||||
seconds are both visible.",
|
||||
)
|
||||
.small()
|
||||
.weak(),
|
||||
);
|
||||
let rows = [
|
||||
("Cache fetch (a hit)", timing.avg_hit_read_ms, p.from_cache),
|
||||
("Cache write", timing.avg_cache_write_ms, p.built),
|
||||
("Build (compile)", timing.avg_compile_ms, p.muted),
|
||||
];
|
||||
for (label, ms, color) in rows {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::space::ITEM;
|
||||
let (label_rect, _) =
|
||||
ui.allocate_exact_size(egui::vec2(LABEL_WIDTH, theme::space::ROW), Sense::hover());
|
||||
let label = style::galley(ui, theme::body(label), false, f32::INFINITY);
|
||||
ui.painter().with_clip_rect(label_rect).galley(
|
||||
Pos2::new(label_rect.left(), label_rect.center().y - label.size().y / 2.0),
|
||||
label,
|
||||
p.text,
|
||||
);
|
||||
let text = ms.map_or("—".into(), |ms| fmt::duration(ms / 1000.0));
|
||||
let value = style::galley(ui, theme::number(text), false, f32::INFINITY);
|
||||
let value_rect = ui
|
||||
.allocate_exact_size(egui::vec2(VALUE_WIDTH, theme::space::ROW), Sense::hover())
|
||||
.0;
|
||||
ui.painter().with_clip_rect(value_rect).galley(
|
||||
Pos2::new(value_rect.right() - value.size().x, value_rect.center().y - value.size().y / 2.0),
|
||||
value,
|
||||
p.text,
|
||||
);
|
||||
let bar_rect = ui
|
||||
.allocate_exact_size(
|
||||
egui::vec2(ui.available_rect_before_wrap().width(), theme::space::ROW),
|
||||
Sense::hover(),
|
||||
)
|
||||
.0;
|
||||
let bar = Rect::from_center_size(
|
||||
bar_rect.center(),
|
||||
egui::vec2(bar_rect.width(), theme::drawing::SPEED_BAR),
|
||||
);
|
||||
style::fill_bar(ui, bar, ms.map_or(0.0, style::log_fraction), color);
|
||||
});
|
||||
}
|
||||
let hit = timing.avg_hit_read_ms;
|
||||
let write = timing.avg_cache_write_ms;
|
||||
let build = timing.avg_compile_ms;
|
||||
let sentence = if let Some(times) = faster(build, hit) {
|
||||
format!("A cache hit is about {times}x faster than building.")
|
||||
} else if let Some(times) = faster(build, write) {
|
||||
format!("Writing to the cache is about {times}x faster than building.")
|
||||
} else {
|
||||
"There are no timings to compare in this range.".to_owned()
|
||||
};
|
||||
ui.add_space(theme::space::ITEM);
|
||||
ui.add(egui::Label::new(theme::strong(sentence)).wrap());
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
theme::small(
|
||||
ui,
|
||||
"The bars use a log scale, so a fraction of a millisecond and several seconds are \
|
||||
both visible.",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
build_times(ui, view);
|
||||
});
|
||||
build_times(ui, view);
|
||||
}
|
||||
|
||||
/// `faster` is about how many times shorter than `slower`, when both are known and positive.
|
||||
@@ -67,15 +87,10 @@ fn faster(slower: Option<f64>, faster: Option<f64>) -> Option<String> {
|
||||
(slower > 0.0 && faster > 0.0).then(|| fmt::round_number(slower / faster))
|
||||
}
|
||||
|
||||
/// Draw with a fixed width, so the bars all start at the same place.
|
||||
fn cell(ui: &mut Ui, width: f32, layout: Layout, contents: impl FnOnce(&mut Ui)) {
|
||||
let height = ui.text_style_height(&egui::TextStyle::Body);
|
||||
ui.allocate_ui_with_layout(egui::vec2(width, height), layout, contents);
|
||||
}
|
||||
|
||||
/// "How long builds take, by language": one histogram per language, all on the
|
||||
/// same log scale of build time, with the mean, median and p90 marked.
|
||||
fn build_times(ui: &mut Ui, view: &View) {
|
||||
let p = theme::ui(ui);
|
||||
let languages: Vec<&BuildTimes> = view
|
||||
.build_times
|
||||
.iter()
|
||||
@@ -84,8 +99,8 @@ fn build_times(ui: &mut Ui, view: &View) {
|
||||
if languages.is_empty() {
|
||||
return;
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
ui.label(RichText::new("How long builds take, by language").strong());
|
||||
ui.add_space(theme::space::BETWEEN_PARTS);
|
||||
crate::overtime::part_title(ui, "How long builds take, by language");
|
||||
|
||||
// One shared axis, from a quarter step before the fastest bin to a quarter step after the slowest.
|
||||
let (mut low, mut high) = (f64::MAX, 0.0_f64);
|
||||
@@ -98,44 +113,33 @@ fn build_times(ui: &mut Ui, view: &View) {
|
||||
let low = (low.max(1.0).log10() - 0.25).max(0.0);
|
||||
let high = (high.log10() + 0.25).min(AXIS_TOP);
|
||||
|
||||
let [_, median_color, p90_color] = style::marks(ui.visuals().dark_mode);
|
||||
let mean_color = ui.visuals().text_color();
|
||||
for times in languages {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new(×.language).strong());
|
||||
ui.label(format!("{} builds", fmt::count(times.compiles)));
|
||||
ui.add_space(6.0);
|
||||
ui.label(RichText::new(format!("mean {}", ms(times.mean_ms))).small().color(mean_color));
|
||||
ui.label(
|
||||
RichText::new(format!("median {}", ms(times.median_ms)))
|
||||
.small()
|
||||
.color(median_color),
|
||||
);
|
||||
ui.label(
|
||||
RichText::new(format!("p90 {}", ms(times.p90_ms)))
|
||||
.small()
|
||||
.color(p90_color),
|
||||
);
|
||||
ui.add_space(theme::space::ITEM);
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::space::ITEM;
|
||||
ui.add(egui::Label::new(theme::strong(times.language.clone())).truncate());
|
||||
ui.add(egui::Label::new(theme::small(ui, format!("{} builds", fmt::count(times.compiles)))).truncate());
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.spacing_mut().item_spacing.x = theme::space::ITEM;
|
||||
for (name, value, color) in [
|
||||
("p90", times.p90_ms, p.p90),
|
||||
("median", times.median_ms, p.median),
|
||||
("mean", times.mean_ms, p.mean),
|
||||
] {
|
||||
ui.label(theme::small(ui, format!("{name} {}", ms(value))).color(color));
|
||||
}
|
||||
});
|
||||
});
|
||||
histogram(
|
||||
ui,
|
||||
times,
|
||||
low,
|
||||
high,
|
||||
[mean_color, median_color, p90_color],
|
||||
);
|
||||
histogram(ui, times, low, high, p);
|
||||
axis(ui, low, high);
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
RichText::new(
|
||||
theme::small(
|
||||
ui,
|
||||
"Each point is the average of the builds that finished within one 10-second reading.",
|
||||
)
|
||||
.small()
|
||||
.weak(),
|
||||
)
|
||||
.wrap(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -145,12 +149,14 @@ fn ms(value: f64) -> String {
|
||||
|
||||
/// The bins as bars, build time along the bottom on a log scale, with a line
|
||||
/// for the mean, median and p90.
|
||||
fn histogram(ui: &mut Ui, times: &BuildTimes, low: f64, high: f64, colors: [Color32; 3]) {
|
||||
fn histogram(ui: &mut Ui, times: &BuildTimes, low: f64, high: f64, p: &theme::Palette) {
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let (rect, response) =
|
||||
ui.allocate_exact_size(egui::vec2(width, HISTOGRAM_HEIGHT), Sense::hover());
|
||||
let (rect, response) = ui.allocate_exact_size(
|
||||
egui::vec2(width, theme::drawing::BUILD_HISTOGRAM),
|
||||
Sense::hover(),
|
||||
);
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(rect, 3.0, ui.visuals().extreme_bg_color);
|
||||
painter.hline(rect.x_range(), rect.bottom() - 0.5, egui::Stroke::new(1.0, p.grid));
|
||||
let at = |value: f64| {
|
||||
let position = ((value.max(1.0).log10() - low) / (high - low)).clamp(0.0, 1.0);
|
||||
rect.left() + rect.width() * position as f32
|
||||
@@ -160,17 +166,17 @@ fn histogram(ui: &mut Ui, times: &BuildTimes, low: f64, high: f64, colors: [Colo
|
||||
if bin.compiles == 0 {
|
||||
continue;
|
||||
}
|
||||
let height = HISTOGRAM_HEIGHT * bin.compiles as f32 / top.max(1) as f32;
|
||||
let bar = egui::Rect::from_min_max(
|
||||
egui::pos2(at(bin.from_ms), rect.bottom() - height),
|
||||
egui::pos2((at(bin.to_ms) - 1.0).max(at(bin.from_ms) + 1.0), rect.bottom()),
|
||||
let height = theme::drawing::BUILD_HISTOGRAM * bin.compiles as f32 / top.max(1) as f32;
|
||||
let bar = Rect::from_min_max(
|
||||
Pos2::new(at(bin.from_ms), rect.bottom() - height),
|
||||
Pos2::new((at(bin.to_ms) - 1.0).max(at(bin.from_ms) + 1.0), rect.bottom()),
|
||||
);
|
||||
painter.rect_filled(bar, 1.0, style::BUILT.gamma_multiply(0.75));
|
||||
painter.rect_filled(bar, 1.0, p.built);
|
||||
}
|
||||
for (value, color) in [times.mean_ms, times.median_ms, times.p90_ms].into_iter().zip(colors) {
|
||||
for (value, color) in [times.mean_ms, times.median_ms, times.p90_ms].into_iter().zip([p.mean, p.median, p.p90]) {
|
||||
let x = at(value);
|
||||
painter.rect_filled(
|
||||
egui::Rect::from_min_max(egui::pos2(x, rect.top()), egui::pos2(x + 2.0, rect.bottom())),
|
||||
Rect::from_min_max(Pos2::new(x, rect.top()), Pos2::new(x + 2.0, rect.bottom())),
|
||||
0.0,
|
||||
color,
|
||||
);
|
||||
@@ -186,22 +192,19 @@ fn histogram(ui: &mut Ui, times: &BuildTimes, low: f64, high: f64, colors: [Colo
|
||||
|
||||
/// The times along the bottom of a histogram: one mark every tenfold step.
|
||||
fn axis(ui: &mut Ui, low: f64, high: f64) {
|
||||
let p = theme::ui(ui);
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, 14.0), Sense::hover());
|
||||
let font = egui::TextStyle::Small.resolve(ui.style());
|
||||
let color = ui.visuals().weak_text_color();
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, theme::drawing::BUILD_AXIS), Sense::hover());
|
||||
let font = egui::FontId::proportional(theme::px::SMALL);
|
||||
for step in 0..=AXIS_TOP as i64 {
|
||||
let value = step as f64;
|
||||
if value < low || value > high {
|
||||
continue;
|
||||
}
|
||||
let x = rect.left() + rect.width() * ((value - low) / (high - low)) as f32;
|
||||
ui.painter().text(
|
||||
egui::pos2(x, rect.center().y),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
ms(10.0_f64.powf(value)),
|
||||
font.clone(),
|
||||
color,
|
||||
);
|
||||
let text = ms(10.0_f64.powf(value));
|
||||
let galley = ui.painter().layout_no_wrap(text, font.clone(), p.muted);
|
||||
let x = x.clamp(rect.left(), rect.right() - galley.size().x);
|
||||
ui.painter().galley(Pos2::new(x, rect.center().y - galley.size().y / 2.0), galley, p.muted);
|
||||
}
|
||||
}
|
||||
+556
-218
@@ -1,100 +1,555 @@
|
||||
//! Colours and small drawings shared by the sections.
|
||||
//! Drawings shared by the panels: the grid, panels, cards, tables, bars and
|
||||
//! chart keys. Every colour and size comes from [`crate::theme`].
|
||||
|
||||
use eframe::egui::{self, Align, Color32, Layout, Pos2, RichText, Sense, Shape, Stroke, Ui};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Served from the cache.
|
||||
pub const CACHE: Color32 = Color32::from_rgb(0x4C, 0xAF, 0x50);
|
||||
/// Compiled because the cache had nothing.
|
||||
pub const BUILT: Color32 = Color32::from_rgb(0x42, 0xA5, 0xF5);
|
||||
pub const NOT_CACHEABLE: Color32 = Color32::from_rgb(0xFF, 0xA7, 0x26);
|
||||
pub const UNSUPPORTED: Color32 = Color32::from_rgb(0xAB, 0x47, 0xBC);
|
||||
pub const NOT_COMPILE: Color32 = Color32::from_rgb(0x26, 0xA6, 0x9A);
|
||||
use eframe::egui::{self, Align, Align2, Color32, Galley, Layout, Pos2, Rect, RichText, Sense, Shape, Stroke, StrokeKind, Ui};
|
||||
use egui::TextWrapMode;
|
||||
|
||||
/// Text colours that mean "good", "worth a look" and "bad", for the theme being drawn.
|
||||
pub fn marks(dark: bool) -> [Color32; 3] {
|
||||
if dark {
|
||||
[
|
||||
Color32::from_rgb(0x3F, 0xB9, 0x50),
|
||||
Color32::from_rgb(0xD2, 0x99, 0x22),
|
||||
Color32::from_rgb(0xF8, 0x51, 0x49),
|
||||
use crate::theme::{self, px, space};
|
||||
|
||||
/// The palette of the theme being drawn.
|
||||
pub fn p(ui: &Ui) -> &'static theme::Palette {
|
||||
theme::ui(ui)
|
||||
}
|
||||
|
||||
/// The width of `text` in `font`.
|
||||
pub fn text_width(ui: &Ui, text: &str, font: egui::FontId) -> f32 {
|
||||
ui.painter()
|
||||
.layout_no_wrap(text.to_owned(), font, theme::ui(ui).text)
|
||||
.size()
|
||||
.x
|
||||
}
|
||||
|
||||
/// Lay `text` out: on one line, or wrapped at `width` when `wrap` is set.
|
||||
pub fn galley(ui: &Ui, text: RichText, wrap: bool, width: f32) -> Arc<Galley> {
|
||||
egui::WidgetText::from(text).into_galley(
|
||||
ui,
|
||||
Some(if wrap { TextWrapMode::Wrap } else { TextWrapMode::Extend }),
|
||||
width,
|
||||
egui::FontSelection::Default,
|
||||
)
|
||||
}
|
||||
|
||||
/// A colour made see-through.
|
||||
pub fn tint(color: Color32, share: f32) -> Color32 {
|
||||
theme::tint(color, share)
|
||||
}
|
||||
|
||||
// ---- The grid ----
|
||||
|
||||
/// How wide a panel is that spans `span` of the `columns` columns of a row.
|
||||
pub fn span_width(ui: &Ui, columns: usize, span: usize) -> f32 {
|
||||
let all = ui.available_rect_before_wrap().width();
|
||||
span_of(all, columns, span)
|
||||
}
|
||||
|
||||
/// The same, from the row's width instead of a `Ui`.
|
||||
pub fn span_of(row_width: f32, columns: usize, span: usize) -> f32 {
|
||||
let gaps = space::PANEL_GAP;
|
||||
let one = (row_width - gaps * (columns as f32 - 1.0)) / columns as f32;
|
||||
one * span as f32 + gaps * (span as f32 - 1.0)
|
||||
}
|
||||
|
||||
/// Where the panels of a row go: one rectangle per entry of `spans` (each the
|
||||
/// number of columns the panel spans), all `height` tall, starting at the
|
||||
/// cursor. Nothing is allocated yet; [`end_row`] does that.
|
||||
pub fn cells(ui: &Ui, height: f32, spans: &[usize]) -> Vec<Rect> {
|
||||
let columns: usize = spans.iter().sum();
|
||||
let top_left = ui.cursor().min;
|
||||
let mut left = top_left.x;
|
||||
spans
|
||||
.iter()
|
||||
.map(|span| {
|
||||
let width = span_width(ui, columns, *span);
|
||||
let rect = Rect::from_min_size(Pos2::new(left, top_left.y), egui::vec2(width, height));
|
||||
left += width + space::PANEL_GAP;
|
||||
rect
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Close a row of panels drawn at `rects`: the cursor moves below the tallest.
|
||||
pub fn end_row(ui: &mut Ui, rects: &[Rect]) {
|
||||
let bottom = rects.iter().map(|rect| rect.bottom()).fold(0.0, f32::max);
|
||||
let left = rects.first().map_or(ui.cursor().left(), |rect| rect.left());
|
||||
ui.allocate_rect(
|
||||
Rect::from_min_max(Pos2::new(left, ui.cursor().top()), Pos2::new(ui.cursor().right(), bottom)),
|
||||
Sense::hover(),
|
||||
);
|
||||
ui.add_space(space::PANEL_GAP);
|
||||
}
|
||||
|
||||
/// A hairline across the panel at the cursor.
|
||||
pub fn rule(ui: &mut Ui) {
|
||||
let (rect, _) = ui.allocate_exact_size(
|
||||
egui::vec2(ui.available_rect_before_wrap().width(), 1.0),
|
||||
Sense::hover(),
|
||||
);
|
||||
ui.painter()
|
||||
.hline(rect.x_range(), rect.top() + 0.5, Stroke::new(1.0, p(ui).border));
|
||||
}
|
||||
|
||||
// ---- Panels and cards ----
|
||||
|
||||
/// A panel with a title, at `rect`: panel colour, a 1 px border, 8 px corners.
|
||||
/// It comes out at least as tall as `rect`; the rect it took is returned second.
|
||||
pub fn panel<R>(ui: &mut Ui, rect: Rect, title: &str, body: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
|
||||
let text = theme::title(ui, title).text().to_owned();
|
||||
panel_titled(
|
||||
ui,
|
||||
rect,
|
||||
|ui| {
|
||||
ui.add(egui::Label::new(theme::title(ui, text)).truncate());
|
||||
},
|
||||
body,
|
||||
)
|
||||
}
|
||||
|
||||
/// [`panel`] with the title drawn by `title`: one line, `UNDER_TITLE` under it.
|
||||
pub fn panel_titled<R>(
|
||||
ui: &mut Ui,
|
||||
rect: Rect,
|
||||
title: impl FnOnce(&mut Ui),
|
||||
body: impl FnOnce(&mut Ui) -> R,
|
||||
) -> (R, Rect) {
|
||||
let p = p(ui);
|
||||
let pad = space::PANEL_PADDING + 1.0;
|
||||
let mut inner = ui.new_child(
|
||||
egui::UiBuilder::new()
|
||||
.max_rect(rect.shrink(pad))
|
||||
.layout(Layout::top_down(Align::Min)),
|
||||
);
|
||||
inner.set_width((rect.width() - 2.0 * pad).max(0.0));
|
||||
inner.set_min_height((rect.height() - 2.0 * pad).max(0.0));
|
||||
inner.spacing_mut().item_spacing = egui::vec2(space::ITEM, space::LINE);
|
||||
// A placeholder goes under the content now and is filled with the panel once
|
||||
// its height is known, so a body that needs more room still sits on it.
|
||||
let background = ui.painter().add(Shape::Noop);
|
||||
title(&mut inner);
|
||||
inner.add_space(space::UNDER_TITLE);
|
||||
let value = body(&mut inner);
|
||||
let taken = inner.min_rect().expand(pad);
|
||||
ui.painter().set(
|
||||
background,
|
||||
Shape::Vec(vec![
|
||||
Shape::rect_filled(taken, space::PANEL_RADIUS, p.panel),
|
||||
Shape::rect_stroke(taken, space::PANEL_RADIUS, Stroke::new(1.0, p.border), StrokeKind::Inside),
|
||||
]),
|
||||
);
|
||||
(value, taken)
|
||||
}
|
||||
|
||||
/// A message that must be noticed: the bad colour as a tint and a border, on
|
||||
/// the panel colour.
|
||||
pub fn banner(ui: &mut Ui, text: RichText, color: Color32) {
|
||||
let p = p(ui);
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, 40.0), Sense::hover());
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
space::CONTROL_RADIUS,
|
||||
tint(color, 0.14),
|
||||
Stroke::new(1.0, tint(color, 0.5)),
|
||||
StrokeKind::Inside,
|
||||
);
|
||||
let galley = galley(
|
||||
ui,
|
||||
text.strong().font(theme::semibold(px::BODY)),
|
||||
true,
|
||||
width - 2.0 * space::PANEL_PADDING,
|
||||
);
|
||||
ui.painter().galley(
|
||||
Pos2::new(rect.left() + space::PANEL_PADDING, rect.center().y - galley.size().y / 2.0),
|
||||
galley,
|
||||
p.text,
|
||||
);
|
||||
}
|
||||
|
||||
/// The title of a panel that opens and closes when clicked. `open` is read and
|
||||
/// written through `toggle`; returns whether it is open after the click.
|
||||
pub fn toggling_title(ui: &mut Ui, title: &str, open: &mut bool) -> bool {
|
||||
let p = p(ui);
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let (rect, response) = ui.allocate_exact_size(egui::vec2(width, space::ROW), Sense::click());
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, title));
|
||||
if response.clicked() {
|
||||
*open = !*open;
|
||||
}
|
||||
let painter = ui.painter();
|
||||
let color = if response.hovered() { p.text } else { p.muted };
|
||||
let galley = galley(ui, theme::title(ui, title).color(color), false, f32::INFINITY);
|
||||
painter.galley(
|
||||
Pos2::new(rect.left(), rect.center().y - galley.size().y / 2.0),
|
||||
galley,
|
||||
color,
|
||||
);
|
||||
// A small chevron at the right: down when open, right when closed.
|
||||
let at = Pos2::new(rect.right() - 4.0, rect.center().y);
|
||||
let stroke = Stroke::new(1.5, p.muted);
|
||||
let points = if *open {
|
||||
vec![
|
||||
Pos2::new(at.x - 4.0, at.y - 2.0),
|
||||
at,
|
||||
Pos2::new(at.x + 4.0, at.y - 2.0),
|
||||
]
|
||||
} else {
|
||||
[
|
||||
Color32::from_rgb(0x1A, 0x7F, 0x37),
|
||||
Color32::from_rgb(0x9A, 0x67, 0x00),
|
||||
Color32::from_rgb(0xCF, 0x22, 0x2E),
|
||||
vec![
|
||||
Pos2::new(at.x - 2.0, at.y - 4.0),
|
||||
at,
|
||||
Pos2::new(at.x - 2.0, at.y + 4.0),
|
||||
]
|
||||
}
|
||||
};
|
||||
painter.add(Shape::line(points, stroke));
|
||||
*open
|
||||
}
|
||||
|
||||
/// The colour of a hit rate: green from 70%, yellow from 40%, red below.
|
||||
pub fn hit_rate_color(rate: Option<f64>, dark: bool) -> Color32 {
|
||||
let [good, warn, bad] = marks(dark);
|
||||
match rate {
|
||||
Some(rate) if rate >= 0.7 => good,
|
||||
Some(rate) if rate >= 0.4 => warn,
|
||||
Some(_) => bad,
|
||||
None => Color32::GRAY,
|
||||
/// One stat card: a small upper-case label, the number in mono, one line of
|
||||
/// small print and the change against the period before. Exactly `rect`.
|
||||
pub fn card(ui: &mut Ui, rect: Rect, label: &str, number: &str, detail: &str, change: RichText, color: Color32) {
|
||||
let p = p(ui);
|
||||
ui.allocate_rect(rect, Sense::hover());
|
||||
let painter = ui.painter();
|
||||
painter.rect(
|
||||
rect,
|
||||
space::PANEL_RADIUS,
|
||||
p.panel,
|
||||
Stroke::new(1.0, p.border),
|
||||
StrokeKind::Inside,
|
||||
);
|
||||
let mut inner = ui.new_child(
|
||||
egui::UiBuilder::new()
|
||||
.max_rect(rect.shrink(space::CARD_PADDING + 1.0))
|
||||
.layout(Layout::top_down(Align::Min)),
|
||||
);
|
||||
inner.set_width(rect.width() - 2.0 * (space::CARD_PADDING + 1.0));
|
||||
inner.spacing_mut().item_spacing = egui::vec2(space::ITEM, 1.0);
|
||||
inner.add(egui::Label::new(theme::title(ui, label)).truncate());
|
||||
inner.add(
|
||||
egui::Label::new(
|
||||
RichText::new(number)
|
||||
.font(theme::number_font(px::CARD_NUMBER))
|
||||
.color(color),
|
||||
)
|
||||
.truncate(),
|
||||
);
|
||||
let detail_label = inner.add(egui::Label::new(theme::small(ui, detail)).truncate());
|
||||
if !detail.is_empty() {
|
||||
detail_label.on_hover_text(detail);
|
||||
}
|
||||
inner.add(egui::Label::new(change).truncate());
|
||||
}
|
||||
|
||||
/// A titled section that starts open and can be folded away.
|
||||
pub fn section<R>(
|
||||
ui: &mut Ui,
|
||||
id: &'static str,
|
||||
title: impl Into<egui::WidgetText>,
|
||||
body: impl FnOnce(&mut Ui) -> R,
|
||||
) -> Option<R> {
|
||||
ui.add_space(8.0);
|
||||
// The body is indented, and then thinks it may run that much further right;
|
||||
// hold it to the width that is left so nothing is pushed off the page.
|
||||
let body_width = ui.available_rect_before_wrap().width() - ui.spacing().indent;
|
||||
egui::CollapsingHeader::new(title.into().strong().size(17.0))
|
||||
.id_salt(id)
|
||||
.default_open(true)
|
||||
.show(ui, |ui| {
|
||||
ui.set_max_width(body_width);
|
||||
body(ui)
|
||||
// ---- Controls ----
|
||||
|
||||
/// One segmented control: `labels` side by side in one pill, the `chosen` one
|
||||
/// marked with the accent. Returns the segment that was clicked.
|
||||
pub fn segmented(ui: &mut Ui, id_salt: &'static str, labels: &[&str], chosen: usize) -> Option<usize> {
|
||||
let p = p(ui);
|
||||
let font = theme::medium(px::BODY);
|
||||
let widths: Vec<f32> = labels
|
||||
.iter()
|
||||
.map(|label| text_width(ui, label, font.clone()) + 2.0 * space::CONTROL_PAD)
|
||||
.collect();
|
||||
let total: f32 = widths.iter().sum();
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(total, space::CONTROL_HEIGHT), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
painter.rect(
|
||||
rect,
|
||||
space::CONTROL_RADIUS,
|
||||
p.track,
|
||||
Stroke::new(1.0, p.border),
|
||||
StrokeKind::Inside,
|
||||
);
|
||||
let mut left = rect.left();
|
||||
let mut clicked = None;
|
||||
for (index, (label, width)) in labels.iter().zip(&widths).enumerate() {
|
||||
let segment = Rect::from_min_max(Pos2::new(left, rect.top()), Pos2::new(left + width, rect.bottom()));
|
||||
let response = ui
|
||||
.interact(segment, ui.scope_id().with(id_salt).with(index), Sense::click())
|
||||
.on_hover_cursor(egui::CursorIcon::PointingHand);
|
||||
let selected = index == chosen;
|
||||
let fill = if selected {
|
||||
tint(p.accent, 0.22)
|
||||
} else if response.hovered() {
|
||||
p.hover
|
||||
} else {
|
||||
Color32::TRANSPARENT
|
||||
};
|
||||
if selected || response.hovered() {
|
||||
painter.rect_filled(segment.shrink2(egui::vec2(1.0, 1.0)), space::CONTROL_RADIUS - 2.0, fill);
|
||||
}
|
||||
if index > 0 && !selected && index - 1 != chosen {
|
||||
painter.vline(segment.left() + 0.5, segment.y_range().shrink(7.0), Stroke::new(1.0, p.border));
|
||||
}
|
||||
let color = if selected {
|
||||
p.accent
|
||||
} else if response.hovered() {
|
||||
p.text
|
||||
} else {
|
||||
p.muted
|
||||
};
|
||||
painter.text(segment.center(), Align2::CENTER_CENTER, *label, font.clone(), color);
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, selected, *label));
|
||||
if response.clicked() {
|
||||
clicked = Some(index);
|
||||
}
|
||||
left += width;
|
||||
}
|
||||
clicked
|
||||
}
|
||||
|
||||
// ---- Tables ----
|
||||
|
||||
/// What one cell of a [`table`] holds.
|
||||
pub enum Cell {
|
||||
Text(RichText),
|
||||
/// A colour square, then text: the entry of a legend.
|
||||
Marked(Color32, RichText),
|
||||
/// A hit-rate bar for `hits` out of `hits + misses`; its column is fixed width.
|
||||
Bar(u64, u64),
|
||||
}
|
||||
|
||||
/// A table that lives inside its panel: columns as wide as what they hold, the
|
||||
/// first column taking the slack; numbers in mono, right-aligned when the head
|
||||
/// is; rows 24 px, a hairline between them; the head in the panel-title style.
|
||||
/// A cell whose text does not fit is cut, and shows all of it on hover.
|
||||
pub fn table(ui: &mut Ui, head: &[&str], rows: &[Vec<Cell>]) {
|
||||
let p = p(ui);
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let columns = head.len().max(rows.first().map_or(0, |row| row.len()));
|
||||
let pad = space::CELL_PAD;
|
||||
let title_font = theme::title_font();
|
||||
let mut natural: Vec<f32> = head
|
||||
.iter()
|
||||
.map(|text| {
|
||||
text_width(ui, &text.to_uppercase(), title_font.clone()) + 2.0 * pad
|
||||
+ text.chars().count() as f32 * space::TITLE_SPACING
|
||||
})
|
||||
.body_returned
|
||||
}
|
||||
|
||||
/// A message that must be noticed, in the colour of how bad it is.
|
||||
pub fn banner(ui: &mut Ui, text: impl Into<RichText>, color: Color32) {
|
||||
let mut text: RichText = text.into();
|
||||
text = text.strong();
|
||||
// As wide as there is room, minus a little: text that wraps measures itself a few
|
||||
// pixels wider, and a page that is told to fit exactly that wide grows each time.
|
||||
let width = ui.available_rect_before_wrap().width() - 2.0 * 8.0 - 6.0;
|
||||
egui::Frame::NONE
|
||||
.fill(color.gamma_multiply(0.22))
|
||||
.stroke(Stroke::new(1.0, color))
|
||||
.corner_radius(6.0)
|
||||
.inner_margin(8.0)
|
||||
.show(ui, |ui| {
|
||||
ui.set_min_width(width);
|
||||
ui.add(egui::Label::new(text).wrap());
|
||||
.collect();
|
||||
natural.resize(columns, 0.0);
|
||||
let mut galleys: Vec<Vec<(Option<Arc<Galley>>, String)>> = Vec::with_capacity(rows.len());
|
||||
for row in rows {
|
||||
let mut line = Vec::with_capacity(columns);
|
||||
for (column, cell) in row.iter().enumerate() {
|
||||
match cell {
|
||||
Cell::Marked(_, text) | Cell::Text(text) => {
|
||||
let galley = galley(ui, text.clone(), false, f32::INFINITY);
|
||||
let mark = if matches!(cell, Cell::Marked(..)) {
|
||||
theme::drawing::LEGEND_SWATCH + 6.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
natural[column] = natural[column].max(galley.size().x + 2.0 * pad + mark);
|
||||
line.push((Some(galley), text.text().to_owned()));
|
||||
}
|
||||
Cell::Bar(..) => {
|
||||
natural[column] = natural[column].max(theme::drawing::HIT_BAR + 2.0 * pad);
|
||||
line.push((None, String::new()));
|
||||
}
|
||||
}
|
||||
}
|
||||
galleys.push(line);
|
||||
}
|
||||
// The label column takes the slack, and gives first when the table is too
|
||||
// wide (after a bar column, which can shrink to a stub).
|
||||
let whole: f32 = natural.iter().sum();
|
||||
let slack = width - whole;
|
||||
if slack >= 0.0 {
|
||||
natural[0] += slack;
|
||||
} else {
|
||||
let bar = rows.first().and_then(|row| {
|
||||
row.iter().position(|cell| matches!(cell, Cell::Bar(..)))
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
let mut missing = -slack;
|
||||
if let Some(bar) = bar {
|
||||
let give = missing.min((natural[bar] - 28.0).max(0.0));
|
||||
natural[bar] -= give;
|
||||
missing -= give;
|
||||
}
|
||||
let give = missing.min((natural[0] - 2.0 * pad - space::LABEL_MIN).max(0.0));
|
||||
natural[0] -= give;
|
||||
missing -= give;
|
||||
if missing > 0.0 && whole > 0.0 {
|
||||
for size in &mut natural {
|
||||
*size -= missing * *size / whole;
|
||||
}
|
||||
}
|
||||
}
|
||||
let lefts: Vec<f32> = natural
|
||||
.iter()
|
||||
.scan(ui.cursor().left(), |left, size| {
|
||||
let at = *left;
|
||||
*left += size;
|
||||
Some(at)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let height = space::ROW * (rows.len() + usize::from(!head.is_empty())) as f32;
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, height), Sense::hover());
|
||||
let painter = ui.painter().with_clip_rect(rect);
|
||||
let cell_rect = |column: usize, top: f32| {
|
||||
Rect::from_min_max(
|
||||
Pos2::new(lefts[column], top),
|
||||
Pos2::new(lefts[column] + natural[column], top + space::ROW),
|
||||
)
|
||||
};
|
||||
let put = |ui: &mut Ui, place: Rect, galley: &Arc<Galley>, text: &str, right: bool, id: egui::Id| {
|
||||
let fits = galley.size().x + 2.0 * pad <= place.width() + 0.5;
|
||||
let x = if right { place.right() - pad - galley.size().x } else { place.left() + pad };
|
||||
let pos = Pos2::new(x, place.center().y - galley.size().y / 2.0);
|
||||
let clip = place.intersect(ui.clip_rect());
|
||||
ui.painter().with_clip_rect(clip).galley(pos, galley.clone(), p.text);
|
||||
if !fits {
|
||||
ui.interact(place, id, Sense::hover()).on_hover_text(text.to_owned());
|
||||
}
|
||||
};
|
||||
|
||||
let mut top = rect.top();
|
||||
if !head.is_empty() {
|
||||
for (column, text) in head.iter().enumerate() {
|
||||
let place = cell_rect(column, top);
|
||||
if text.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let galley = ui.painter().layout_no_wrap(text.to_uppercase(), title_font.clone(), p.muted);
|
||||
put(ui, place, &galley, text, column > 0, ui.scope_id().with(("head", column)));
|
||||
}
|
||||
painter.hline(rect.x_range(), top.round() + space::ROW + 0.5, Stroke::new(1.0, p.border));
|
||||
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 };
|
||||
for (index, (row, line)) in rows.iter().zip(&galleys).enumerate() {
|
||||
top = first + index as f32 * space::ROW;
|
||||
if index + 1 < rows.len() {
|
||||
painter.hline(rect.x_range(), top.round() + space::ROW + 0.5, Stroke::new(1.0, p.grid));
|
||||
}
|
||||
for (column, cell) in row.iter().enumerate() {
|
||||
let place = cell_rect(column, top);
|
||||
match cell {
|
||||
Cell::Text(_) => {
|
||||
let (galley, text) = &line[column];
|
||||
if let Some(galley) = galley {
|
||||
put(ui, place, galley, text, column > 0, ui.scope_id().with(("cell", index, column)));
|
||||
}
|
||||
}
|
||||
Cell::Marked(color, _) => {
|
||||
let side = theme::drawing::LEGEND_SWATCH;
|
||||
let square = Rect::from_center_size(
|
||||
Pos2::new(place.left() + pad + side / 2.0, place.center().y),
|
||||
egui::vec2(side, side),
|
||||
);
|
||||
ui.painter().rect_filled(square, 2.0, *color);
|
||||
let (galley, text) = &line[column];
|
||||
if let Some(galley) = galley {
|
||||
let text_place = Rect::from_min_max(
|
||||
Pos2::new(place.left() + pad + side + 6.0, place.top()),
|
||||
place.max,
|
||||
);
|
||||
put(ui, text_place, galley, text, false, ui.scope_id().with(("cell", index, column)));
|
||||
}
|
||||
}
|
||||
Cell::Bar(hits, misses) => {
|
||||
// As wide as its column, which shrinks before the text does.
|
||||
let bar = Rect::from_min_size(
|
||||
Pos2::new(place.left() + pad, place.center().y - theme::drawing::HIT_BAR_HEIGHT / 2.0),
|
||||
egui::vec2((place.width() - 2.0 * pad).max(0.0), theme::drawing::HIT_BAR_HEIGHT),
|
||||
);
|
||||
hit_bar(ui, bar, *hits, *misses);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A small coloured square in front of a legend entry.
|
||||
pub fn swatch(ui: &mut Ui, color: Color32) {
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(10.0, 10.0), Sense::hover());
|
||||
ui.painter().rect_filled(rect, 2.0, color);
|
||||
|
||||
/// A bar filled from the left to `fraction` of its width (0 to 1), always `height` tall.
|
||||
pub fn meter(ui: &mut Ui, height: f32, fraction: f64, fill: Color32) {
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, height), Sense::hover());
|
||||
fill_bar(ui, rect, fraction, fill);
|
||||
}
|
||||
|
||||
/// The same, in a rectangle already chosen.
|
||||
pub fn fill_bar(ui: &mut Ui, rect: Rect, fraction: f64, fill: Color32) {
|
||||
let p = p(ui);
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(rect, rect.height() / 2.0, p.track);
|
||||
let width = rect.width() * fraction.clamp(0.0, 1.0) as f32;
|
||||
if width > 0.5 {
|
||||
painter.rect_filled(
|
||||
Rect::from_min_max(rect.min, Pos2::new(rect.left() + width, rect.bottom())),
|
||||
rect.height() / 2.0,
|
||||
fill,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One bar split into coloured parts. The parts fill the whole width when
|
||||
/// their counts add up to `total`; a part with no count gets no width. What
|
||||
/// each part holds shows on hover.
|
||||
pub fn stacked_bar(ui: &mut Ui, parts: &[(&'static str, u64, Color32)], total: u64) {
|
||||
let p = p(ui);
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let (rect, response) = ui.allocate_exact_size(
|
||||
egui::vec2(width, theme::drawing::STACKED_BAR),
|
||||
Sense::hover(),
|
||||
);
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(rect, 3.0, p.track);
|
||||
let mut x = rect.left();
|
||||
let mut tip = String::new();
|
||||
for (name, part, color) in parts {
|
||||
let width = if total > 0 { rect.width() * *part as f64 as f32 / total as f32 } else { 0.0 };
|
||||
if width > 0.0 {
|
||||
let part_rect = Rect::from_min_max(Pos2::new(x, rect.top()), Pos2::new(x + width, rect.bottom()));
|
||||
painter.rect_filled(part_rect, 3.0, *color);
|
||||
x += width;
|
||||
tip.push_str(&format!(
|
||||
"{name}: {} ({})\n",
|
||||
crate::fmt::count(*part),
|
||||
crate::fmt::share(*part, total)
|
||||
));
|
||||
}
|
||||
}
|
||||
if !tip.is_empty() {
|
||||
response.on_hover_text(tip.trim_end());
|
||||
}
|
||||
}
|
||||
|
||||
/// A short bar showing hits (in the "from cache" colour) against misses.
|
||||
pub fn hit_bar(ui: &mut Ui, rect: Rect, hits: u64, misses: u64) {
|
||||
let p = p(ui);
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(rect, rect.height() / 2.0, p.track);
|
||||
let total = hits + misses;
|
||||
if total > 0 {
|
||||
let hit_width = rect.width() * hits as f32 / total as f32;
|
||||
painter.rect_filled(
|
||||
Rect::from_min_max(rect.min, Pos2::new(rect.left() + hit_width, rect.bottom())),
|
||||
rect.height() / 2.0,
|
||||
p.from_cache,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dot(ui: &mut Ui, color: Color32) {
|
||||
let side = theme::drawing::SEVERITY_DOT;
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(side, side), Sense::hover());
|
||||
ui.painter().circle_filled(rect.center(), side / 2.0, color);
|
||||
}
|
||||
|
||||
/// A trend line one point per bucket, drawn in a strip `height` tall. `None`
|
||||
/// points break the line, so a gap never looks like a zero. `top` is the value
|
||||
/// drawn at the top of the strip.
|
||||
pub fn sparkline(ui: &mut Ui, height: f32, values: &[Option<f64>], top: f64, color: Color32) {
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(ui.available_rect_before_wrap().width(), height), Sense::hover());
|
||||
let p = p(ui);
|
||||
let width = ui.available_rect_before_wrap().width();
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, height), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
painter.hline(
|
||||
rect.x_range(),
|
||||
rect.bottom() - 0.5,
|
||||
Stroke::new(1.0, ui.visuals().widgets.noninteractive.bg_stroke.color),
|
||||
);
|
||||
painter.hline(rect.x_range(), rect.bottom() - 0.5, Stroke::new(1.0, p.grid));
|
||||
if values.is_empty() || top <= 0.0 {
|
||||
return;
|
||||
}
|
||||
@@ -124,70 +579,6 @@ pub fn sparkline(ui: &mut Ui, height: f32, values: &[Option<f64>], top: f64, col
|
||||
flush(&mut run, painter);
|
||||
}
|
||||
|
||||
/// A bar filled from the left to `fraction` of its width (0 to 1), always `height` tall.
|
||||
pub fn meter(ui: &mut Ui, height: f32, fraction: f64, fill: Color32) {
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(ui.available_rect_before_wrap().width(), height), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
// An outline, so the empty track can be seen when the bar is nearly empty.
|
||||
painter.rect(
|
||||
rect,
|
||||
height / 2.0,
|
||||
ui.visuals().extreme_bg_color,
|
||||
ui.visuals().widgets.noninteractive.bg_stroke,
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
let width = (rect.width() * fraction.clamp(0.0, 1.0) as f32).min(rect.width());
|
||||
if width > 0.5 {
|
||||
painter.rect_filled(
|
||||
egui::Rect::from_min_max(rect.min, egui::pos2(rect.left() + width, rect.bottom())),
|
||||
height / 2.0,
|
||||
fill,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One bar split into coloured parts. The parts fill the whole width when
|
||||
/// their counts add up to `total`; a part with no count gets no width.
|
||||
pub fn stacked_bar(ui: &mut Ui, height: f32, parts: &[(&'static str, u64, Color32)], total: u64) {
|
||||
let (rect, response) = ui.allocate_exact_size(egui::vec2(ui.available_rect_before_wrap().width(), height), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(rect, 4.0, ui.visuals().extreme_bg_color);
|
||||
let mut x = rect.left();
|
||||
let mut tip = String::new();
|
||||
for (name, part, color) in parts {
|
||||
let width = if total > 0 {
|
||||
rect.width() * *part as f64 as f32 / total as f32
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
if width > 0.0 {
|
||||
let part_rect = egui::Rect::from_min_max(egui::pos2(x, rect.top()), egui::pos2(x + width, rect.bottom()));
|
||||
painter.rect_filled(part_rect, 4.0, *color);
|
||||
x += width;
|
||||
tip.push_str(&format!("{name}: {} ({})\n", crate::fmt::count(*part), crate::fmt::share(*part, total)));
|
||||
}
|
||||
}
|
||||
if !tip.is_empty() {
|
||||
response.clone().on_hover_text(tip.trim_end());
|
||||
}
|
||||
}
|
||||
|
||||
/// A short bar of fixed width showing hits against misses for one language.
|
||||
pub fn hit_bar(ui: &mut Ui, width: f32, hits: u64, misses: u64) {
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, 12.0), Sense::hover());
|
||||
let painter = ui.painter();
|
||||
painter.rect_filled(rect, 3.0, ui.visuals().extreme_bg_color);
|
||||
let total = hits + misses;
|
||||
if total > 0 {
|
||||
let hit_width = rect.width() * hits as f32 / total as f32;
|
||||
painter.rect_filled(
|
||||
egui::Rect::from_min_max(rect.min, egui::pos2(rect.left() + hit_width, rect.bottom())),
|
||||
3.0,
|
||||
CACHE,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a value between a tenth of a millisecond and 100 seconds sits on a
|
||||
/// scale that lets 0.7 ms and 8 s both be seen.
|
||||
pub fn log_fraction(ms: f64) -> f64 {
|
||||
@@ -200,67 +591,7 @@ pub fn log_fraction(ms: f64) -> f64 {
|
||||
position.clamp(0.02, 1.0)
|
||||
}
|
||||
|
||||
/// A cell of [`table_row`]: its width as a share of the row (0 to 1), or
|
||||
/// `f32::INFINITY` for the width that is left; which side its content lines up
|
||||
/// with; and what draws it.
|
||||
pub type Cell<'a> = (f32, egui::Align, Box<dyn FnOnce(&mut Ui) + 'a>);
|
||||
|
||||
/// Text in a cell, cut short if it is too long (or wrapped when `wrap` is set);
|
||||
/// the whole text shows on hover.
|
||||
pub fn text_cell(text: RichText, share: f32, right: bool, wrap: bool) -> Cell<'static> {
|
||||
let hover = text.text().to_owned();
|
||||
let align = if right { egui::Align::Max } else { egui::Align::Min };
|
||||
let draw = Box::new(move |ui: &mut Ui| {
|
||||
let label = egui::Label::new(text);
|
||||
let label = if wrap { label.wrap() } else { label.truncate() };
|
||||
ui.add(label).on_hover_text(hover);
|
||||
});
|
||||
(share, align, draw)
|
||||
}
|
||||
|
||||
/// The width an `f32::INFINITY` cell gets in a row whose other cells take `fixed` of the row.
|
||||
pub fn leftover(ui: &Ui, fixed: f32, cells: usize) -> f32 {
|
||||
let all = ui.available_rect_before_wrap().width();
|
||||
(all * (1.0 - fixed) - ROW_SPACING * cells as f32).max(0.0)
|
||||
}
|
||||
|
||||
pub const ROW_SPACING: f32 = 4.0;
|
||||
|
||||
/// One table row. Each cell sits at a fixed share of the row's width, so the
|
||||
/// columns line up across rows whatever the numbers are.
|
||||
pub fn table_row(ui: &mut Ui, cells: Vec<Cell<'_>>) {
|
||||
let line = ui.text_style_height(&egui::TextStyle::Body) + 2.0;
|
||||
let total = ui.available_rect_before_wrap().width();
|
||||
let fixed: f32 = cells
|
||||
.iter()
|
||||
.filter(|(share, _, _)| share.is_finite())
|
||||
.map(|(share, _, _)| *share)
|
||||
.sum::<f32>()
|
||||
.min(1.0);
|
||||
let rest = (total * (1.0 - fixed) - ROW_SPACING * cells.len() as f32).max(0.0);
|
||||
// The row is one exact rectangle, and every cell gets its own place in it.
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(total, line), Sense::hover());
|
||||
let mut row = ui.new_child(
|
||||
egui::UiBuilder::new()
|
||||
.max_rect(rect)
|
||||
.layout(Layout::left_to_right(Align::Center)),
|
||||
);
|
||||
let mut left = rect.left();
|
||||
for (share, align, draw) in cells {
|
||||
let width = if share.is_finite() { total * share } else { rest };
|
||||
let cell = egui::Rect::from_min_max(
|
||||
egui::pos2(left, rect.top()),
|
||||
egui::pos2(left + width, rect.bottom()),
|
||||
);
|
||||
let layout = match align {
|
||||
Align::Max => Layout::right_to_left(Align::Center),
|
||||
_ => Layout::left_to_right(Align::Center),
|
||||
};
|
||||
let mut cell = row.new_child(egui::UiBuilder::new().max_rect(cell).layout(layout));
|
||||
draw(&mut cell);
|
||||
left += width + ROW_SPACING;
|
||||
}
|
||||
}
|
||||
// ---- Chart keys ----
|
||||
|
||||
/// What an entry of a chart's key stands for.
|
||||
pub enum Mark {
|
||||
@@ -271,37 +602,44 @@ pub enum Mark {
|
||||
/// A dashed line: a reset.
|
||||
Dashed(Color32),
|
||||
/// Time nothing was recorded in.
|
||||
Band(bool),
|
||||
Band,
|
||||
}
|
||||
|
||||
/// The swatch for one entry of a chart's key.
|
||||
pub fn key(ui: &mut Ui, mark: Mark) {
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(16.0, 10.0), Sense::hover());
|
||||
let p = p(ui);
|
||||
let (rect, _) = ui.allocate_exact_size(
|
||||
egui::vec2(theme::drawing::KEY_SWATCH, theme::drawing::KEY_SWATCH),
|
||||
Sense::hover(),
|
||||
);
|
||||
let painter = ui.painter();
|
||||
let left = egui::pos2(rect.left(), rect.center().y);
|
||||
let right = egui::pos2(rect.right(), rect.center().y);
|
||||
let left = Pos2::new(rect.left(), rect.center().y);
|
||||
let right = Pos2::new(rect.right(), rect.center().y);
|
||||
match mark {
|
||||
Mark::Fill(color) => {
|
||||
painter.rect_filled(rect.shrink(1.0), 2.0, color);
|
||||
painter.rect_filled(rect.shrink(3.0), 2.0, color);
|
||||
}
|
||||
Mark::Line(color) => {
|
||||
painter.add(Shape::line(vec![left, right], Stroke::new(2.0, color)));
|
||||
}
|
||||
Mark::Dashed(color) => {
|
||||
painter.add(Shape::dashed_line(
|
||||
&[left, right],
|
||||
Stroke::new(1.5, color),
|
||||
4.0,
|
||||
3.0,
|
||||
));
|
||||
painter.add(Shape::dashed_line(&[left, right], Stroke::new(1.5, color), 4.0, 3.0));
|
||||
}
|
||||
Mark::Band(dark) => {
|
||||
let color = if dark {
|
||||
Color32::WHITE.gamma_multiply(0.14)
|
||||
} else {
|
||||
Color32::BLACK.gamma_multiply(0.12)
|
||||
};
|
||||
painter.rect_filled(rect.shrink(1.0), 2.0, color);
|
||||
Mark::Band => {
|
||||
painter.rect_filled(rect.shrink(3.0), 2.0, p.unrecorded);
|
||||
painter.rect_stroke(rect.shrink(3.0), 2.0, Stroke::new(1.0, p.border), StrokeKind::Inside);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The key to a chart, drawn under it so it never sits on the data.
|
||||
pub fn legend(ui: &mut Ui, entries: Vec<(Mark, String)>) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = space::PANEL_GAP + 2.0;
|
||||
for (mark, text) in entries {
|
||||
key(ui, mark);
|
||||
let response = ui.add(egui::Label::new(theme::small(ui, text.clone())).truncate());
|
||||
response.on_hover_text(text);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
//! Every colour, size, spacing and font of the page, in one place. A change of
|
||||
//! taste is an edit in this file and nowhere else.
|
||||
//!
|
||||
//! The type is Inter and JetBrains Mono (both under the SIL Open Font License;
|
||||
//! the licence files sit beside the font files in `assets/`).
|
||||
|
||||
use eframe::egui::{self, Color32, FontFamily, FontId, RichText, TextStyle};
|
||||
|
||||
pub static INTER_REGULAR_TTF: &[u8] = include_bytes!("../assets/Inter-Regular.ttf");
|
||||
pub static INTER_MEDIUM_TTF: &[u8] = include_bytes!("../assets/Inter-Medium.ttf");
|
||||
pub static INTER_SEMIBOLD_TTF: &[u8] = include_bytes!("../assets/Inter-SemiBold.ttf");
|
||||
pub static MONO_REGULAR_TTF: &[u8] = include_bytes!("../assets/JetBrainsMono-Regular.ttf");
|
||||
pub static MONO_MEDIUM_TTF: &[u8] = include_bytes!("../assets/JetBrainsMono-Medium.ttf");
|
||||
|
||||
const fn rgb(hex: u32) -> Color32 {
|
||||
Color32::from_rgb((hex >> 16) as u8, (hex >> 8) as u8, hex as u8)
|
||||
}
|
||||
|
||||
/// The colours of one theme. State colours (`good`, `warn`, `bad`) are used
|
||||
/// only for state; the series colours only for the five outcomes of a compile.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Palette {
|
||||
pub dark: bool,
|
||||
pub page: Color32,
|
||||
pub panel: Color32,
|
||||
pub border: Color32,
|
||||
pub text: Color32,
|
||||
pub muted: Color32,
|
||||
/// Hairlines inside a panel: between table rows and across a chart.
|
||||
pub grid: Color32,
|
||||
/// The recessed track of a bar, and of a control.
|
||||
pub track: Color32,
|
||||
/// A control under the pointer.
|
||||
pub hover: Color32,
|
||||
pub good: Color32,
|
||||
pub warn: Color32,
|
||||
pub bad: Color32,
|
||||
pub from_cache: Color32,
|
||||
pub built: Color32,
|
||||
pub not_cacheable: Color32,
|
||||
pub unsupported: Color32,
|
||||
pub not_compile: Color32,
|
||||
/// Selected controls.
|
||||
pub 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.
|
||||
pub mean: Color32,
|
||||
pub median: Color32,
|
||||
pub p90: Color32,
|
||||
}
|
||||
|
||||
pub const DARK: Palette = Palette {
|
||||
dark: true,
|
||||
page: rgb(0x0e1116),
|
||||
panel: rgb(0x161a22),
|
||||
border: rgb(0x232936),
|
||||
text: rgb(0xe6e9ef),
|
||||
muted: rgb(0x8a93a5),
|
||||
grid: rgb(0x1f2530),
|
||||
track: rgb(0x0b0e13),
|
||||
hover: rgb(0x1f2530),
|
||||
good: rgb(0x3fb950),
|
||||
warn: rgb(0xd29922),
|
||||
bad: rgb(0xf85149),
|
||||
from_cache: rgb(0x4cc38a),
|
||||
built: rgb(0x5b8def),
|
||||
not_cacheable: rgb(0x8a93a5),
|
||||
unsupported: rgb(0xb08cf0),
|
||||
not_compile: rgb(0x4fb3bf),
|
||||
accent: rgb(0x5b8def),
|
||||
unrecorded: Color32::from_rgba_premultiplied(14, 14, 14, 14),
|
||||
mean: rgb(0xe6e9ef),
|
||||
median: rgb(0xb08cf0),
|
||||
p90: rgb(0x4fb3bf),
|
||||
};
|
||||
|
||||
pub const LIGHT: Palette = Palette {
|
||||
dark: false,
|
||||
page: rgb(0xf5f6f8),
|
||||
panel: rgb(0xffffff),
|
||||
border: rgb(0xdfe3ea),
|
||||
text: rgb(0x1b2029),
|
||||
muted: rgb(0x5d6675),
|
||||
grid: rgb(0xeceff4),
|
||||
track: rgb(0xeef0f4),
|
||||
hover: rgb(0xf0f2f6),
|
||||
good: rgb(0x1a7f37),
|
||||
warn: rgb(0x9a6700),
|
||||
bad: rgb(0xcf222e),
|
||||
from_cache: rgb(0x2a9150),
|
||||
built: rgb(0x3a6fd8),
|
||||
not_cacheable: rgb(0x6b7484),
|
||||
unsupported: rgb(0x7c5cd6),
|
||||
not_compile: rgb(0x1f8a9b),
|
||||
accent: rgb(0x3a6fd8),
|
||||
unrecorded: Color32::from_rgba_premultiplied(0, 0, 0, 18),
|
||||
mean: rgb(0x1b2029),
|
||||
median: rgb(0x7c5cd6),
|
||||
p90: rgb(0x1f8a9b),
|
||||
};
|
||||
|
||||
/// The palette of the theme being drawn.
|
||||
pub fn of(dark: bool) -> &'static Palette {
|
||||
if dark {
|
||||
&DARK
|
||||
} else {
|
||||
&LIGHT
|
||||
}
|
||||
}
|
||||
|
||||
/// The palette of the theme `ctx` is drawing in.
|
||||
pub fn ctx(ctx: &egui::Context) -> &'static Palette {
|
||||
of(ctx.theme() == egui::Theme::Dark)
|
||||
}
|
||||
|
||||
/// The palette of the theme `ui` is drawing in.
|
||||
pub fn ui(ui: &egui::Ui) -> &'static Palette {
|
||||
ctx(ui.ctx())
|
||||
}
|
||||
|
||||
/// A colour made see-through: `color` over the panel at `share` of its strength.
|
||||
pub fn tint(color: Color32, share: f32) -> Color32 {
|
||||
let alpha = (share.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||
Color32::from_rgba_premultiplied(color.r(), color.g(), color.b(), alpha)
|
||||
}
|
||||
|
||||
/// Font sizes in pixels. There are no others.
|
||||
pub mod px {
|
||||
/// Panel titles, table heads and small labels: upper case, letter-spaced.
|
||||
pub const TITLE: f32 = 11.0;
|
||||
/// Text, and the controls.
|
||||
pub const BODY: f32 = 13.0;
|
||||
/// Small print.
|
||||
pub const SMALL: f32 = 11.0;
|
||||
/// The number on a stat card.
|
||||
pub const CARD_NUMBER: f32 = 24.0;
|
||||
/// The three figures of the headline panel.
|
||||
pub const HEADLINE: f32 = 40.0;
|
||||
}
|
||||
|
||||
/// Space in pixels.
|
||||
pub mod space {
|
||||
pub const PAGE_MARGIN: f32 = 16.0;
|
||||
/// Between panels, and between cards.
|
||||
pub const PANEL_GAP: f32 = 12.0;
|
||||
pub const PANEL_PADDING: f32 = 16.0;
|
||||
pub const CARD_PADDING: f32 = 12.0;
|
||||
pub const PANEL_RADIUS: f32 = 8.0;
|
||||
pub const CONTROL_RADIUS: f32 = 6.0;
|
||||
/// Between items that follow each other in a panel.
|
||||
pub const ITEM: f32 = 8.0;
|
||||
/// Between lines of one paragraph.
|
||||
pub const LINE: f32 = 3.0;
|
||||
/// One table row.
|
||||
pub const ROW: f32 = 24.0;
|
||||
/// Space either side of the text in a table cell.
|
||||
pub const CELL_PAD: f32 = 8.0;
|
||||
/// The narrowest the label column of a table gets before its text is cut.
|
||||
pub const LABEL_MIN: f32 = 72.0;
|
||||
pub const CONTROL_HEIGHT: f32 = 28.0;
|
||||
pub const CONTROL_PAD: f32 = 10.0;
|
||||
pub const TITLE_SPACING: f32 = 0.8;
|
||||
pub const TOOLBAR_NOTE_WIDTH: f32 = 150.0;
|
||||
/// Room under a title before the panel's content.
|
||||
pub const UNDER_TITLE: f32 = 8.0;
|
||||
/// Room between titled parts of one panel.
|
||||
pub const BETWEEN_PARTS: f32 = 14.0;
|
||||
}
|
||||
|
||||
/// How the page is laid out, in pixels of window width.
|
||||
pub mod layout {
|
||||
/// From this width the page has three columns of panels.
|
||||
pub const THREE_COLUMNS_FROM: f32 = 1100.0;
|
||||
/// From this width it has two; below it, one.
|
||||
pub const TWO_COLUMNS_FROM: f32 = 700.0;
|
||||
/// Below this width the toolbar's actions go on a second line.
|
||||
pub const TOOLBAR_TWO_LINES_BELOW: f32 = 1240.0;
|
||||
/// How many columns of key/value lines the raw counters run in, per page column.
|
||||
pub const RAW_LINE_WIDTH: f32 = 400.0;
|
||||
|
||||
pub const TOOLBAR_HEIGHT: f32 = 28.0;
|
||||
pub const HEADLINE_HEIGHT: f32 = 216.0;
|
||||
/// A headline figure: the number, its caption, the trend line and two lines of small print.
|
||||
pub const FIGURE_HEIGHT: f32 = 124.0;
|
||||
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;
|
||||
/// 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;
|
||||
/// 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;
|
||||
/// "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;
|
||||
}
|
||||
|
||||
/// Drawings inside panels, in pixels.
|
||||
pub mod drawing {
|
||||
pub const CHART_HEIGHT: f32 = 170.0;
|
||||
/// The trend line under a headline figure.
|
||||
pub const SPARKLINE: f32 = 28.0;
|
||||
pub const BUILD_HISTOGRAM: f32 = 44.0;
|
||||
pub const BUILD_AXIS: f32 = 14.0;
|
||||
pub const STACKED_BAR: f32 = 22.0;
|
||||
pub const SPEED_BAR: f32 = 10.0;
|
||||
pub const USAGE_BAR: f32 = 6.0;
|
||||
pub const HIT_BAR: f32 = 72.0;
|
||||
pub const HIT_BAR_HEIGHT: f32 = 6.0;
|
||||
pub const LEGEND_SWATCH: f32 = 10.0;
|
||||
pub const KEY_SWATCH: f32 = 14.0;
|
||||
pub const SEVERITY_DOT: f32 = 8.0;
|
||||
/// Share of the range's length left empty either side of a chart, so the
|
||||
/// first and last time label sit inside the plot.
|
||||
pub const CHART_SIDE_AIR: f64 = 0.035;
|
||||
}
|
||||
|
||||
/// A hit rate is good from this share of compiles, and worth a look from the next.
|
||||
pub mod state {
|
||||
pub const HIT_RATE_GOOD: f64 = 0.7;
|
||||
pub const HIT_RATE_WARN: f64 = 0.4;
|
||||
/// A cache this full is shown in the bad colour.
|
||||
pub const CACHE_FULL: f64 = 0.95;
|
||||
}
|
||||
|
||||
// The font families, by name.
|
||||
pub const REGULAR: &str = "inter-regular";
|
||||
pub const MEDIUM: &str = "inter-medium";
|
||||
pub const SEMIBOLD: &str = "inter-semibold";
|
||||
pub const MONO: &str = "jetbrains-mono";
|
||||
pub const MONO_MEDIUM: &str = "jetbrains-mono-medium";
|
||||
|
||||
// The text styles beyond egui's own, by name.
|
||||
pub const TITLE_STYLE: &str = "title";
|
||||
pub const CARD_STYLE: &str = "card-number";
|
||||
pub const HEADLINE_STYLE: &str = "headline-number";
|
||||
|
||||
pub fn medium_family() -> FontFamily {
|
||||
FontFamily::Name(MEDIUM.into())
|
||||
}
|
||||
|
||||
pub fn semibold_family() -> FontFamily {
|
||||
FontFamily::Name(SEMIBOLD.into())
|
||||
}
|
||||
|
||||
pub fn mono_medium_family() -> FontFamily {
|
||||
FontFamily::Name(MONO_MEDIUM.into())
|
||||
}
|
||||
|
||||
/// Text of `size` in Inter Medium.
|
||||
pub fn medium(size: f32) -> FontId {
|
||||
FontId::new(size, medium_family())
|
||||
}
|
||||
|
||||
/// Text of `size` in Inter SemiBold.
|
||||
pub fn semibold(size: f32) -> FontId {
|
||||
FontId::new(size, semibold_family())
|
||||
}
|
||||
|
||||
/// A number of `size`: JetBrains Mono Medium.
|
||||
pub fn number_font(size: f32) -> FontId {
|
||||
FontId::new(size, mono_medium_family())
|
||||
}
|
||||
|
||||
/// The font of panel titles and table heads.
|
||||
pub fn title_font() -> FontId {
|
||||
semibold(px::TITLE)
|
||||
}
|
||||
|
||||
fn families() -> egui::FontDefinitions {
|
||||
use std::sync::Arc;
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
for (name, data) in [
|
||||
(REGULAR, INTER_REGULAR_TTF),
|
||||
(MEDIUM, INTER_MEDIUM_TTF),
|
||||
(SEMIBOLD, INTER_SEMIBOLD_TTF),
|
||||
(MONO, MONO_REGULAR_TTF),
|
||||
(MONO_MEDIUM, MONO_MEDIUM_TTF),
|
||||
] {
|
||||
fonts
|
||||
.font_data
|
||||
.insert(name.to_owned(), Arc::new(egui::FontData::from_static(data)));
|
||||
}
|
||||
fonts
|
||||
.families
|
||||
.entry(FontFamily::Proportional)
|
||||
.or_default()
|
||||
.insert(0, REGULAR.to_owned());
|
||||
fonts
|
||||
.families
|
||||
.entry(FontFamily::Monospace)
|
||||
.or_default()
|
||||
.insert(0, MONO.to_owned());
|
||||
fonts
|
||||
.families
|
||||
.insert(medium_family(), vec![MEDIUM.to_owned()]);
|
||||
fonts
|
||||
.families
|
||||
.insert(semibold_family(), vec![SEMIBOLD.to_owned()]);
|
||||
fonts
|
||||
.families
|
||||
.insert(mono_medium_family(), vec![MONO_MEDIUM.to_owned()]);
|
||||
fonts
|
||||
}
|
||||
|
||||
fn text_styles() -> std::collections::BTreeMap<TextStyle, FontId> {
|
||||
[
|
||||
(TextStyle::Small, FontId::proportional(px::SMALL)),
|
||||
(TextStyle::Body, FontId::proportional(px::BODY)),
|
||||
(TextStyle::Button, medium(px::BODY)),
|
||||
(TextStyle::Heading, semibold(px::BODY)),
|
||||
(TextStyle::Monospace, FontId::monospace(px::BODY)),
|
||||
(TextStyle::Name(TITLE_STYLE.into()), title_font()),
|
||||
(
|
||||
TextStyle::Name(CARD_STYLE.into()),
|
||||
number_font(px::CARD_NUMBER),
|
||||
),
|
||||
(
|
||||
TextStyle::Name(HEADLINE_STYLE.into()),
|
||||
number_font(px::HEADLINE),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn visuals(p: &Palette) -> egui::Visuals {
|
||||
use egui::style::WidgetVisuals;
|
||||
use egui::{CornerRadius, Stroke};
|
||||
let mut visuals = if p.dark {
|
||||
egui::Visuals::dark()
|
||||
} else {
|
||||
egui::Visuals::light()
|
||||
};
|
||||
visuals.override_text_color = Some(p.text);
|
||||
visuals.panel_fill = p.page;
|
||||
visuals.window_fill = p.panel;
|
||||
visuals.window_stroke = Stroke::new(1.0, p.border);
|
||||
visuals.extreme_bg_color = p.track;
|
||||
visuals.faint_bg_color = p.hover;
|
||||
visuals.selection.bg_fill = tint(p.accent, 0.35);
|
||||
visuals.selection.stroke = Stroke::new(1.0, p.accent);
|
||||
visuals.hyperlink_color = p.accent;
|
||||
visuals.warn_fg_color = p.warn;
|
||||
visuals.error_fg_color = p.bad;
|
||||
|
||||
let control = |fill, stroke, text: Color32| WidgetVisuals {
|
||||
corner_radius: CornerRadius::same(space::CONTROL_RADIUS as u8),
|
||||
bg_fill: fill,
|
||||
weak_bg_fill: fill,
|
||||
bg_stroke: Stroke::new(1.0, stroke),
|
||||
fg_stroke: Stroke::new(1.0, text),
|
||||
expansion: 0.0,
|
||||
};
|
||||
visuals.widgets.noninteractive = control(p.track, p.border, p.muted);
|
||||
visuals.widgets.inactive = control(p.track, p.border, p.text);
|
||||
visuals.widgets.hovered = control(p.hover, p.accent, p.text);
|
||||
visuals.widgets.active = control(tint(p.accent, 0.25), p.accent, p.text);
|
||||
visuals.widgets.open = control(p.hover, p.accent, p.text);
|
||||
visuals
|
||||
}
|
||||
|
||||
/// Put the fonts, text styles, spacing and both themes' colours on the page.
|
||||
pub fn install(ctx: &egui::Context) {
|
||||
ctx.set_fonts(families());
|
||||
ctx.all_styles_mut(|style| {
|
||||
style.text_styles = text_styles();
|
||||
style.spacing.item_spacing = egui::vec2(space::ITEM, space::LINE);
|
||||
style.spacing.button_padding = egui::vec2(10.0, 4.0);
|
||||
style.spacing.indent = 12.0;
|
||||
style.visuals = visuals(of(style.visuals.dark_mode));
|
||||
});
|
||||
}
|
||||
|
||||
/// A panel title: 11 px, upper case, letter-spaced, muted.
|
||||
pub fn title(scope: &egui::Ui, text: impl AsRef<str>) -> RichText {
|
||||
RichText::new(text.as_ref().to_uppercase())
|
||||
.font(title_font())
|
||||
.color(ui(scope).muted)
|
||||
.extra_letter_spacing(space::TITLE_SPACING)
|
||||
}
|
||||
|
||||
/// Small print in the muted colour.
|
||||
pub fn small(scope: &egui::Ui, text: impl Into<String>) -> RichText {
|
||||
RichText::new(text.into())
|
||||
.font(FontId::proportional(px::SMALL))
|
||||
.color(ui(scope).muted)
|
||||
}
|
||||
|
||||
/// Text in the body size.
|
||||
pub fn body(text: impl Into<String>) -> RichText {
|
||||
RichText::new(text.into()).font(FontId::proportional(px::BODY))
|
||||
}
|
||||
|
||||
/// Text in the body size, a little heavier.
|
||||
pub fn strong(text: impl Into<String>) -> RichText {
|
||||
RichText::new(text.into()).font(semibold(px::BODY))
|
||||
}
|
||||
|
||||
/// A number in the body size, in the mono font.
|
||||
pub fn number(text: impl Into<String>) -> RichText {
|
||||
RichText::new(text.into()).font(number_font(px::BODY))
|
||||
}
|
||||
|
||||
/// The colour of a hit rate: good, worth a look, or bad.
|
||||
pub fn hit_rate_color(rate: Option<f64>, p: &Palette) -> Color32 {
|
||||
match rate {
|
||||
Some(rate) if rate >= state::HIT_RATE_GOOD => p.good,
|
||||
Some(rate) if rate >= state::HIT_RATE_WARN => p.warn,
|
||||
Some(_) => p.bad,
|
||||
None => p.muted,
|
||||
}
|
||||
}
|
||||
|
||||
/// How many columns of panels the page has at `width`.
|
||||
pub fn columns(width: f32) -> usize {
|
||||
if width >= layout::THREE_COLUMNS_FROM {
|
||||
3
|
||||
} else if width >= layout::TWO_COLUMNS_FROM {
|
||||
2
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
+97
-122
@@ -1,143 +1,118 @@
|
||||
//! Where compiles went: one bar split by outcome, what happened inside the
|
||||
//! built share, why some could not be cached, and how each language fared.
|
||||
//! Where compiles went: one bar split by outcome, with a legend of counts and
|
||||
//! shares; what happened inside the built share; and why some could not be
|
||||
//! cached. How each language fared is its own panel ([`languages`]).
|
||||
|
||||
use eframe::egui::{self, RichText, Ui};
|
||||
use eframe::egui::{self, Color32, Ui};
|
||||
use sccache_dash_api::View;
|
||||
|
||||
use crate::fmt;
|
||||
use crate::style;
|
||||
use crate::style::{self, Cell};
|
||||
use crate::theme;
|
||||
|
||||
pub fn section(ui: &mut Ui, view: &View, _dark: bool) {
|
||||
pub fn section(ui: &mut Ui, view: &View) {
|
||||
let totals = &view.totals;
|
||||
let p = theme::ui(ui);
|
||||
// Five shares of every compiler call; timeouts, cache errors and forced
|
||||
// recaches are inside the built share, as sccache counts them.
|
||||
let parts: [(&'static str, u64, egui::Color32); 5] = [
|
||||
("From cache", totals.hits, style::CACHE),
|
||||
("Built", totals.misses, style::BUILT),
|
||||
("Not cacheable", totals.not_cacheable, style::NOT_CACHEABLE),
|
||||
("Unsupported compiler", totals.unsupported_compiler, style::UNSUPPORTED),
|
||||
("Not a compile", totals.not_compile, style::NOT_COMPILE),
|
||||
let parts: [(&'static str, u64, Color32); 5] = [
|
||||
("From cache", totals.hits, p.from_cache),
|
||||
("Built", totals.misses, p.built),
|
||||
("Not cacheable", totals.not_cacheable, p.not_cacheable),
|
||||
("Unsupported compiler", totals.unsupported_compiler, p.unsupported),
|
||||
("Not a compile", totals.not_compile, p.not_compile),
|
||||
];
|
||||
let all: u64 = parts.iter().map(|(_, count, _)| count).sum();
|
||||
let percents = fmt::shares(&parts.iter().map(|(_, count, _)| *count).collect::<Vec<_>>());
|
||||
|
||||
style::section(ui, "where", "Where compiles went", |ui| {
|
||||
style::stacked_bar(ui, 22.0, &parts, all);
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for ((name, count, color), percent) in parts.iter().zip(&percents) {
|
||||
style::swatch(ui, *color);
|
||||
ui.label(*name);
|
||||
ui.label(
|
||||
RichText::new(format!("{} · {percent}%", fmt::count(*count))).weak(),
|
||||
);
|
||||
ui.add_space(8.0);
|
||||
}
|
||||
});
|
||||
ui.add(
|
||||
egui::Label::new(format!(
|
||||
style::stacked_bar(ui, &parts, all);
|
||||
ui.add_space(6.0);
|
||||
let legend: Vec<Vec<Cell>> = parts
|
||||
.iter()
|
||||
.zip(&percents)
|
||||
.map(|((name, count, color), percent)| {
|
||||
vec![
|
||||
Cell::Marked(*color, theme::body(*name)),
|
||||
Cell::Text(theme::number(fmt::count(*count))),
|
||||
Cell::Text(theme::number(format!("{percent}%"))),
|
||||
]
|
||||
})
|
||||
.collect();
|
||||
style::table(ui, &[], &legend);
|
||||
|
||||
ui.add_space(theme::space::ITEM);
|
||||
ui.add(egui::Label::new(
|
||||
theme::small(
|
||||
ui,
|
||||
format!(
|
||||
"Of the built: {} timeouts, {} cache errors, {} forced recaches, {} failed to compile",
|
||||
fmt::count(totals.timeouts),
|
||||
fmt::count(totals.errors()),
|
||||
fmt::count(totals.forced_recaches),
|
||||
fmt::count(totals.compile_fails)
|
||||
))
|
||||
.wrap(),
|
||||
);
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
if !view.not_cached.is_empty() {
|
||||
ui.add_space(6.0);
|
||||
ui.label(RichText::new("Why compiles could not be cached").strong());
|
||||
let heading = |text: &'static str, share: f32, right: bool| {
|
||||
style::text_cell(RichText::new(text).small().weak(), share, right, false)
|
||||
};
|
||||
style::table_row(
|
||||
ui,
|
||||
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![
|
||||
heading("Reason", f32::INFINITY, false),
|
||||
heading("Compiles", 0.16, true),
|
||||
heading("Share", 0.12, true),
|
||||
],
|
||||
);
|
||||
for (reason, count) in &view.not_cached {
|
||||
style::table_row(
|
||||
ui,
|
||||
vec![
|
||||
style::text_cell(RichText::new(reason.as_str()), f32::INFINITY, false, false),
|
||||
style::text_cell(RichText::new(fmt::count(*count)), 0.16, true, false),
|
||||
style::text_cell(
|
||||
RichText::new(fmt::share(*count, totals.not_cacheable)),
|
||||
0.12,
|
||||
true,
|
||||
false,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if !view.languages.is_empty() {
|
||||
ui.add_space(6.0);
|
||||
ui.label(RichText::new("By language").strong());
|
||||
languages(ui, view);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Column shares for the language table: name, hits, misses, errors, hit rate.
|
||||
/// The bar takes what is left, so the columns line up at every width.
|
||||
const LANGUAGE_COLUMNS: [f32; 5] = [0.2, 0.16, 0.16, 0.13, 0.12];
|
||||
|
||||
/// One row per language: hits, misses, errors, hit rate and a small bar.
|
||||
fn languages(ui: &mut Ui, view: &View) {
|
||||
let dark = ui.visuals().dark_mode;
|
||||
let text_color = ui.visuals().text_color();
|
||||
let [_, _, bad] = style::marks(dark);
|
||||
let [name, hits, misses, errors, rate] = LANGUAGE_COLUMNS;
|
||||
let bar = style::leftover(ui, LANGUAGE_COLUMNS.iter().sum(), 6) - style::ROW_SPACING;
|
||||
let heading = |text: &'static str, share: f32, right: bool| {
|
||||
style::text_cell(RichText::new(text).small().weak(), share, right, false)
|
||||
};
|
||||
style::table_row(
|
||||
ui,
|
||||
vec![
|
||||
heading("", name, false),
|
||||
heading("Hits", hits, true),
|
||||
heading("Misses", misses, true),
|
||||
heading("Errors", errors, true),
|
||||
heading("Hit rate", rate, true),
|
||||
(f32::INFINITY, egui::Align::Min, Box::new(|_ui| {})),
|
||||
],
|
||||
);
|
||||
for language in &view.languages {
|
||||
let language_rate = crate::overtime::hit_rate(language.hits, language.misses);
|
||||
let (language_hits, language_misses) = (language.hits, language.misses);
|
||||
style::table_row(
|
||||
ui,
|
||||
vec![
|
||||
style::text_cell(RichText::new(&language.name).strong(), name, false, false),
|
||||
style::text_cell(RichText::new(fmt::count(language.hits)), hits, true, false),
|
||||
style::text_cell(RichText::new(fmt::count(language.misses)), misses, true, false),
|
||||
style::text_cell(
|
||||
RichText::new(fmt::count(language.errors))
|
||||
.color(if language.errors > 0 { bad } else { text_color }),
|
||||
errors,
|
||||
true,
|
||||
false,
|
||||
),
|
||||
style::text_cell(
|
||||
RichText::new(fmt::percent(language_rate))
|
||||
.color(style::hit_rate_color(language_rate, dark)),
|
||||
rate,
|
||||
true,
|
||||
false,
|
||||
),
|
||||
(
|
||||
f32::INFINITY,
|
||||
egui::Align::Min,
|
||||
Box::new(move |ui| style::hit_bar(ui, bar, language_hits, language_misses)),
|
||||
),
|
||||
],
|
||||
);
|
||||
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
|
||||
}
|
||||
|
||||
/// "By language": one row per language, with hits, misses, errors, the hit rate
|
||||
/// in its state colour, and a bar of hits against misses.
|
||||
pub fn languages(ui: &mut Ui, view: &View) {
|
||||
if view.languages.is_empty() {
|
||||
ui.label(theme::small(ui, "No compiles were counted in this range."));
|
||||
return;
|
||||
}
|
||||
let p = theme::ui(ui);
|
||||
// The bar is the first thing to go where the columns are too tight to leave it room.
|
||||
let with_bars = ui.available_rect_before_wrap().width() >= theme::layout::LANGUAGE_BARS_FROM;
|
||||
let mut head = vec!["", "Hits", "Misses", "Errors", "Hit rate"];
|
||||
if with_bars {
|
||||
head.push("");
|
||||
}
|
||||
let mut rows: Vec<Vec<Cell>> = view
|
||||
.languages
|
||||
.iter()
|
||||
.map(|language| {
|
||||
let rate = crate::overtime::hit_rate(language.hits, language.misses);
|
||||
vec![
|
||||
Cell::Text(theme::strong(language.name.clone())),
|
||||
Cell::Text(theme::number(fmt::count(language.hits))),
|
||||
Cell::Text(theme::number(fmt::count(language.misses))),
|
||||
Cell::Text(
|
||||
theme::number(fmt::count(language.errors))
|
||||
.color(if language.errors > 0 { p.bad } else { p.text }),
|
||||
),
|
||||
Cell::Text(
|
||||
theme::number(fmt::percent(rate)).color(theme::hit_rate_color(rate, p)),
|
||||
),
|
||||
]
|
||||
})
|
||||
.collect();
|
||||
if with_bars {
|
||||
for (row, language) in rows.iter_mut().zip(&view.languages) {
|
||||
row.push(Cell::Bar(language.hits, language.misses));
|
||||
}
|
||||
}
|
||||
style::table(ui, &head, &rows);
|
||||
}
|
||||
Reference in new issue
Block a user