import numeral from 'numeral'
export const Chart = ({ data }) => {
if (data) {
const numbers = normalize(data)
return (
{numbers.map(({ value, normalizedValue, date }, i) => (
))}
)
}
}
const BarMaker = ({ value, height, date }) => {
const h = `h-[${height}px]`
const showValue = numeral(value).format('0,0')
return (
)
}
export const ChartLoading = () => {
return (
{Array.from(Array(30).keys()).map((i) => (
))}
)
}
const BarMakerLoading = () => {
return (
)
}
const normalize = (data) => {
const maxHeight = 300
let max = 0
data.map((entry) => (entry.total > max ? (max = entry.total) : null))
const newList = data.map((day) => {
const date = new Date(day.date)
const formattedDate = date.getUTCMonth() + 1 + '/' + date.getUTCDate()
const n = (day.total / max) * maxHeight
return {
value: day.total,
date: formattedDate,
normalizedValue: Math.trunc(n),
}
})
return newList
}