Skip to content

Commit

Permalink
Fix heat map cell size
Browse files Browse the repository at this point in the history
  • Loading branch information
O4epegb committed Sep 18, 2024
1 parent 7496ccf commit a93223b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 17 additions & 6 deletions apps/web/src/screens/Player/Calendar/HeatMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export type DayData = {
winrate: number
}

export const cellSize = 20
export const cellGap = 2
const cellSize = 20
const cellSizeCss = 'size-[20px]'
const cellGap = 2
export const monthGap = 8
export const cellPlusGap = cellSize + cellGap
export const cellAndGap = cellSize + cellGap

export const HeatMap = ({
monthesWithDays,
Expand All @@ -26,7 +27,12 @@ export const HeatMap = ({
invisible?: boolean
}) => {
return (
<div className={cn('flex gap-2', invisible && 'opacity-0')}>
<div
style={{
gap: `${monthGap}px`,
}}
className={cn('flex', invisible && 'opacity-0')}
>
{monthesWithDays.map((month, monthIndex) => {
const firstDay = month[0]

Expand All @@ -48,7 +54,12 @@ export const HeatMap = ({
<span className="text-xs font-semibold">{firstDay.date.format('MMM')}</span>
</Tooltip>
</div>
<div className="grid grid-flow-col grid-rows-7 gap-0.5">
<div
style={{
gap: `${cellGap}px`,
}}
className="grid grid-flow-col grid-rows-7"
>
{month.map((day, dayIndex) => {
let daysToPad = 0

Expand Down Expand Up @@ -77,7 +88,7 @@ export const HeatMap = ({
}
>
<div
className={cn('flex h-5 w-5 items-center justify-center rounded', {
className={cn('flex items-center justify-center rounded', cellSizeCss, {
'border border-zinc-300 dark:border-zinc-400': day.games < maxGames * 0.9,
})}
>
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/screens/Player/Calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { Tooltip } from '~/components/ui/Tooltip'
import { useElementWidth } from '~/hooks/useElementWidth'
import { usePlayerPageContext } from '~/screens/Player/context'
import { date, formatNumber, pluralize } from '~/utils'
import { cellPlusGap, DayData, HeatMap, monthGap } from './HeatMap'
import { cellAndGap, DayData, HeatMap, monthGap } from './HeatMap'
import { HistoryDialog } from './HistoryDialog'

export const Calendar = () => {
const { player } = usePlayerPageContext()
const [ref, wrapperWidth] = useElementWidth<HTMLDivElement>()

const days = useMemo(() => {
let widthLeft = wrapperWidth - cellPlusGap
let widthLeft = wrapperWidth - cellAndGap
const result: dayjs.Dayjs[] = []

let current = date().startOf('day')
Expand All @@ -27,9 +27,9 @@ export const Calendar = () => {
const next = current.subtract(1, 'day')

if (next.month() !== current.month()) {
widthLeft -= cellPlusGap + monthGap
widthLeft -= cellAndGap + monthGap
} else if (next.week() !== current.week()) {
widthLeft -= cellPlusGap
widthLeft -= cellAndGap
}

current = next
Expand Down

0 comments on commit a93223b

Please sign in to comment.