diff --git a/src/components/widgets/BaseWidget.tsx b/src/components/widgets/BaseWidget.tsx index c17ff10..8ae09ad 100644 --- a/src/components/widgets/BaseWidget.tsx +++ b/src/components/widgets/BaseWidget.tsx @@ -17,10 +17,20 @@ export type WidgetSettings = { unitColor?: string, } +const emptyNumber = '----' + +const defaultFormatter = (v: any) => { + if (typeof v === 'undefined' || v === null || String(v) === 'NaN') return emptyNumber + if (Number.isNaN(+v)) return v + const f = parseFloat(v) + if (Number.isFinite(v)) return f.toFixed(2) + return `${f < 0 ? '-' : ''}\u221E` +} + export const defaultSettings: WidgetSettings = { unit: '----', label: 'Виджет', - formatter: v => isNaN(v) ? v : parseFloat(v).toFixed(2), + formatter: defaultFormatter, labelColor: '#000000', valueColor: '#000000', @@ -57,7 +67,7 @@ export const BaseWidget = memo(({ value, onRemove, onEdit, ...s
- {(sets.formatter === null ? value : sets.formatter?.(value)) ?? sets.defaultValue ?? '----'} + {(sets.formatter === null ? value : sets.formatter?.(value)) ?? sets.defaultValue ?? emptyNumber}
{sets.unit}