@@ -41,9 +41,9 @@ export type VersionDownloadChartProps = {
4141 maxDaysShown ?: number ;
4242
4343 /**
44- * The number of days between ticks
44+ * The number of days between ticks. Or "month" for ticks at the start of each month.
4545 */
46- tickInterval ?: number ;
46+ tickInterval ?: number | "month" ;
4747
4848 /**
4949 * The maximum number of "popular" versions show (see below).
@@ -102,7 +102,7 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
102102 showTooltip,
103103 unit,
104104 versionLabeler,
105- tickInterval,
105+ tickInterval = 7 ,
106106 theme,
107107 tooltipTheme,
108108} ) => {
@@ -164,14 +164,28 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
164164 const firstDate = filteredHistory ?. points [ 0 ] ?. date ;
165165 const lastDate = filteredHistory ?. points [ lastDateIndex ] ?. date ;
166166
167- const msInDay = 1000 * 60 * 60 * 24 ;
168167 const ticks : number [ ] = [ ] ;
169- for (
170- let date = firstDate ?? 0 ;
171- date <= ( lastDate ?? 0 ) ;
172- date += msInDay * ( tickInterval ?? 7 )
173- ) {
174- ticks . push ( date ) ;
168+ if ( tickInterval === "month" ) {
169+ if ( firstDate && lastDate ) {
170+ const currentDate = new Date ( firstDate ) ;
171+ currentDate . setMonth ( currentDate . getMonth ( ) + 1 ) ;
172+ currentDate . setDate ( 1 ) ;
173+ currentDate . setHours ( 0 , 0 , 0 , 0 ) ;
174+
175+ while ( + currentDate <= lastDate ) {
176+ ticks . push ( currentDate . getTime ( ) ) ;
177+ currentDate . setMonth ( currentDate . getMonth ( ) + 1 ) ;
178+ }
179+ }
180+ } else {
181+ const msInDay = 1000 * 60 * 60 * 24 ;
182+ for (
183+ let date = firstDate ?? 0 ;
184+ date <= ( lastDate ?? 0 ) ;
185+ date += msInDay * tickInterval
186+ ) {
187+ ticks . push ( date ) ;
188+ }
175189 }
176190
177191 return (
@@ -191,10 +205,18 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
191205 scale = "time"
192206 domain = { [ "dataMin" , "dataMax" ] }
193207 tickFormatter = { ( unixTime ) =>
194- new Date ( unixTime ) . toLocaleDateString ( "en-US" , {
195- month : "short" ,
196- day : "numeric" ,
197- } )
208+ new Date ( unixTime ) . toLocaleDateString (
209+ "en-US" ,
210+ tickInterval === "month"
211+ ? {
212+ month : "short" ,
213+ year : "numeric" ,
214+ }
215+ : {
216+ month : "short" ,
217+ day : "numeric" ,
218+ }
219+ )
198220 }
199221 />
200222 < YAxis
0 commit comments