From f72593e33807a4885d3ee2cb665b946e9ecb3396 Mon Sep 17 00:00:00 2001 From: Suhaha Date: Thu, 16 Jun 2022 14:57:46 +0800 Subject: [PATCH] fix: restriction of minimap brush --- ui/lib/components/TreeDiagram/Minimap.tsx | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ui/lib/components/TreeDiagram/Minimap.tsx b/ui/lib/components/TreeDiagram/Minimap.tsx index dd748da0ab..f3246fb7ce 100644 --- a/ui/lib/components/TreeDiagram/Minimap.tsx +++ b/ui/lib/components/TreeDiagram/Minimap.tsx @@ -40,11 +40,34 @@ const Minimap = ({ const minimapContainerWidth = viewPort.width * minimapScale const minimapContainerHeight = viewPort.height * minimapScale + const longSide = mainChartWidth > mainChartHeight ? 'x' : 'y' + const chartLongSideSize = Math.max(mainChartWidth, mainChartHeight) + const chartMinimapScale = + chartLongSideSize / + (longSide === 'x' ? minimapContainerWidth : minimapContainerHeight) + const drawMinimap = () => { minimapSVG .attr('width', minimapContainerWidth) .attr('height', minimapContainerHeight) - .attr('viewBox', [0, 0, mainChartWidth, mainChartHeight].join(' ')) + .attr( + 'viewBox', + (longSide === 'x' + ? [ + 0, + -(minimapContainerHeight * chartMinimapScale - mainChartHeight) / + 2, + mainChartWidth, + minimapContainerHeight * chartMinimapScale, + ] + : [ + -(minimapContainerWidth * chartMinimapScale - mainChartWidth) / 2, + 0, + minimapContainerWidth * chartMinimapScale, + mainChartHeight, + ] + ).join(' ') + ) .attr('preserveAspectRatio', 'xMidYMid meet') .style('position', 'absolute') .style('top', 0)