@@ -41,9 +41,9 @@ export type VersionDownloadChartProps = {
41
41
maxDaysShown ?: number ;
42
42
43
43
/**
44
- * The number of days between ticks
44
+ * The number of days between ticks. Or "month" for ticks at the start of each month.
45
45
*/
46
- tickInterval ?: number ;
46
+ tickInterval ?: number | "month" ;
47
47
48
48
/**
49
49
* The maximum number of "popular" versions show (see below).
@@ -102,7 +102,7 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
102
102
showTooltip,
103
103
unit,
104
104
versionLabeler,
105
- tickInterval,
105
+ tickInterval = 7 ,
106
106
theme,
107
107
tooltipTheme,
108
108
} ) => {
@@ -164,14 +164,28 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
164
164
const firstDate = filteredHistory ?. points [ 0 ] ?. date ;
165
165
const lastDate = filteredHistory ?. points [ lastDateIndex ] ?. date ;
166
166
167
- const msInDay = 1000 * 60 * 60 * 24 ;
168
167
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
+ }
175
189
}
176
190
177
191
return (
@@ -191,10 +205,18 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
191
205
scale = "time"
192
206
domain = { [ "dataMin" , "dataMax" ] }
193
207
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
+ )
198
220
}
199
221
/>
200
222
< YAxis
0 commit comments