@@ -124,77 +124,93 @@ export default function useMeasure<TDatum>({
124124 right : 0 ,
125125 }
126126
127- const domainEl = elRef . current . querySelector ( `.Axis-Group.inner .domain` )
127+ const currentEl = elRef . current
128128
129- if ( ! domainEl ) {
130- return
131- }
129+ const [ innerDims ] = [ 'inner' ] . map ( inOrOut => {
130+ const domainEl = currentEl . querySelector ( `.Axis-Group.${ inOrOut } .domain` )
132131
133- const domainDims = getElBox ( domainEl )
132+ if ( ! domainEl ) {
133+ return
134+ }
134135
135- const measureDims = Array . from (
136- elRef . current . querySelectorAll ( '.Axis-Group.inner .tickLabel' )
137- ) . map ( el => getElBox ( el ) )
136+ const domainDims = getElBox ( domainEl )
138137
139- // Determine the largest labels on the axis
140- let widestRealLabel = measureDims [ 0 ]
141- let tallestRealLabel = measureDims [ 0 ]
138+ const measureDims = Array . from (
139+ currentEl . querySelectorAll ( `.Axis-Group. ${ inOrOut } .tickLabel` )
140+ ) . map ( el => getElBox ( el ) )
142141
143- measureDims . forEach ( d => {
144- if ( d . width > 0 && d . width > widestRealLabel . width ) {
145- widestRealLabel = d
142+ if ( ! measureDims . length ) {
143+ return
146144 }
147145
148- if ( d . height > 0 && d . height > tallestRealLabel . height ) {
149- tallestRealLabel = d
150- }
146+ // Determine the largest labels on the axis
147+ let widestLabel = measureDims [ 0 ]
148+ let tallestLabel = measureDims [ 0 ]
149+
150+ measureDims . forEach ( d => {
151+ if ( d . width > 0 && d . width > widestLabel . width ) {
152+ widestLabel = d
153+ }
154+
155+ if ( d . height > 0 && d . height > tallestLabel . height ) {
156+ tallestLabel = d
157+ }
158+ } )
159+
160+ return { domainDims, measureDims, widestLabel, tallestLabel }
151161 } )
152162
163+ if ( ! innerDims ) {
164+ return
165+ }
166+
153167 // Axis overflow measurements
154168 if ( ! axis . isVertical ) {
155- if ( measureDims . length ) {
156- const leftMostLabelDim = measureDims . reduce ( ( d , labelDim ) =>
169+ if ( innerDims . measureDims . length ) {
170+ const leftMostLabelDim = innerDims . measureDims . reduce ( ( d , labelDim ) =>
157171 labelDim . left < d . left ? labelDim : d
158172 )
159- const rightMostLabelDim = measureDims . reduce ( ( d , labelDim ) =>
173+ const rightMostLabelDim = innerDims . measureDims . reduce ( ( d , labelDim ) =>
160174 labelDim . right > d . right ? labelDim : d
161175 )
162176
163177 newDimensions . left = Math . round (
164- Math . max ( 0 , domainDims . left - leftMostLabelDim ?. left )
178+ Math . max ( 0 , innerDims . domainDims . left - leftMostLabelDim ?. left )
165179 )
166180
167181 newDimensions . right = Math . round (
168- Math . max ( 0 , rightMostLabelDim ?. right - domainDims . right )
182+ Math . max ( 0 , rightMostLabelDim ?. right - innerDims . domainDims . right )
169183 )
170184 }
171185
172186 newDimensions . height = Math . round (
173187 // Math.max(axis.tickSizeInner, axis.tickSizeOuter) +
174- 8 + axis . minTickPaddingForRotation + ( tallestRealLabel ?. height ?? 0 )
188+ 8 +
189+ axis . minTickPaddingForRotation +
190+ ( innerDims . tallestLabel ?. height ?? 0 )
175191 )
176192 } else {
177- if ( measureDims . length ) {
178- const topMostLabelDim = measureDims . reduce ( ( d , labelDim ) =>
193+ if ( innerDims . measureDims . length ) {
194+ const topMostLabelDim = innerDims . measureDims . reduce ( ( d , labelDim ) =>
179195 labelDim . top < d . top ? labelDim : d
180196 )
181197
182- const bottomMostLabelDim = measureDims . reduce ( ( d , labelDim ) =>
198+ const bottomMostLabelDim = innerDims . measureDims . reduce ( ( d , labelDim ) =>
183199 labelDim . bottom > d . bottom ? labelDim : d
184200 )
185201
186202 newDimensions . top = Math . round (
187- Math . max ( 0 , domainDims . top - topMostLabelDim ?. top )
203+ Math . max ( 0 , innerDims . domainDims . top - topMostLabelDim ?. top )
188204 )
189205
190206 newDimensions . bottom = Math . round (
191- Math . max ( 0 , bottomMostLabelDim ?. bottom - domainDims . bottom )
207+ Math . max ( 0 , bottomMostLabelDim ?. bottom - innerDims . domainDims . bottom )
192208 )
193209 }
194210
195211 newDimensions . width = Math . round (
196212 // Math.max(axis.tickSizeInner, axis.tickSizeOuter) +
197- 8 + axis . minTickPaddingForRotation + ( widestRealLabel ?. width ?? 0 )
213+ 8 + axis . minTickPaddingForRotation + ( innerDims . widestLabel ?. width ?? 0 )
198214 )
199215 }
200216
@@ -229,10 +245,16 @@ export default function useMeasure<TDatum>({
229245
230246 // Measure after if needed
231247 useIsomorphicLayoutEffect ( ( ) => {
232- measureRotation ( )
248+ // setTimeout(() => {
249+ window . requestAnimationFrame ( ( ) => {
250+ measureRotation ( )
251+ } )
233252 } , [ measureRotation ] )
234253
235254 useIsomorphicLayoutEffect ( ( ) => {
236- measureDimensions ( )
255+ // setTimeout(() => {
256+ window . requestAnimationFrame ( ( ) => {
257+ measureDimensions ( )
258+ } )
237259 } , [ measureRotation ] )
238260}
0 commit comments