Skip to content

Commit

Permalink
fix: add first day offset, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Battlesquid committed Dec 19, 2024
1 parent 42c1c31 commit d99ab1c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/app/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ import { ResultOf } from "gql.tada";
import { ContributionQuery } from "./query";

export type ContributionWeeks = NonNullable<ResultOf<typeof ContributionQuery>["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"];

export type ContributionWeek = ContributionWeeks[number];

export type ContributionDay = ContributionWeeks[number]["contributionDays"][number];
10 changes: 3 additions & 7 deletions packages/app/src/components/contribution_tower.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Card, Text } from "@mantine/core";
import { MeshProps } from "@react-three/fiber";
import { useState } from "react";
import * as THREE from "three";
import { Card, Text } from "@mantine/core";
import { ResultOf } from "gql.tada";
import { ContributionQuery } from "../api/query";
import { ContributionDay } from "../api/types";
import { t } from "../App";

interface ContributionTowerProps extends MeshProps {
Expand All @@ -13,9 +12,7 @@ interface ContributionTowerProps extends MeshProps {
size: number;
defaultColor: string;
showContributionColor: boolean;
day: NonNullable<
ResultOf<typeof ContributionQuery>["user"]
>["contributionsCollection"]["contributionCalendar"]["weeks"][number]["contributionDays"][number];
day: ContributionDay;
}

export function ContributionTower(props: ContributionTowerProps) {
Expand All @@ -36,7 +33,6 @@ export function ContributionTower(props: ContributionTowerProps) {
position={[x, height / 2, y]}
onClick={(event) => {
event.stopPropagation();
console.log(x, y);
click(!clicked);
}}
onPointerMove={(event) => {
Expand Down
1 change: 0 additions & 1 deletion packages/app/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function Sidebar(props: SidebarProps) {

useEffect(() => {
if (!ok) {
console.log(ok)
setModified(true);
}
}, [name]);
Expand Down
10 changes: 8 additions & 2 deletions packages/app/src/components/skyline_model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect } from "react";
import { defaults, SkylineModelParameters } from "../parameters";
import { useSceneStore } from "../stores";
import { ContributionTower } from "./contribution_tower";
import { ContributionWeeks } from "../api/types";
import { ContributionWeek, ContributionWeeks } from "../api/types";

export interface SkylineModelProps {
parameters: SkylineModelParameters;
Expand Down Expand Up @@ -40,6 +40,12 @@ export function SkylineModel(props: SkylineModelProps) {
}
}, [props.parameters.towerSize, props.parameters.towerDampening, props.parameters.name, props.parameters.year, props.parameters.padding, props.parameters.font]);

const calculateFirstDayOffset = (week: ContributionWeek, weekNo: number): number => {
return weekNo === 0
? new Date(week.firstDay).getUTCDay()
: 0;
}

return (
<group>
{weeks.map((week, i) =>
Expand All @@ -48,7 +54,7 @@ export function SkylineModel(props: SkylineModelProps) {
key={day.date.toString()}
day={day}
x={i * parameters.towerSize - length / 2 + parameters.towerSize / 2}
y={j * parameters.towerSize - width / 2 + parameters.towerSize / 2}
y={(j + calculateFirstDayOffset(week, i)) * parameters.towerSize - width / 2 + parameters.towerSize / 2}
height={day.contributionCount * parameters.towerSize / parameters.towerDampening + parameters.towerSize / parameters.towerDampening}
size={parameters.towerSize}
defaultColor={parameters.color}
Expand Down

0 comments on commit d99ab1c

Please sign in to comment.