11import { useState } from 'react' ;
22import DatePicker from "react-datepicker" ;
3- import "react-datepicker/dist/react-datepicker.css" ;
43import {
54 XAxis ,
65 YAxis ,
76 CartesianGrid ,
87 Tooltip ,
98 Area ,
109 AreaChart ,
10+ Bar ,
11+ BarChart ,
1112 ResponsiveContainer ,
1213 } from "recharts" ;
1314import { Footer } from "~/components/general" ;
1415import h from "./main.module.sass" ;
1516import { useData } from "vike-react/useData" ;
17+ import { Switch } from '@blueprintjs/core' ;
1618
1719
1820function getDateFromYearAndWeek ( year : number , week : number ) : Date {
@@ -38,6 +40,7 @@ export function Page() {
3840 const [ checkinBound , setCheckin ] = useState ( [ lower , upper ] ) ;
3941 const [ signupBound , setSignup ] = useState ( [ lower , upper ] ) ;
4042 const [ activeBound , setActive ] = useState ( [ lower , upper ] ) ;
43+ const [ showBar , setShowBar ] = useState ( false ) ;
4144
4245 // new API doesn't return all data
4346 const { data } = useData ( ) ;
@@ -145,15 +148,32 @@ export function Page() {
145148 console . log ( "Scaled the month: " , currentName )
146149
147150 // chart array
148- let areaArr = [
151+ const areaArr = [
149152 h ( CartesianGrid , { strokeDasharray : "3 3" } ) ,
150153 h ( XAxis , { dataKey : "name" , stroke : "var(--text-emphasized-color)" } ) ,
151154 h ( YAxis , { stroke : "var(--text-emphasized-color)" } ) ,
152155 h ( Tooltip ) ,
153156 h ( Area , { type : "monotone" , dataKey : "Total" , stroke : "#8884d8" , fill : "#8884d8" } ) ,
154157 ]
155158
159+ const barArr = [
160+ h ( CartesianGrid , { strokeDasharray : "3 3" } ) ,
161+ h ( XAxis , { dataKey : "name" , stroke : "var(--text-emphasized-color)" } ) ,
162+ h ( YAxis , { stroke : "var(--text-emphasized-color)" } ) ,
163+ h ( Tooltip ) ,
164+ h ( Bar , { dataKey : "Total" , fill : "#8884d8" } ) ,
165+ ] ;
166+
167+ const arr = showBar ? barArr : areaArr ;
168+ const ChartComponent = showBar ? BarChart : AreaChart ;
169+
156170 return h ( 'div' , { className : "container" } , [
171+ h ( Switch , {
172+ className : "switch" ,
173+ value : showBar ,
174+ label : "Show bar charts" ,
175+ onChange : ( ) => setShowBar ( ! showBar )
176+ } ) ,
157177 h ( "div" , { className : 'metrics' } , [
158178 h ( "div" , { className : 'header' } , [
159179 h ( "h1" , "Metrics" ) ,
@@ -188,7 +208,7 @@ export function Page() {
188208 h ( "div" , { className : 'checkins_week' } , [
189209 h ( "h2" , "Checkins by week" ) ,
190210 h ( ResponsiveContainer , { width : "100%" , height : 300 } , [
191- h ( AreaChart , { className : "chart" , data : checkins_by_week } , areaArr ) ,
211+ h ( ChartComponent , { className : "chart" , data : checkins_by_week } , arr ) ,
192212 ] ) ,
193213 h ( 'div' , { className : 'date-picker' } , [
194214 h ( 'p' , 'Select date range:' ) ,
@@ -200,13 +220,13 @@ export function Page() {
200220 h ( "div" , { className : 'checkins_month' } , [
201221 h ( "h2" , "Checkins by month" ) ,
202222 h ( ResponsiveContainer , { width : "100%" , height : 300 } , [
203- h ( AreaChart , { className : "chart" , data : checkins_by_month } , areaArr )
223+ h ( ChartComponent , { className : "chart" , data : checkins_by_month } , arr )
204224 ] ) ,
205225 ] ) ,
206226 h ( "div" , { className : 'signups_week' } , [
207227 h ( "h2" , "Signups by week" ) ,
208228 h ( ResponsiveContainer , { width : "100%" , height : 300 } , [
209- h ( AreaChart , { className : "chart" , data : signups_by_week } , areaArr ) ,
229+ h ( ChartComponent , { className : "chart" , data : signups_by_week } , arr ) ,
210230 ] ) ,
211231 h ( 'div' , { className : 'date-picker' } , [
212232 h ( 'p' , 'Select date range:' ) ,
@@ -218,13 +238,13 @@ export function Page() {
218238 h ( "div" , { className : 'signups_month' } , [
219239 h ( "h2" , "Signups by month" ) ,
220240 h ( ResponsiveContainer , { width : "100%" , height : 300 } , [
221- h ( AreaChart , { className : "chart" , data : signups_by_month } , areaArr )
241+ h ( ChartComponent , { className : "chart" , data : signups_by_month } , arr )
222242 ] ) ,
223243 ] ) ,
224244 h ( "div" , { className : 'users_week' } , [
225245 h ( "h2" , "Active Users by week" ) ,
226246 h ( ResponsiveContainer , { width : "100%" , height : 300 } , [
227- h ( AreaChart , { className : "chart" , data : active_users_by_week } , areaArr ) ,
247+ h ( ChartComponent , { className : "chart" , data : active_users_by_week } , arr ) ,
228248 ] ) ,
229249 h ( 'div' , { className : 'date-picker' } , [
230250 h ( 'p' , 'Select date range:' ) ,
@@ -236,7 +256,7 @@ export function Page() {
236256 h ( "div" , { className : 'users_month' } , [
237257 h ( "h2" , "Active Users by month" ) ,
238258 h ( ResponsiveContainer , { width : "100%" , height : 300 } , [
239- h ( AreaChart , { className : "chart" , data : active_users_by_month } , areaArr )
259+ h ( ChartComponent , { className : "chart" , data : active_users_by_month } , arr )
240260 ] ) ,
241261 ] ) ,
242262 ] )
0 commit comments