Files
telemt-api/web/src/lib/kpi-trend-math.ts
T
Denozordec 89b6cc5185
Publish telemt-api gateway Docker image / test (push) Successful in 25s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m25s
Enhance Mihomo overview charts component with improved theming and chart management
- Integrated dynamic theming for chart colors using a centralized theme file, enhancing visual consistency across charts.
- Refactored chart initialization logic to ensure proper destruction and recreation of charts on data updates, improving performance and responsiveness.
- Updated chart options to utilize theme colors for grid, ticks, and legends, providing a more cohesive user experience.
2026-03-31 18:37:03 +07:00

24 lines
1.1 KiB
TypeScript

/** Доля изменения для тренд-бейджа; null если сравнивать не с чем. */
export function percentChange(prev: number, cur: number): number | null {
if (!Number.isFinite(prev) || !Number.isFinite(cur)) return null;
if (prev === 0 && cur === 0) return null;
if (prev === 0) return cur === 0 ? null : null; // избегаем бесконечного %; покажем только направление отдельно
const p = ((cur - prev) / Math.abs(prev)) * 100;
return Number.isFinite(p) ? p : null;
}
/** Для prev===0 и cur>0 возвращает «рост от нуля». */
export function trendFromZero(prev: number, cur: number): 'up' | 'down' | 'flat' | null {
if (!Number.isFinite(prev) || !Number.isFinite(cur)) return null;
if (prev === 0 && cur === 0) return null;
if (prev === 0) return cur > 0 ? 'up' : cur < 0 ? 'down' : 'flat';
if (cur > prev) return 'up';
if (cur < prev) return 'down';
return 'flat';
}
export function formatSignedPercent(p: number): string {
const sign = p > 0 ? '+' : '';
return `${sign}${p.toFixed(1)}%`;
}