@@ -63,14 +63,14 @@ export default function BlogHistory({ posts = [], isDesktop }: BlogHistoryProps)
6363
6464 const getOptimalInterval = ( months : Date [ ] ) => {
6565 const totalMonths = months . length ;
66-
67- // Aim to show roughly 6-8 labels on the axis
68- if ( totalMonths <= 8 ) return 1 ; // Show all labels if 8 or fewer months
69- if ( totalMonths <= 16 ) return 2 ; // Every 2 months if <= 16 months
70- if ( totalMonths <= 24 ) return 3 ; // Every quarter if <= 2 years
71- if ( totalMonths <= 36 ) return 4 ; // Every 4 months if <= 3 years
72- if ( totalMonths <= 48 ) return 6 ; // Every 6 months if <= 4 years
73- return 12 ; // Every year for longer periods
66+
67+ // Determine desired number of labels based on screen size
68+ let targetLabels = isDesktop ? 6 : 3 ;
69+
70+ // Calculate interval that would give us roughly the desired number of labels
71+ let interval = Math . max ( 1 , Math . floor ( totalMonths / targetLabels ) ) ;
72+
73+ return interval ;
7474 } ;
7575
7676 // Modify the monthlyData generation
@@ -85,7 +85,9 @@ export default function BlogHistory({ posts = [], isDesktop }: BlogHistoryProps)
8585 } ) ;
8686
8787 const interval = getOptimalInterval ( months ) ;
88- const showLabel = index % interval === 0 ;
88+ const showLabel = index === 0 ||
89+ index === months . length - 1 ||
90+ index % interval === 0 ;
8991
9092 // Create an object with individual post sizes
9193 const postSizes = postsInMonth . reduce (
@@ -158,7 +160,9 @@ export default function BlogHistory({ posts = [], isDesktop }: BlogHistoryProps)
158160 < XAxis
159161 dataKey = "monthDisplay"
160162 type = "category"
161- interval = { getOptimalInterval ( months ) - 1 }
163+ interval = { ( index ) => {
164+ return monthlyData [ index ] . showLabel ;
165+ } }
162166 height = { 60 }
163167 tick = { { fontSize : 14 } }
164168 />
0 commit comments