@@ -69,6 +69,7 @@ interface Props {
6969 dimmedOpacity : number ;
7070 customLayers : CustomLayerDataType [ ] ;
7171 collapseColorScaleByDefault ?: boolean ;
72+ zoomAndCenterByHighlightedIds : boolean ;
7273}
7374
7475export function Graph ( props : Props ) {
@@ -104,6 +105,7 @@ export function Graph(props: Props) {
104105 dimmedOpacity,
105106 customLayers,
106107 collapseColorScaleByDefault,
108+ zoomAndCenterByHighlightedIds,
107109 } = props ;
108110 const [ selectedColor , setSelectedColor ] = useState < string | undefined > ( undefined ) ;
109111 const zoomRef = useRef < ZoomBehavior < SVGSVGElement , unknown > | null > ( null ) ;
@@ -165,10 +167,29 @@ export function Graph(props: Props) {
165167 // eslint-disable-next-line react-hooks/exhaustive-deps
166168 } , [ height , width , zoomInteraction ] ) ;
167169
168- // eslint-disable-next-line @typescript-eslint/no-explicit-any
169- const bounds = bbox ( mapData as any ) ;
170- // eslint-disable-next-line @typescript-eslint/no-explicit-any
171- const center = centerOfMass ( mapData as any ) ;
170+ const bounds = bbox ( {
171+ ...mapData ,
172+ features : zoomAndCenterByHighlightedIds
173+ ? mapData . features . filter (
174+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
175+ ( d : any ) =>
176+ ( highlightedIds || [ ] ) . length === 0 ||
177+ highlightedIds . indexOf ( d . properties [ mapProperty ] ) !== - 1 ,
178+ )
179+ : mapData . features ,
180+ } ) ;
181+
182+ const center = centerOfMass ( {
183+ ...mapData ,
184+ features : zoomAndCenterByHighlightedIds
185+ ? mapData . features . filter (
186+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
187+ ( d : any ) =>
188+ ( highlightedIds || [ ] ) . length === 0 ||
189+ highlightedIds . indexOf ( d . properties [ mapProperty ] ) !== - 1 ,
190+ )
191+ : mapData . features ,
192+ } ) ;
172193 const lonDiff = bounds [ 2 ] - bounds [ 0 ] ;
173194 const latDiff = bounds [ 3 ] - bounds [ 1 ] ;
174195 const scaleX = ( ( ( width * 190 ) / 960 ) * 360 ) / lonDiff ;
0 commit comments