@@ -2,12 +2,15 @@ import React, { useEffect, useRef, useState } from 'react';
22import * as d3 from 'd3' ;
33import { colorMappings } from '@/utils/heightgraph' ;
44import makeResizable from '@/utils/resizable' ;
5+ import { ToolButton } from '@/components/map/parts/tool-button' ;
6+ import elevationIcon from '@/images/elevation.png' ;
57import type { FeatureCollection , GeoJsonProperties , Geometry } from 'geojson' ;
68
79interface HeightGraphProps {
810 data : FeatureCollection < Geometry , GeoJsonProperties > [ ] ;
911 width : number ;
1012 height ?: number ;
13+ disabled ?: boolean ;
1114 onExpand ?: ( expanded : boolean ) => void ;
1215 onHighlight ?: ( index : number | null ) => void ;
1316}
@@ -16,6 +19,7 @@ const HeightGraph: React.FC<HeightGraphProps> = ({
1619 data,
1720 width,
1821 height = 200 ,
22+ disabled = false ,
1923 onExpand,
2024 onHighlight,
2125} ) => {
@@ -279,37 +283,43 @@ const HeightGraph: React.FC<HeightGraphProps> = ({
279283 } ;
280284 } , [ isExpanded ] ) ;
281285
286+ // Auto-collapse when disabled
287+ const [ prevDisabled , setPrevDisabled ] = useState ( disabled ) ;
288+ if ( disabled !== prevDisabled ) {
289+ setPrevDisabled ( disabled ) ;
290+ if ( disabled && isExpanded ) {
291+ setIsExpanded ( false ) ;
292+ if ( onExpand ) onExpand ( false ) ;
293+ }
294+ }
295+
282296 const handleToggleExpand = ( ) => {
297+ if ( disabled ) return ;
283298 const newState = ! isExpanded ;
284299 setIsExpanded ( newState ) ;
285300 if ( onExpand ) onExpand ( newState ) ;
286301 } ;
287302
288303 return (
289304 < >
290- < div
291- className = "heightgraph-toggle"
292- onClick = { handleToggleExpand }
305+ < ToolButton
293306 title = "Height Graph"
294- style = { {
295- position : 'absolute' ,
296- bottom : '84px' ,
297- right : '10px' ,
298- width : '36px' ,
299- height : '36px' ,
300- background : 'white' ,
301- border : '2px solid rgba(0,0,0,0.2)' ,
302- borderRadius : '4px' ,
303- cursor : 'pointer' ,
304- display : 'flex' ,
305- alignItems : 'center' ,
306- justifyContent : 'center' ,
307- fontSize : '18px' ,
308- zIndex : 1001 ,
309- } }
310- >
311- { isExpanded ? '−' : '▲' }
312- </ div >
307+ icon = {
308+ isExpanded ? (
309+ < span style = { { fontSize : '18px' } } > −</ span >
310+ ) : (
311+ < img
312+ src = { elevationIcon }
313+ alt = "Height Graph"
314+ style = { { width : '24px' , height : '24px' } }
315+ />
316+ )
317+ }
318+ onClick = { handleToggleExpand }
319+ disabled = { disabled }
320+ className = "z-[1001]"
321+ data-testid = "heightgraph-toggle"
322+ />
313323 < div
314324 ref = { containerRef }
315325 className = { `maplibre-heightgraph ${ isExpanded ? 'heightgraph-expanded' : '' } ` }
0 commit comments