Skip to content

Commit

Permalink
feat: rename cumulative to history in Repo pages (#3195)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeucapua committed Apr 17, 2024
1 parent fa21314 commit 8a33e24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
20 changes: 7 additions & 13 deletions components/Graphs/ForksChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { BiGitRepoForked } from "react-icons/bi";
import { type DayRange } from "components/shared/DayRangePicker";
import { type StatsType } from "lib/hooks/api/useFetchMetricStats";
import { getCumulativeForksHistogramToDays, getDailyForksHistogramToDays, getTicks } from "lib/utils/repo-page-utils";
import { getHistoryForksHistogramToDays, getDailyForksHistogramToDays, getTicks } from "lib/utils/repo-page-utils";

import Card from "components/atoms/Card/card";
import Button from "components/shared/Button/button";
Expand All @@ -30,12 +30,9 @@ type ForksChartProps = {
};

export default function ForksChart({ stats, total, syncId, range = 30, isLoading }: ForksChartProps) {
const [category, setCategory] = useState<"daily" | "cumulative">("daily");
const [category, setCategory] = useState<"daily" | "history">("daily");
const dailyData = useMemo(() => getDailyForksHistogramToDays({ stats, range }), [stats, range]);
const cumulativeData = useMemo(
() => getCumulativeForksHistogramToDays({ stats, total, range }),
[stats, total, range]
);
const historyData = useMemo(() => getHistoryForksHistogramToDays({ stats, total, range }), [stats, total, range]);
const bucketTicks = useMemo(() => getTicks({ histogram: dailyData, range }), [dailyData, range]);

const renderChart = () => {
Expand All @@ -50,9 +47,9 @@ export default function ForksChart({ stats, total, syncId, range = 30, isLoading
<Bar dataKey="forks_count" fill="#FF5100" />
</BarChart>
);
case "cumulative":
case "history":
return (
<LineChart data={cumulativeData} syncId={syncId}>
<LineChart data={historyData} syncId={syncId}>
<XAxis dataKey="bucket" tick={false} />
<YAxis domain={["auto", "auto"]} />
<Tooltip content={CustomTooltip} filterNull={false} />
Expand All @@ -78,11 +75,8 @@ export default function ForksChart({ stats, total, syncId, range = 30, isLoading
<Button variant={category === "daily" ? "outline" : "default"} onClick={() => setCategory("daily")}>
Daily
</Button>
<Button
variant={category === "cumulative" ? "outline" : "default"}
onClick={() => setCategory("cumulative")}
>
Cumulative
<Button variant={category === "history" ? "outline" : "default"} onClick={() => setCategory("history")}>
History
</Button>
</div>
</>
Expand Down
20 changes: 7 additions & 13 deletions components/Graphs/StarsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
CartesianGrid,
} from "recharts";
import { FaStar } from "react-icons/fa6";
import { getCumulativeStarsHistogramToDays, getDailyStarsHistogramToDays, getTicks } from "lib/utils/repo-page-utils";
import { getHistoryStarsHistogramToDays, getDailyStarsHistogramToDays, getTicks } from "lib/utils/repo-page-utils";
import { type DayRange } from "components/shared/DayRangePicker";
import { type StatsType } from "lib/hooks/api/useFetchMetricStats";
import Card from "components/atoms/Card/card";
Expand All @@ -30,12 +30,9 @@ type StarsChartProps = {
};

export default function StarsChart({ stats, total, syncId, range = 30, isLoading }: StarsChartProps) {
const [category, setCategory] = useState<"daily" | "cumulative">("daily");
const [category, setCategory] = useState<"daily" | "history">("daily");
const dailyData = useMemo(() => getDailyStarsHistogramToDays({ stats, range }), [stats, range]);
const cumulativeData = useMemo(
() => getCumulativeStarsHistogramToDays({ stats, total, range }),
[stats, total, range]
);
const historyData = useMemo(() => getHistoryStarsHistogramToDays({ stats, total, range }), [stats, total, range]);
const bucketTicks = useMemo(() => getTicks({ histogram: dailyData, range }), [dailyData, range]);

const renderChart = () => {
Expand All @@ -50,9 +47,9 @@ export default function StarsChart({ stats, total, syncId, range = 30, isLoading
<Bar dataKey="star_count" fill="#FF5100" />
</BarChart>
);
case "cumulative":
case "history":
return (
<LineChart data={cumulativeData} syncId={syncId}>
<LineChart data={historyData} syncId={syncId}>
<XAxis dataKey="bucket" ticks={bucketTicks} tick={CustomTick} />
<YAxis domain={["auto", "auto"]} />
<Tooltip content={CustomTooltip} filterNull={false} />
Expand All @@ -78,11 +75,8 @@ export default function StarsChart({ stats, total, syncId, range = 30, isLoading
<Button variant={category === "daily" ? "outline" : "default"} onClick={() => setCategory("daily")}>
Daily
</Button>
<Button
variant={category === "cumulative" ? "outline" : "default"}
onClick={() => setCategory("cumulative")}
>
Cumulative
<Button variant={category === "history" ? "outline" : "default"} onClick={() => setCategory("history")}>
History
</Button>
</div>
</>
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/repo-page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function getDailyStarsHistogramToDays({
return result;
}

export function getCumulativeStarsHistogramToDays({
export function getHistoryStarsHistogramToDays({
stats,
range,
total,
Expand Down Expand Up @@ -229,7 +229,7 @@ export function getDailyForksHistogramToDays({
return result;
}

export function getCumulativeForksHistogramToDays({
export function getHistoryForksHistogramToDays({
stats,
range,
total,
Expand Down

0 comments on commit 8a33e24

Please sign in to comment.