fix: add headroom to dashboard bar scales
This commit is contained in:
1 parent
ed456e6a5d
commit
63b387f679
5 files changed
+96
-10
No files matched your search
+26
-6
@@ -1385,8 +1385,24 @@ function renderOperationsDashboardSummary() {
|
||||
}
|
||||
}
|
||||
|
||||
function operationsDashboardRankBar(total, maximum) {
|
||||
const safeMaximum = Math.max(1, Number(maximum || 0));
|
||||
function operationsDashboardRankScale(maximum) {
|
||||
const numericMaximum = Number(maximum || 0);
|
||||
const safeMaximum = Number.isFinite(numericMaximum) ? Math.max(0, numericMaximum) : 0;
|
||||
if (safeMaximum <= 0) return 1;
|
||||
|
||||
const roughStep = safeMaximum / 5;
|
||||
const magnitude = 10 ** Math.floor(Math.log10(Math.max(1, roughStep)));
|
||||
const normalizedStep = roughStep / magnitude;
|
||||
const niceStep = Math.max(
|
||||
1,
|
||||
(normalizedStep <= 1 ? 1 : normalizedStep <= 2 ? 2 : normalizedStep <= 5 ? 5 : 10) * magnitude
|
||||
);
|
||||
const roundedMaximum = Math.ceil(safeMaximum / niceStep) * niceStep;
|
||||
return roundedMaximum <= safeMaximum ? roundedMaximum + niceStep : roundedMaximum;
|
||||
}
|
||||
|
||||
function operationsDashboardRankBar(total, scaleMaximum) {
|
||||
const safeMaximum = Math.max(1, Number(scaleMaximum || 0));
|
||||
const safeTotal = Math.max(0, Number(total || 0));
|
||||
const bar = el('span', 'operations-dashboard-rank-bar');
|
||||
bar.setAttribute('aria-hidden', 'true');
|
||||
@@ -1408,7 +1424,9 @@ function renderOperationsDashboardBusinesses() {
|
||||
container.append(el('p', 'operations-dashboard-empty', '当前范围内还没有任务类型数据。'));
|
||||
return;
|
||||
}
|
||||
const maximum = Math.max(...businesses.map((item) => Number(item.total || 0)), 1);
|
||||
const scaleMaximum = operationsDashboardRankScale(
|
||||
Math.max(...businesses.map((item) => Number(item.total || 0)), 0)
|
||||
);
|
||||
for (const [index, item] of businesses.entries()) {
|
||||
const button = el('button', 'operations-dashboard-business-row');
|
||||
button.type = 'button';
|
||||
@@ -1418,7 +1436,7 @@ function renderOperationsDashboardBusinesses() {
|
||||
el('span', 'operations-dashboard-rank-number', String(index + 1).padStart(2, '0')),
|
||||
el('strong', 'operations-dashboard-rank-name', operationsDashboardBusinessLabel(item.label))
|
||||
);
|
||||
button.prepend(operationsDashboardRankBar(item.total, maximum));
|
||||
button.prepend(operationsDashboardRankBar(item.total, scaleMaximum));
|
||||
const metrics = el('span', 'operations-dashboard-rank-metrics');
|
||||
metrics.append(
|
||||
el('span', 'is-total', `操作 ${Number(item.total || 0)}`),
|
||||
@@ -1444,7 +1462,9 @@ function renderOperationsDashboardUsers() {
|
||||
container.append(el('p', 'operations-dashboard-empty', '当前范围内还没有人员工作数据。'));
|
||||
return;
|
||||
}
|
||||
const maximum = Math.max(...users.map((item) => Number(item.total || 0)), 1);
|
||||
const scaleMaximum = operationsDashboardRankScale(
|
||||
Math.max(...users.map((item) => Number(item.total || 0)), 0)
|
||||
);
|
||||
for (const [index, item] of users.entries()) {
|
||||
const button = el('button', 'operations-dashboard-user-row');
|
||||
button.type = 'button';
|
||||
@@ -1460,7 +1480,7 @@ function renderOperationsDashboardUsers() {
|
||||
el('strong', '', item.actor.username),
|
||||
el('small', '', accountRoleLabel(item.actor.role))
|
||||
);
|
||||
const bar = operationsDashboardRankBar(item.total, maximum);
|
||||
const bar = operationsDashboardRankBar(item.total, scaleMaximum);
|
||||
const metrics = el('div', 'operations-dashboard-user-metrics');
|
||||
metrics.append(
|
||||
el('span', 'is-total', `操作 ${Number(item.total || 0)}`),
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#edf2f4">
|
||||
<title>AI操作台 · LianSyn-platform</title>
|
||||
<link rel="stylesheet" href="styles.css?v=20260902-dashboard-bar-chart-1">
|
||||
<link rel="stylesheet" href="styles.css?v=20260902-dashboard-nice-scale-1">
|
||||
</head>
|
||||
<body>
|
||||
<main class="app-shell">
|
||||
@@ -397,6 +397,6 @@
|
||||
</section>
|
||||
|
||||
</main>
|
||||
<script src="app.js?v=20260902-dashboard-bar-chart-1"></script>
|
||||
<script src="app.js?v=20260902-dashboard-nice-scale-1"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user