@@ -32,10 +32,7 @@ export default function useMeasure({
32
32
gridHeight,
33
33
show,
34
34
} ) {
35
- const [ tickLabelSkipIndices , setChartState ] = useChartState (
36
- state => state . tickLabelSkipIndices [ id ]
37
- )
38
- const [ axisDimension ] = useChartState (
35
+ const [ axisDimension , setChartState ] = useChartState (
39
36
state => state . axisDimensions ?. [ position ] ?. [ id ]
40
37
)
41
38
@@ -46,6 +43,7 @@ export default function useMeasure({
46
43
47
44
if ( ! elRef . current ) {
48
45
if ( axisDimension ) {
46
+ console . log ( 'remove axis' )
49
47
// If the entire axis is hidden, then we need to remove the axis dimensions
50
48
setChartState ( state => {
51
49
const newAxes = state . axisDimensions [ position ] || { }
@@ -113,21 +111,6 @@ export default function useMeasure({
113
111
} , false )
114
112
}
115
113
116
- let newTickLabelSkipIndices = [ ]
117
-
118
- if (
119
- JSON . stringify ( newTickLabelSkipIndices ) !==
120
- JSON . stringify ( tickLabelSkipIndices )
121
- ) {
122
- setChartState ( old => ( {
123
- ...old ,
124
- tickLabelSkipIndices : {
125
- ...old . tickLabelSkipIndices ,
126
- [ id ] : newTickLabelSkipIndices ,
127
- } ,
128
- } ) )
129
- }
130
-
131
114
// Rotate ticks for non-time horizontal axes
132
115
if ( ! vertical ) {
133
116
const newRotation =
@@ -136,6 +119,7 @@ export default function useMeasure({
136
119
: 0
137
120
138
121
if ( newRotation !== rotation ) {
122
+ console . log ( 'rotation' )
139
123
setRotation ( position === 'top' ? - newRotation : newRotation )
140
124
}
141
125
}
@@ -151,63 +135,51 @@ export default function useMeasure({
151
135
152
136
// Axis overflow measurements
153
137
if ( ! vertical ) {
154
- const leftMostLabelDim = realLabelDims . length
155
- ? realLabelDims . reduce ( ( d , labelDim ) =>
156
- labelDim . left < d . left ? labelDim : d
157
- )
158
- : null
159
- const rightMostLabelDim = realLabelDims . length
160
- ? realLabelDims . reduce ( ( d , labelDim ) =>
161
- labelDim . right > d . right ? labelDim : d
162
- )
163
- : null
164
-
165
- newDimensions . left = round (
166
- Math . max ( 0 , domainDims . left - leftMostLabelDim ?. left ) ,
167
- 5 ,
168
- Math . ceil
169
- )
170
-
171
- newDimensions . right = round (
172
- Math . max ( 0 , rightMostLabelDim ?. right - domainDims . right ) ,
173
- 5 ,
174
- Math . ceil
175
- )
138
+ if ( realLabelDims . length ) {
139
+ const leftMostLabelDim = realLabelDims . reduce ( ( d , labelDim ) =>
140
+ labelDim . left < d . left ? labelDim : d
141
+ )
142
+ const rightMostLabelDim = realLabelDims . reduce ( ( d , labelDim ) =>
143
+ labelDim . right > d . right ? labelDim : d
144
+ )
145
+
146
+ newDimensions . left = Math . round (
147
+ Math . max ( 0 , domainDims . left - leftMostLabelDim ?. left )
148
+ )
149
+
150
+ newDimensions . right = Math . round (
151
+ Math . max ( 0 , rightMostLabelDim ?. right - domainDims . right )
152
+ )
153
+ }
176
154
177
- newDimensions . height = round (
155
+ newDimensions . height = Math . round (
178
156
Math . max ( tickSizeInner , tickSizeOuter ) +
179
157
tickPadding +
180
- ( tallestRealLabel ?. height || 0 ) ,
181
- 5 ,
182
- Math . ceil
158
+ ( tallestRealLabel ?. height ?? 0 )
183
159
)
184
160
} else {
185
- const topMostLabelDim = realLabelDims . reduce ( ( d , labelDim ) =>
186
- labelDim . top < d . top ? labelDim : d
187
- )
188
-
189
- const bottomMostLabelDim = realLabelDims . reduce ( ( d , labelDim ) =>
190
- labelDim . bottom > d . bottom ? labelDim : d
191
- )
192
-
193
- newDimensions . top = round (
194
- Math . max ( 0 , domainDims . top - topMostLabelDim ?. top ) ,
195
- 5 ,
196
- Math . ceil
197
- )
198
-
199
- newDimensions . bottom = round (
200
- Math . max ( 0 , bottomMostLabelDim ?. bottom - domainDims . bottom ) ,
201
- 5 ,
202
- Math . ceil
203
- )
161
+ if ( realLabelDims . length ) {
162
+ const topMostLabelDim = realLabelDims . reduce ( ( d , labelDim ) =>
163
+ labelDim . top < d . top ? labelDim : d
164
+ )
165
+
166
+ const bottomMostLabelDim = realLabelDims . reduce ( ( d , labelDim ) =>
167
+ labelDim . bottom > d . bottom ? labelDim : d
168
+ )
169
+
170
+ newDimensions . top = Math . round (
171
+ Math . max ( 0 , domainDims . top - topMostLabelDim ?. top )
172
+ )
173
+
174
+ newDimensions . bottom = Math . round (
175
+ Math . max ( 0 , bottomMostLabelDim ?. bottom - domainDims . bottom )
176
+ )
177
+ }
204
178
205
- newDimensions . width = round (
179
+ newDimensions . width = Math . round (
206
180
Math . max ( tickSizeInner , tickSizeOuter ) +
207
181
tickPadding +
208
- ( widestRealLabel ?. width || 0 ) ,
209
- 5 ,
210
- Math . ceil
182
+ ( widestRealLabel ?. width ?? 0 )
211
183
)
212
184
}
213
185
@@ -216,6 +188,8 @@ export default function useMeasure({
216
188
! axisDimension ||
217
189
Object . keys ( newDimensions ) . some ( key => {
218
190
return newDimensions [ key ] !== axisDimension [ key ]
191
+ ? console . log ( id , key , newDimensions [ key ] , axisDimension [ key ] ) || true
192
+ : false
219
193
} )
220
194
) {
221
195
setChartState ( state => ( {
@@ -230,6 +204,7 @@ export default function useMeasure({
230
204
} ) )
231
205
}
232
206
} , [
207
+ axisDimension ,
233
208
elRef ,
234
209
gridHeight ,
235
210
gridWidth ,
@@ -240,16 +215,14 @@ export default function useMeasure({
240
215
setChartState ,
241
216
setRotation ,
242
217
show ,
243
- tickLabelSkipIndices ,
244
218
tickPadding ,
245
219
tickSizeInner ,
246
220
tickSizeOuter ,
247
221
vertical ,
248
- axisDimension ,
249
222
] )
250
223
251
224
// Measure after if needed
252
- useIsomorphicLayoutEffect ( ( ) => {
225
+ React . useEffect ( ( ) => {
253
226
measureDimensions ( )
254
227
} , [ measureDimensions ] )
255
228
}
0 commit comments