From 17c388c0b7ad9c122b6c244515dfbbdf294b6869 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Tue, 1 Nov 2022 13:54:45 +0400 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=20=D0=B7=D1=83=D0=BC=20=D0=B4=D0=BB=D1=8F=20=D0=B3?= =?UTF-8?q?=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B0=20D3Chart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/d3/D3Chart.tsx | 23 ++++++++++++------- .../Telemetry/Operations/OperationsChart.jsx | 5 ++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/components/d3/D3Chart.tsx b/src/components/d3/D3Chart.tsx index dff01e6..2aedeab 100644 --- a/src/components/d3/D3Chart.tsx +++ b/src/components/d3/D3Chart.tsx @@ -93,6 +93,11 @@ export type D3ChartProps = React.DetailedHTMLProp /** Параметры блока легенды */ legend?: BasePluginSettings & D3LegendSettings } + /** Добавление зума графику */ + zoom?: { + /** Массив коэффициентов приближения k0 - минимальный k1 - максимальный коэффициент */ + scaleExtent: [k0: number, k1: number] + } } const getDefaultXAxisConfig = (): ChartAxis => ({ @@ -115,6 +120,7 @@ const _D3Chart = >({ ticks, plugins, dash, + zoom, ...other }: D3ChartProps) => { const xAxisConfig = usePartialProps>(_xAxisConfig, getDefaultXAxisConfig) @@ -360,17 +366,18 @@ const _D3Chart = >({ }, [redrawCharts]) useEffect(() => { - if (!svgRef) return - const zoom = d3.zoom() - .scaleExtent([1, 5]) - .translateExtent([[0, 0], [width, height]]) + if (!svgRef || !zoom) return + const zoomBehavior = d3.zoom() + .scaleExtent(zoom.scaleExtent) + .translateExtent([[0, 0], [width - offset.left - offset.right, height - offset.top - offset.bottom]]) + .extent([[0, 0], [width - offset.left - offset.right, height - offset.top - offset.bottom]]) .on('zoom', () => { const zoomState = d3.zoomTransform(svgRef) setCurrentZoomState(zoomState) }) - d3.select(svgRef).call(zoom) - }, [svgRef, width, height, offset]) + d3.select(svgRef).call(zoomBehavior) + }, [svgRef, zoom, width, height, offset]) return ( >({ - + >({ /> - + ({ + scaleExtent: [1, 5] + }), []) + return ( ) })