@@ -10,6 +10,9 @@ import './AnalysisControl.css';
1010const EVOLUTION_FRAME_INTERVAL_MS = 33 ;
1111const MAX_EVOLUTION_STEPS_PER_FRAME = 8 ;
1212const PLAYBACK_SPEEDS = [ 0.25 , 0.5 , 1 , 2 , 4 ] ;
13+ const ENERGY_GROUP_TOLERANCE = 0.005 ;
14+ const ENERGY_LEVEL_TOP_Y = 36 ;
15+ const ENERGY_LEVEL_BOTTOM_Y = 152 ;
1316
1417const clamp = ( value , min , max ) => Math . min ( max , Math . max ( min , value ) ) ;
1518
@@ -40,7 +43,7 @@ const getEnergyGroups = (levels) => {
4043 const groups = [ ] ;
4144
4245 levels . forEach ( ( level ) => {
43- const group = groups . find ( item => Math . abs ( item . energy - level . energy ) < 1e-6 ) ;
46+ const group = groups . find ( item => Math . abs ( item . energy - level . energy ) <= ENERGY_GROUP_TOLERANCE ) ;
4447
4548 if ( group ) {
4649 group . levels . push ( level ) ;
@@ -142,15 +145,21 @@ function StationaryLevelPicker({
142145 canCalculate,
143146} ) {
144147 const hasLevels = levels . length > 0 ;
145- const minEnergy = hasLevels ? Math . min ( ...levels . map ( level => level . energy ) ) : 0 ;
146- const maxEnergy = hasLevels ? Math . max ( ...levels . map ( level => level . energy ) ) : 1 ;
147- const range = Math . max ( maxEnergy - minEnergy , 1 ) ;
148+ const anchorBottomEnergy = hasLevels ? levels [ 0 ] . energy : 0 ;
149+ const anchorTopEnergy = hasLevels
150+ ? levels . find ( level => level . n === 5 ) ?. energy ?? levels [ levels . length - 1 ] . energy
151+ : 1 ;
152+ const anchorRange = Math . max ( anchorTopEnergy - anchorBottomEnergy , 0.001 ) ;
148153 const selectedLevel = hasLevels ? levels . find ( level => level . n === selectedIndex ) ?? levels [ 0 ] : null ;
149154 const selectedSliderIndex = hasLevels
150155 ? Math . max ( 0 , levels . findIndex ( level => level . n === selectedLevel . n ) )
151156 : - 1 ;
152157 const groups = getEnergyGroups ( levels ) ;
153- const toY = ( energy ) => 152 - ( ( energy - minEnergy ) / range ) * 116 ;
158+ const toY = ( energy ) => {
159+ const ratio = clamp ( ( energy - anchorBottomEnergy ) / anchorRange , 0 , 1 ) ;
160+
161+ return ENERGY_LEVEL_BOTTOM_Y - ratio * ( ENERGY_LEVEL_BOTTOM_Y - ENERGY_LEVEL_TOP_Y ) ;
162+ } ;
154163
155164 return (
156165 < div className = "stationary-editor" >
0 commit comments