Files
dawnline/web/src/admin/widgets/meter.ts
T
Aemeath 18e3013047
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
Dawnline 0.17.0
- Redraw the admin's charts in the connection map's style: the live speed as lines, the last 30 days and a device's week as stacked download and upload bars, a device's days as a strip, data use as meters.
- Read any chart point by point with the pointer, a tap or the arrow keys; a day's tooltip compares it with the average and shows its download and upload.
- Show where a data limit leads at the recent pace: the week ahead on the meter, and when the limit fills or what a monthly one reaches by the reset.
- Make Speed now live, one point a second, on a person's page, in the People list and in an online person's card.
- Name every place an online person's devices connect from, and the city each device connects from now.
- Portal: read the month and the week by tap or arrow keys, see how a day compares with the others, the pace toward the data limit and how long the allowed hours still run.
- Send VPN clients' DNS to the LAN's DNS after its interceptors, so transparent proxies such as forkop also handle their lookups.
2026-11-02 09:48:31 +03:00

43 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// A usage meter in the connection map's language (the device panel's places
// strip): a 6 px track and a rounded fill, live blue, orange when nearly full,
// red when full. Past the fill, dashed like an arc, where a week at the recent
// pace takes it (shared/pace.ts). The alert level is the replay's tick. Without a
// limit, the month split by device: a rounded segment each (c0–c4, the swatch
// colours), a gap between. Tooltips are the caller's (ui/glide.ts pointTip).
type MeterTone = 'live' | 'warn' | 'bad';
/** The tone for a share used: full at 100%, nearly full from 90%. */
const toneOf = (pct: number): MeterTone => (pct >= 100 ? 'bad' : pct >= 90 ? 'warn' : 'live');
/** `pct` used of the limit; `ahead`: where a week at this pace takes it (both 0–100); `mark`: the alert (0–1). */
export function limitMeter(pct: number, ahead = 0, mark?: number): HTMLElement {
const el = document.createElement('div');
el.className = `dl-smeter ${toneOf(pct)}`;
const fill = el.appendChild(document.createElement('i'));
fill.style.width = `${pct}%`;
if (ahead > pct) {
const dash = el.appendChild(document.createElement('b'));
dash.style.left = `${pct}%`;
dash.style.width = `${ahead - pct}%`;
}
if (mark != null) {
const m = el.appendChild(document.createElement('span'));
m.className = 'mark';
m.style.left = `${mark * 100}%`;
}
return el;
}
/** The month split by device, largest first (values in bytes; colours c0–c4 in that order). */
export function splitMeter(values: number[]): HTMLElement {
const el = document.createElement('div');
el.className = 'dl-smeter parts';
values.forEach((v, i) => {
const seg = el.appendChild(document.createElement('i'));
seg.className = `c${Math.min(i, 4)}`;
seg.style.flexGrow = String(v);
});
return el;
}