({ startDate, endDate }: propsType)
| 21 | }; |
| 22 | |
| 23 | export default function UsageGraph({ startDate, endDate }: propsType) { |
| 24 | const { data: selectedProject } = useSelectedProject(); |
| 25 | |
| 26 | const stats = useStats(selectedProject?.id || "", startDate, endDate); |
| 27 | |
| 28 | const data = useMemo(() => { |
| 29 | return ( |
| 30 | stats.data?.periods.map(({ period, numQueries }) => ({ |
| 31 | period, |
| 32 | Requests: numQueries, |
| 33 | })) || [] |
| 34 | ); |
| 35 | }, [stats.data]); |
| 36 | |
| 37 | const [requestsMainColor, requestsFill] = useToken("colors", ["blue.700", "blue.500"]); |
| 38 | |
| 39 | const longestRequestsLabelLength = data |
| 40 | .map((c) => c.Requests.toString()) |
| 41 | .reduce((acc, cur) => (cur.length > acc ? cur.length : acc), 0); |
| 42 | |
| 43 | return ( |
| 44 | <ResponsiveContainer width="100%" height={400}> |
| 45 | <ComposedChart data={data} margin={{ top: 5, right: 24, left: 4, bottom: 5 }}> |
| 46 | <XAxis |
| 47 | dataKey="period" |
| 48 | tickMargin={4} |
| 49 | tickFormatter={(dateStr: string) => formatToUTCDayMonth(dateStr)} |
| 50 | /> |
| 51 | <YAxis |
| 52 | yAxisId="left" |
| 53 | dataKey="Requests" |
| 54 | orientation="left" |
| 55 | width={longestRequestsLabelLength * 10 + 8} |
| 56 | /> |
| 57 | <Tooltip content={<CustomTooltip />} /> |
| 58 | <Legend /> |
| 59 | <CartesianGrid stroke="#f5f5f5" /> |
| 60 | <Area |
| 61 | type="monotone" |
| 62 | dataKey="Requests" |
| 63 | fill={requestsFill} |
| 64 | stroke={requestsMainColor} |
| 65 | yAxisId="left" |
| 66 | /> |
| 67 | </ComposedChart> |
| 68 | </ResponsiveContainer> |
| 69 | ); |
| 70 | } |
nothing calls this directly
no test coverage detected