Files
Dmitry 6891028074 fix(app): подписи осей и легенда графика стоимости
Крайние подписи оси Y (414.6K поверх 400K) скрыты, числа в русской краткой форме, подписи оси X не обрезаются справа. Добавлена легенда: сплошная линия — стоимость, пунктир — вложено нетто.
2026-09-20 10:46:35 +03:00

19 lines
747 B
Dart
Raw Permalink 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.
/// «12,3 тыс», «1,2 млн» — for axis labels and cells too narrow for a full amount.
///
/// fl_chart's own short form («414.6K») is English and rounds a step of 50 000 to the same
/// label twice; this one keeps the Russian suffixes and one decimal below a hundred.
String compactNumber(double value) {
final n = value.abs();
String scaled(double x, String suffix) {
final s = x >= 100
? x.round().toString()
: x.toStringAsFixed(1).replaceAll(RegExp(r'\.0$'), '');
return '${s.replaceAll('.', ',')} $suffix';
}
final sign = value < 0 ? '' : '';
if (n >= 1e6) return '$sign${scaled(n / 1e6, 'млн')}';
if (n >= 1e3) return '$sign${scaled(n / 1e3, 'тыс')}';
return '$sign${n.round()}';
}