(props: {
data: { date: string; value: number }[];
ylabel: string;
})
| 72 | const msToDay = 1000 * 60 * 60 * 24; |
| 73 | |
| 74 | function DatesBarGraph(props: { |
| 75 | data: { date: string; value: number }[]; |
| 76 | ylabel: string; |
| 77 | }) { |
| 78 | if (!props.data || props.data.length == 0) return null; |
| 79 | |
| 80 | const chartData = props.data |
| 81 | .map((d) => ({ date: Date.parse(d.date) / msToDay, value: d.value })) |
| 82 | .sort((a, b) => a.date - b.date); |
| 83 | |
| 84 | const xRange = chartData[chartData.length - 1].date - chartData[0].date; |
| 85 | const offset = Math.ceil(xRange * 0.1); |
| 86 | |
| 87 | const intToDate = (date: number) => formatDate(new Date(date * msToDay)); |
| 88 | |
| 89 | return ( |
| 90 | <> |
| 91 | <ResponsiveContainer width="99%" aspect={2}> |
| 92 | <ComposedChart |
| 93 | data={chartData} |
| 94 | margin={{ |
| 95 | top: 20, |
| 96 | right: 30, |
| 97 | left: 20, |
| 98 | bottom: 0, |
| 99 | }} |
| 100 | maxBarSize={50} |
| 101 | > |
| 102 | <XAxis |
| 103 | dataKey="date" |
| 104 | type="number" |
| 105 | scale="time" |
| 106 | domain={[`dataMin - ${offset}`, `dataMax + ${offset}`]} |
| 107 | tickFormatter={intToDate} |
| 108 | /> |
| 109 | <YAxis allowDecimals={false}> |
| 110 | <Label |
| 111 | value={props.ylabel} |
| 112 | angle={-90} |
| 113 | style={{ textAnchor: "middle" }} |
| 114 | position="insideLeft" |
| 115 | offset={-5} |
| 116 | /> |
| 117 | </YAxis> |
| 118 | <Tooltip |
| 119 | labelFormatter={intToDate} |
| 120 | formatter={(value) => |
| 121 | `${Math.round((value as number) * 100) / 100}` |
| 122 | } |
| 123 | /> |
| 124 | |
| 125 | <Bar dataKey="value" fill="#8884d8" /> |
| 126 | </ComposedChart> |
| 127 | </ResponsiveContainer> |
| 128 | </> |
| 129 | ); |
| 130 | } |
| 131 |
nothing calls this directly
no outgoing calls
no test coverage detected