Skip to content

Commit 4b2a1e2

Browse files
committed
fix(svg): use actual weekday for tower positioning
1 parent 211cbb5 commit 4b2a1e2

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

lib/svg/layout.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,22 @@ it('assigns correct row and col values based on week/day position', () => {
223223
weeks: [
224224
{
225225
contributionDays: [
226+
{ contributionCount: 1, date: '2024-06-09' },
226227
{ contributionCount: 1, date: '2024-06-10' },
227228
{ contributionCount: 1, date: '2024-06-11' },
228-
{ contributionCount: 1, date: '2024-06-12' },
229229
],
230230
},
231231
{
232232
contributionDays: [
233-
{ contributionCount: 1, date: '2024-06-13' },
234-
{ contributionCount: 1, date: '2024-06-14' },
235-
{ contributionCount: 1, date: '2024-06-15' },
233+
{ contributionCount: 1, date: '2024-06-16' },
234+
{ contributionCount: 1, date: '2024-06-17' },
235+
{ contributionCount: 1, date: '2024-06-18' },
236236
],
237237
},
238238
],
239239
} as unknown as ContributionCalendar;
240240

241-
const towers = computeTowers(calendar, 'linear', '2024-06-15');
241+
const towers = computeTowers(calendar, 'linear', '2024-06-18');
242242

243243
expect(towers[0].row).toBe(0);
244244
expect(towers[0].col).toBe(0);

lib/svg/layout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export function computeTowers(
123123
? `TODAY: ${day.date}: ${count} ${unit}`
124124
: `${day.date}: ${count} ${unit}`;
125125

126-
const coords = projectIsometric(i, j);
126+
const dayOfWeekIndex = new Date(day.date).getUTCDay();
127+
const coords = projectIsometric(i, dayOfWeekIndex);
127128

128129
let intensityLevel = 0;
129130
if (hasCommits) {
@@ -153,7 +154,7 @@ export function computeTowers(
153154
strokeOpacity: isGhost ? 0.3 : 0,
154155
strokeWidth: isGhost ? 0.5 : 0,
155156
row: i,
156-
col: j,
157+
col: dayOfWeekIndex,
157158
intensityLevel,
158159
});
159160
});

0 commit comments

Comments
 (0)