diff --git a/src/components/d3/monitoring/D3MonitoringLimitChart.tsx b/src/components/d3/monitoring/D3MonitoringLimitChart.tsx index be88683..97dc80c 100644 --- a/src/components/d3/monitoring/D3MonitoringLimitChart.tsx +++ b/src/components/d3/monitoring/D3MonitoringLimitChart.tsx @@ -1,9 +1,9 @@ -import { memo, useEffect, useMemo, useState } from 'react' +import { CSSProperties, memo, useEffect, useMemo, useState } from 'react' import * as d3 from 'd3' import { Grid, GridItem } from '@components/Grid' +import { formatDate, makeDisplayValue } from '@utils' import { TelemetryDataSaubDto } from '@api' -import { formatDate } from '@utils' type LimitChartData = { id: number @@ -77,6 +77,8 @@ export type D3MonitoringLimitChartProps = { const tooltipWidth = 270 const tooltipHeight = 120 +const displayValue = makeDisplayValue() + const _D3MonitoringLimitChart = ({ yAxis, data: chartData, @@ -85,7 +87,7 @@ const _D3MonitoringLimitChart = ({ left, top, regulators, - zoneWidth = 0 + zoneWidth = 0, }: D3MonitoringLimitChartProps) => { const [ref, setRef] = useState(null) const [selected, setSelected] = useState() @@ -108,22 +110,37 @@ const _D3MonitoringLimitChart = ({ const y = yAxis(d.dateStart) - tooltipHeight setSelected({ ...d, y, x: -tooltipWidth - 10, visible: true }) }) - .on('mouseout', (_, d) => setSelected((pre) => pre ? ({ ...pre, visible: false }) : undefined)) + .on('mouseout', () => setSelected((pre) => pre ? ({ ...pre, visible: false }) : undefined)) }, [yAxis, data, ref, width]) const zoneY1 = useMemo(() => yAxis && selected ? yAxis(selected.dateStart) : 0, [yAxis, selected]) const zoneY2 = useMemo(() => yAxis && selected ? yAxis(selected.dateEnd) : 0, [yAxis, selected]) - const tooltipStyle = useMemo(() => ({ transition: 'opacity .1s ease-in-out', opacity: selected?.visible ? 1 : 0 }), [selected]) + const opacityStyle: CSSProperties = useMemo(() => ({ + transition: 'opacity .1s ease-in-out', + opacity: selected?.visible ? 1 : 0, + }), [selected]) + + const tooltipStyle: CSSProperties = useMemo(() => ({ + ...opacityStyle, + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + }), [opacityStyle]) return ( {selected && ( - - - + + + ({ {selected && ( -
+
Ограничивающий параметр {regulators[selected.id].label} - + Начало: {formatDate(selected.dateStart)} - {selected.depthStart?.toFixed(2) ?? '---'} + {displayValue(selected.depthStart)} м. Конец: {formatDate(selected.dateEnd)} - {selected.depthEnd?.toFixed(2) ?? '---'} + {displayValue(selected.depthEnd)} м.
diff --git a/src/utils/functions/numbers.tsx b/src/utils/functions/numbers.tsx index c60a46e..6e6ca26 100644 --- a/src/utils/functions/numbers.tsx +++ b/src/utils/functions/numbers.tsx @@ -35,7 +35,11 @@ export const makeDisplayValue = ({ def = '----', inf = (v) => `${v < 0 ? '-' : ''}\u221E`, fixed = 2 -}: DisplayValueOptions) => (v: unknown): ReactNode => { +}: DisplayValueOptions = { + def: '----', + inf: (v) => `${v < 0 ? '-' : ''}\u221E`, + fixed: 2 +}) => (v: unknown): ReactNode => { if (typeof v === 'undefined' || v === null || String(v) === 'NaN') return def let f = Number(v) if (typeof v === 'string') {