Windows 0.3.3 dashboard layout and speed presentation source delta; no private history or other platform changes

This commit is contained in:
2026-11-03 15:15:23 +00:00
parent bfe8d6c62a
commit aff1a50d35
32 changed files with 1673 additions and 652 deletions
+44 -11
View File
@@ -137,37 +137,70 @@ internal sealed class TrafficChartTimeline
}
}
// Pure axis description keeps the labels and plotted byte scale consistent.
internal readonly record struct ChartAxisY(double UnitBytes, string UnitText, double MaximumUnits, bool Speed)
{
internal double MaximumBytes => MaximumUnits * UnitBytes;
internal string Tick(double value) => Speed ? SpeedDisplay.Number(value) : value.ToString("0.#");
internal string UpperLimitLabel => "上限 " + Tick(MaximumUnits);
internal static ChartAxisY Create(double peak, bool speed)
{
if (!double.IsFinite(peak) || peak < 0) peak = 0;
double unit;
string unitName;
if (speed) (unit, unitName) = SpeedDisplay.UnitFor(peak);
else
{
unit = peak >= 1024d * 1024 * 1024 ? 1024d * 1024 * 1024 : peak >= 1024d * 1024 ? 1024d * 1024 : peak >= 1024 ? 1024d : 1d;
unitName = unit >= 1024d * 1024 * 1024 ? "GB" : unit >= 1024d * 1024 ? "MB" : unit >= 1024 ? "KB" : "B";
}
var raw = Math.Max(1, peak / unit) * 1.15;
var power = Math.Pow(10, Math.Floor(Math.Log10(raw)));
var normal = raw / power;
var maximum = (normal <= 1 ? 1 : normal <= 2 ? 2 : normal <= 2.5 ? 2.5 : normal <= 5 ? 5 : 10) * power;
return new(unit, unitName, maximum, speed);
}
}
internal static class ChartAxis
{
internal const TextFormatFlags PaintFlags = TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping;
internal static (RectangleF Plot, double Maximum) Draw(Graphics g, Rectangle bounds, Font font, int dpi, double peak, bool speed)
{
var scale = dpi / 96f;
var unit = peak >= 1024d * 1024 * 1024 ? 1024d * 1024 * 1024 : peak >= 1024d * 1024 ? 1024d * 1024 : peak >= 1024 ? 1024d : 1d;
var unitName = unit >= 1024d * 1024 * 1024 ? "GB" : unit >= 1024d * 1024 ? "MB" : unit >= 1024 ? "KB" : "B";
var raw = Math.Max(1, peak / unit) * 1.15;
var power = Math.Pow(10, Math.Floor(Math.Log10(raw)));
var normal = raw / power;
var maximum = (normal <= 1 ? 1 : normal <= 2 ? 2 : normal <= 2.5 ? 2.5 : normal <= 5 ? 5 : 10) * power;
var axis = ChartAxisY.Create(peak, speed);
var maximum = axis.MaximumUnits;
var fontHeight = TextRenderer.MeasureText(g, "0", font).Height;
var left = Math.Max(31 * scale, TextRenderer.MeasureText(g, maximum.ToString("0.#"), font).Width + 5 * scale);
var plot = new RectangleF(left, fontHeight + 1, Math.Max(1, bounds.Width - left - 9 * scale), Math.Max(1, bounds.Height - fontHeight * 2 - 7 * scale));
// In the compact dashboard the heading and range occupy their own
// left rail. Keep the vertical budget for the curve; units and the
// explicitly captioned upper limit stay inside the axis gutter rather
// than costing a top row. A bare maximum below the top gridline looks
// like a tick at the wrong height, so label this as scale metadata.
var denseSpeed = speed && bounds.Height < 82 * scale;
var left = Math.Max(31 * scale, TextRenderer.MeasureText(g,
denseSpeed ? axis.UpperLimitLabel : axis.Tick(maximum), font).Width + 5 * scale);
var plot = denseSpeed
? new RectangleF(left, 2 * scale, Math.Max(1, bounds.Width - left - 9 * scale), Math.Max(1, bounds.Height - fontHeight - 5 * scale))
: new RectangleF(left, fontHeight + 1, Math.Max(1, bounds.Width - left - 9 * scale), Math.Max(1, bounds.Height - fontHeight * 2 - 7 * scale));
g.SmoothingMode = SmoothingMode.AntiAlias;
var compactAxis = plot.Height < fontHeight * 3;
TextRenderer.DrawText(g, unitName + (speed ? "/s" : "") + (compactAxis ? $" · {maximum:0.#}" : ""), font, new Rectangle(0, 0, bounds.Width, fontHeight), Brand.Muted, PaintFlags | TextFormatFlags.NoPadding);
TextRenderer.DrawText(g, axis.UnitText + (compactAxis && !denseSpeed ? " · " + axis.Tick(maximum) : ""), font,
new Rectangle(0, 0, denseSpeed ? (int)left : bounds.Width, fontHeight), Brand.Muted, PaintFlags | TextFormatFlags.NoPadding);
if(denseSpeed) TextRenderer.DrawText(g, axis.UpperLimitLabel, font, new Rectangle(0, fontHeight, (int)left-4, fontHeight),
Brand.Muted, PaintFlags | TextFormatFlags.Right | TextFormatFlags.NoPadding);
using var grid = new Pen(Color.FromArgb(218, 230, 245), Math.Max(1, scale * .6f)) { DashStyle = DashStyle.Dash };
for (var i = 0; i <= 2; i++)
{
var y = plot.Bottom - plot.Height * i / 2;
g.DrawLine(grid, plot.Left, y, plot.Right, y);
if (!compactAxis || i == 0) TextRenderer.DrawText(g, (maximum * i / 2).ToString("0.#"), font, new Rectangle(0, (int)y - fontHeight / 2, (int)left - 4, fontHeight), Brand.Muted, PaintFlags | TextFormatFlags.Right | TextFormatFlags.NoPadding);
if (denseSpeed ? i == 0 : !compactAxis || i == 0) TextRenderer.DrawText(g, axis.Tick(maximum * i / 2), font, new Rectangle(0, (int)y - fontHeight / 2, (int)left - 4, fontHeight), Brand.Muted, PaintFlags | TextFormatFlags.Right | TextFormatFlags.NoPadding);
}
for (var i = 0; i <= 6; i++)
{
var x = plot.Left + plot.Width * i / 6;
g.DrawLine(grid, x, plot.Top, x, plot.Bottom);
}
return (plot, maximum * unit);
return (plot, axis.MaximumBytes);
}
internal static void TimeLabels(Graphics g, RectangleF plot, Font font, string[] labels)