@@ -136,19 +136,22 @@ describe('useChartLabelLayout', () => {
136136
137137 describe ( 'edge-constrained rotation' , ( ) => {
138138 it ( 'same data picks 0° without edge constraint but 45° with edge constraint' , ( ) => {
139- // "A".repeat(16) = 112px. At 0°: overhang = 56px.
140- const config = { data : makeData ( 'A' . repeat ( 16 ) , 'BB' , 'CC' ) , fontMgr : mockFontMgr , fontSize : FONT_SIZE , tickSpacing : 120 , labelAreaWidth : 360 } ;
139+ // "A".repeat(22) = 154px. firstMinTrunc = (10+3)*7 = 91px.
140+ // At 0°: centered overhang = 77px. firstTickLeftSpace=72 < 77 → 0° edge fails.
141+ // At 45° right-aligned: edgeMax = 72/SIN_45−8 ≈ 93.8 ≥ 91 → 45° edge fits.
142+ const config = { data : makeData ( 'A' . repeat ( 22 ) , 'BB' , 'CC' ) , fontMgr : mockFontMgr , fontSize : FONT_SIZE , tickSpacing : 160 , labelAreaWidth : 480 } ;
141143
142144 const { result : noEdge } = renderLayout ( config ) ;
143145 expect ( noEdge . current . labelRotation ) . toBe ( 0 ) ;
144146
145- // firstTickLeftSpace=40 < 56 → 0° edge fails → escalates to 45°
146- const { result : withEdge } = renderLayout ( { ...config , firstTickLeftSpace : 40 , lastTickRightSpace : 200 } ) ;
147+ // firstTickLeftSpace=72 < 77 → 0° edge fails → escalates to 45°
148+ const { result : withEdge } = renderLayout ( { ...config , firstTickLeftSpace : 72 , lastTickRightSpace : 200 } ) ;
147149 expect ( withEdge . current . labelRotation ) . toBe ( 45 ) ;
148150 } ) ;
149151
150152 it ( 'escalates to 90° when edge space is too small for both 0° and 45°' , ( ) => {
151- // firstTickLeftSpace=5: at 45° centered edgeMax = max(0, 2*(5/SIN_45-8)) ≈ 0 → fails
153+ // "AAAAAA" = 42px (6 chars <= MIN_TRUNCATED_CHARS=10), so firstMinTrunc = 42.
154+ // firstTickLeftSpace=5: at 45° right-aligned edgeMax = max(0, 5/SIN_45−8) = 0 < 42 → fails
152155 const { result} = renderLayout ( {
153156 data : makeData ( 'AAAAAA' , 'BBBBBB' ) ,
154157 fontMgr : mockFontMgr ,
@@ -160,50 +163,9 @@ describe('useChartLabelLayout', () => {
160163 } ) ;
161164 expect ( result . current . labelRotation ) . toBe ( 90 ) ;
162165 } ) ;
163-
164- it ( 'allowTightDiagonalPacking enables 45° at tighter tick spacing' , ( ) => {
165- // "AAAAAA" = 42px. tickSpacing=30.
166- // Without packing: minDiagWidth = 42*SIN_45 ≈ 29.7, 29.7+4=33.7 > 30 → 45° fails
167- // With packing: diagonalOverlap = 16*SIN_45 ≈ 11.3, minDiagWidth = 29.7-11.3=18.4, 18.4+4=22.4 ≤ 30 ✓
168- const base = {
169- data : makeData ( 'AAAAAA' , 'BBBBBB' ) ,
170- fontMgr : mockFontMgr ,
171- fontSize : FONT_SIZE ,
172- tickSpacing : 30 ,
173- labelAreaWidth : 400 ,
174- firstTickLeftSpace : 100 ,
175- lastTickRightSpace : 100 ,
176- } ;
177-
178- const { result : noPacking } = renderLayout ( { ...base , allowTightDiagonalPacking : false } ) ;
179- expect ( noPacking . current . labelRotation ) . toBe ( 90 ) ;
180-
181- const { result : withPacking } = renderLayout ( { ...base , allowTightDiagonalPacking : true } ) ;
182- expect ( withPacking . current . labelRotation ) . toBe ( 45 ) ;
183- } ) ;
184166 } ) ;
185167
186168 describe ( 'edge-aware max-width constraints' , ( ) => {
187- it ( 'constrains first label below full width when centered and edge is tight' , ( ) => {
188- // First label: 16 chars = 112px. tickMaxWidth ≈ 164. edgeMax ≈ 97 (stricter).
189- // labelMaxWidths[0] should be < 112; middle/last labels unconstrained.
190- const { result} = renderLayout ( {
191- data : makeData ( 'A' . repeat ( 16 ) , 'BB' , 'CC' ) ,
192- fontMgr : mockFontMgr ,
193- fontSize : FONT_SIZE ,
194- tickSpacing : 120 ,
195- labelAreaWidth : 360 ,
196- firstTickLeftSpace : 40 ,
197- lastTickRightSpace : 200 ,
198- } ) ;
199- expect ( result . current . labelRotation ) . toBe ( 45 ) ;
200- // Edge constraint tightens first label below its natural width
201- expect ( result . current . labelMaxWidths . at ( 0 ) ) . toBeLessThan ( 16 * PX_PER_CHAR ) ;
202- // Middle and last labels are only tick-constrained (much wider than 'BB'/'CC')
203- expect ( result . current . labelMaxWidths . at ( 1 ) ) . toBeGreaterThanOrEqual ( 2 * PX_PER_CHAR ) ;
204- expect ( result . current . labelMaxWidths . at ( 2 ) ) . toBeGreaterThanOrEqual ( 2 * PX_PER_CHAR ) ;
205- } ) ;
206-
207169 it ( 'constrains first label below full width when right-aligned and edge is tight' , ( ) => {
208170 // Right-aligned first label: edgeMax = 72/SIN_45 - 8 ≈ 93.8 < 112 → constrained.
209171 const { result} = renderLayout ( {
@@ -214,28 +176,12 @@ describe('useChartLabelLayout', () => {
214176 labelAreaWidth : 360 ,
215177 firstTickLeftSpace : 72 ,
216178 lastTickRightSpace : 200 ,
217- allowTightDiagonalPacking : true ,
218179 } ) ;
219180 expect ( result . current . labelRotation ) . toBe ( 45 ) ;
220181 expect ( result . current . labelMaxWidths . at ( 0 ) ) . toBeLessThan ( 16 * PX_PER_CHAR ) ;
221182 expect ( result . current . labelMaxWidths . at ( 1 ) ) . toBeGreaterThanOrEqual ( 2 * PX_PER_CHAR ) ;
222183 } ) ;
223184
224- it ( 'constrains last label below full width when centered and right edge is tight' , ( ) => {
225- // lastTickRightSpace=40: edgeMax = 2*(40/SIN_45-8) ≈ 97.1 < 112 → constrained.
226- const { result} = renderLayout ( {
227- data : makeData ( 'AA' , 'BB' , 'A' . repeat ( 16 ) ) ,
228- fontMgr : mockFontMgr ,
229- fontSize : FONT_SIZE ,
230- tickSpacing : 200 ,
231- labelAreaWidth : 600 ,
232- firstTickLeftSpace : 200 ,
233- lastTickRightSpace : 40 ,
234- } ) ;
235- expect ( result . current . labelRotation ) . toBe ( 45 ) ;
236- expect ( result . current . labelMaxWidths . at ( 2 ) ) . toBeLessThan ( 16 * PX_PER_CHAR ) ;
237- } ) ;
238-
239185 it ( 'does NOT constrain last label when right-aligned despite tight right edge' , ( ) => {
240186 // Right-aligned: last label right overhang = halfLH*SIN_45 ≈ 5.6 (constant, tiny).
241187 // lastTickRightSpace=40 >> 5.6 → edgeMax = Infinity → no edge constraint.
@@ -248,7 +194,6 @@ describe('useChartLabelLayout', () => {
248194 labelAreaWidth : 600 ,
249195 firstTickLeftSpace : 200 ,
250196 lastTickRightSpace : 40 ,
251- allowTightDiagonalPacking : true ,
252197 } ) ;
253198 expect ( result . current . labelRotation ) . toBe ( 45 ) ;
254199 expect ( result . current . labelMaxWidths . at ( 2 ) ) . toBeGreaterThanOrEqual ( 16 * PX_PER_CHAR ) ;
0 commit comments