@@ -5,6 +5,7 @@ import type {
5
5
DownloadDataPoint ,
6
6
PackageDownloadsRecentVersion ,
7
7
} from "../../../utils/api_types.ts" ;
8
+ import type ApexCharts from "apexcharts" ;
8
9
9
10
interface Props {
10
11
downloads : PackageDownloadsRecentVersion [ ] ;
@@ -14,8 +15,7 @@ export type AggregationPeriod = "daily" | "weekly" | "monthly";
14
15
15
16
export function DownloadChart ( props : Props ) {
16
17
const chartDivRef = useRef < HTMLDivElement > ( null ) ;
17
- // deno-lint-ignore no-explicit-any
18
- const chartRef = useRef < any > ( null ) ;
18
+ const chartRef = useRef < ApexCharts > ( null ) ;
19
19
const [ graphRendered , setGraphRendered ] = useState ( false ) ;
20
20
21
21
useEffect ( ( ) => {
@@ -63,7 +63,7 @@ export function DownloadChart(props: Props) {
63
63
setGraphRendered ( true ) ;
64
64
} ) ( ) ;
65
65
return ( ) => {
66
- chartRef . current . destroy ( ) ;
66
+ chartRef . current ? .destroy ( ) ;
67
67
chartRef . current = null ;
68
68
} ;
69
69
} , [ ] ) ;
@@ -78,7 +78,7 @@ export function DownloadChart(props: Props) {
78
78
< select
79
79
id = "aggregationPeriod"
80
80
onChange = { ( e ) =>
81
- chartRef . current . updateSeries (
81
+ chartRef . current ? .updateSeries (
82
82
getSeries (
83
83
props . downloads ,
84
84
e . currentTarget . value as AggregationPeriod ,
@@ -158,7 +158,7 @@ export function normalize(
158
158
dataPoints : DownloadDataPoint [ ] ,
159
159
xValues : string [ ] ,
160
160
aggregationPeriod : AggregationPeriod ,
161
- ) : [ Date , number ] [ ] {
161
+ ) : [ number , number ] [ ] {
162
162
const normalized : { [ key : string ] : number } = { } ;
163
163
for ( const date of xValues ) {
164
164
normalized [ date ] = 0 ;
@@ -176,7 +176,7 @@ export function normalize(
176
176
177
177
return Object . entries ( normalized ) . map ( (
178
178
[ key , value ] ,
179
- ) => [ new Date ( key ) , value ] ) ;
179
+ ) => [ new Date ( key ) . getTime ( ) , value ] ) ;
180
180
}
181
181
182
182
function getSeries (
@@ -193,7 +193,7 @@ function getSeries(
193
193
) . flat ( ) ;
194
194
195
195
const xValues = collectX (
196
- dataPointsToDisplay . map ( ( version ) => version . downloads ) . flat ( ) ,
196
+ dataPointsWithDownloads . map ( ( version ) => version . downloads ) . flat ( ) ,
197
197
aggregationPeriod ,
198
198
) ;
199
199
0 commit comments