11import cx from "classnames" ;
22import { isEqual , keyBy , uniqBy } from "lodash" ;
33import Slider , { SliderProps } from "rc-slider" ;
4- import React , { FC , useContext , useState , useMemo } from "react" ;
4+ import React , { FC , useContext , useState , useMemo , useEffect } from "react" ;
55import { FaTimes , FaUndo } from "react-icons/fa" ;
66import { FaGear , FaNetworkWired } from "react-icons/fa6" ;
77import { VscSettings } from "react-icons/vsc" ;
@@ -38,6 +38,21 @@ const Settings: FC = () => {
3838 const maxLabelSize = typeof navState . maxLabelSize === "number" ? navState . maxLabelSize : DEFAULT_LABEL_SIZE ;
3939 const labelThresholdRatio =
4040 typeof navState . labelThresholdRatio === "number" ? navState . labelThresholdRatio : DEFAULT_LABEL_THRESHOLD ;
41+ // Local UI state for smoother sliders
42+ const [ localMinLabelSize , setLocalMinLabelSize ] = useState < number > ( minLabelSize ) ;
43+ const [ localMaxLabelSize , setLocalMaxLabelSize ] = useState < number > ( maxLabelSize ) ;
44+ const [ localLabelThresholdRatio , setLocalLabelThresholdRatio ] = useState < number > ( labelThresholdRatio ) ;
45+
46+ // Keep local slider values in sync if navState changes elsewhere
47+ useEffect ( ( ) => {
48+ setLocalMinLabelSize ( minLabelSize ) ;
49+ } , [ minLabelSize ] ) ;
50+ useEffect ( ( ) => {
51+ setLocalMaxLabelSize ( maxLabelSize ) ;
52+ } , [ maxLabelSize ] ) ;
53+ useEffect ( ( ) => {
54+ setLocalLabelThresholdRatio ( labelThresholdRatio ) ;
55+ } , [ labelThresholdRatio ] ) ;
4156
4257 const { fields, fieldsIndex } = data ;
4358
@@ -170,21 +185,27 @@ const Settings: FC = () => {
170185 < div className = "pb-3" >
171186 < Slider
172187 range
173- value = { [ minLabelSize , maxLabelSize ] }
188+ value = { [ localMinLabelSize , localMaxLabelSize ] }
174189 min = { MIN_LABEL_SIZE }
175190 max = { MAX_LABEL_SIZE }
176191 step = { LABEL_SIZE_STEP }
177192 marks = { {
178193 [ MIN_LABEL_SIZE ] : MIN_LABEL_SIZE ,
179194 [ MAX_LABEL_SIZE ] : MAX_LABEL_SIZE ,
180- [ minLabelSize ] : minLabelSize ,
181- [ maxLabelSize ] : maxLabelSize ,
195+ [ localMinLabelSize ] : localMinLabelSize ,
196+ [ localMaxLabelSize ] : localMaxLabelSize ,
182197 } }
183198 onChange = {
184- ( ( [ minLabelSize , maxLabelSize ] : number [ ] ) => {
185- setNavState ( { ...navState , minLabelSize, maxLabelSize } ) ;
199+ ( ( [ minValue , maxValue ] : number [ ] ) => {
200+ setLocalMinLabelSize ( minValue ) ;
201+ setLocalMaxLabelSize ( maxValue ) ;
186202 } ) as SliderProps [ "onChange" ]
187203 }
204+ onAfterChange = {
205+ ( ( [ minValue , maxValue ] : number [ ] ) => {
206+ setNavState ( { ...navState , minLabelSize : minValue , maxLabelSize : maxValue } ) ;
207+ } ) as SliderProps [ "onAfterChange" ]
208+ }
188209 // Styles:
189210 { ...RANGE_STYLE }
190211 />
@@ -279,7 +300,7 @@ const Settings: FC = () => {
279300 </ h3 >
280301 < div className = "pb-3" >
281302 < Slider
282- value = { labelThresholdRatio }
303+ value = { localLabelThresholdRatio }
283304 min = { MIN_LABEL_THRESHOLD }
284305 max = { MAX_LABEL_THRESHOLD }
285306 step = { LABEL_THRESHOLD_STEP }
@@ -300,6 +321,8 @@ const Settings: FC = () => {
300321 } }
301322 onChange = {
302323 ( ( v : number ) => {
324+ setLocalLabelThresholdRatio ( v ) ;
325+ // Update graph in real-time for better responsiveness
303326 setNavState ( { ...navState , labelThresholdRatio : v } ) ;
304327 } ) as SliderProps [ "onChange" ]
305328 }
0 commit comments