~bigbes/lethe

ref: c9442a6b8a6caf8bf82ba241ce2c464eb2efa586 lethe/web/src/primitives/HourBars.tsx -rw-r--r-- 1.3 KiB
c9442a6b — Eugene Blikh docs(lethe-web-ui-aggregates): record execute, verify, review a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type React from 'react'
import { EmptyState } from './EmptyState'

interface HourBarsProps {
  hours: { hour: number; count: number }[]
}

export function HourBars({ hours }: HourBarsProps): React.JSX.Element {
  if (hours.length !== 24) {
    return <EmptyState glyph="∅" copy="no activity yet" />
  }

  const maxCount = Math.max(...hours.map(h => h.count), 1)

  return (
    <>
      <svg
        viewBox="0 0 240 70"
        style={{ display: 'block', width: '100%', height: 70 }}
        preserveAspectRatio="none"
      >
        {hours.map(({ hour, count }) => {
          const barH = Math.max(2, (count / maxCount) * 68)
          const x = hour * 10 + 1
          const isOffPeak = hour < 9 || hour > 19
          return (
            <rect
              key={hour}
              x={x}
              y={70 - barH}
              width={8}
              height={barH}
              fill="var(--accent)"
              opacity={isOffPeak ? 0.45 : 0.85}
            />
          )
        })}
      </svg>
      <div
        className="flex muted mono"
        style={{ justifyContent: 'space-between', fontSize: 9.5, marginTop: 4 }}
      >
        <span>00</span>
        <span>06</span>
        <span>12</span>
        <span>18</span>
        <span>24</span>
      </div>
    </>
  )
}