From fc91cfc6ff74039a4ffba8e4b8875853b59367a3 Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 21 Nov 2022 08:49:03 +0500 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B5=D0=B3=D1=83=D0=BB=D1=8F=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../d3/monitoring/D3MonitoringCharts.tsx | 12 +++---- .../d3/monitoring/D3MonitoringLimitChart.tsx | 31 +++++++++++++++---- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/components/d3/monitoring/D3MonitoringCharts.tsx b/src/components/d3/monitoring/D3MonitoringCharts.tsx index 0f6b320..8215cce 100644 --- a/src/components/d3/monitoring/D3MonitoringCharts.tsx +++ b/src/components/d3/monitoring/D3MonitoringCharts.tsx @@ -242,7 +242,7 @@ const _D3MonitoringCharts = >({ if (!data) return const yAxis = d3.scaleTime() - .domain([yDomain?.min ?? 0, yDomain?.max ?? 0]) + .domain([yDomain?.min || 0, yDomain?.max || 0]) .range([0, sizes.chartsHeight]) return yAxis @@ -453,7 +453,7 @@ const _D3MonitoringCharts = >({ .tickSize(yTicks.visible ? -width + offset.left + offset.right : 0) .ticks(yTicks.count) as any // TODO: Исправить тип ) - + yAxisArea().selectAll('.tick line').attr('stroke', yTicks.color) }, [yAxisArea, yAxis, animDurationMs, width, offset, yTicks]) @@ -463,8 +463,8 @@ const _D3MonitoringCharts = >({ groups.forEach((group, i) => { group() .attr('transform', `translate(${sizes.groupLeft(group.key)}, 0)`) - .attr('clip-path', `url(#chart-clip)`) - + .attr('clip-path', `url(#chart-group-clip)`) + group.charts.forEach((chart) => { chart() .attr('color', chart.color || null) @@ -506,7 +506,7 @@ const _D3MonitoringCharts = >({ chart.afterDraw?.(chart) }) }) - }, [data, groups, height, offset, sizes, chartDomains]) + }, [data, groups, height, offset, sizes, chartDomains, yAxis]) return ( >({ > - + {/* Сдвиг во все стороны на 1 px чтобы линии на краях было видно */} diff --git a/src/components/d3/monitoring/D3MonitoringLimitChart.tsx b/src/components/d3/monitoring/D3MonitoringLimitChart.tsx index d58bdde..7e2aaec 100644 --- a/src/components/d3/monitoring/D3MonitoringLimitChart.tsx +++ b/src/components/d3/monitoring/D3MonitoringLimitChart.tsx @@ -92,6 +92,15 @@ const _D3MonitoringLimitChart = ({ const [ref, setRef] = useState(null) const [selected, setSelected] = useState() + const selectedRegulator = useMemo(() => { + if (!selected) return null + const out = regulators[selected.id] || { + label: `ID = ${selected.id}`, + color: 'black', + } + return out + }, [selected, regulators]) + const data = useMemo(() => calcualteData(chartData), [chartData]) useEffect(() => { @@ -105,7 +114,7 @@ const _D3MonitoringLimitChart = ({ .attr('width', width) .attr('height', (d) => Math.max(yAxis(d.dateEnd) - yAxis(d.dateStart), 1)) .attr('y', (d) => yAxis(d.dateStart)) - .attr('fill', (d) => regulators[d.id].color) + .attr('fill', (d) => regulators[d.id]?.color || 'black') .on('mouseover', (_, d) => { const y = yAxis(d.dateStart) - tooltipHeight setSelected({ ...d, y, x: -tooltipWidth - 10, visible: true }) @@ -130,14 +139,24 @@ const _D3MonitoringLimitChart = ({ return ( - - + + + {/* Сдвиг во все стороны на 1 px чтобы линии на краях было видно */} + + + + + + + + {selected && ( @@ -148,7 +167,7 @@ const _D3MonitoringLimitChart = ({ y={zoneY1} width={zoneWidth} height={zoneY2 - zoneY1} - fill={regulators[selected.id].color} + fill={selectedRegulator?.color} /> )} @@ -158,7 +177,7 @@ const _D3MonitoringLimitChart = ({
Ограничивающий параметр - {regulators[selected.id].label} + {selectedRegulator?.label} Начало: {formatDate(selected.dateStart)}