Skip to content

Commit

Permalink
Fix layout for Treemap in electric cars page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ru Chern Chong committed Jan 1, 2024
1 parent 8127bb4 commit cf8bbbd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions app/(cars)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
POPULAR_MAKES_THRESHOLD,
} from "@/config";
import { sortByMake } from "@/utils/sortByMake";
import type { Car } from "@/types";
import { Car } from "@/types";
import { WebSite, WithContext } from "schema-dts";
import { fetchApi } from "@/utils/fetchApi";

Expand All @@ -17,14 +17,15 @@ export const runtime = "edge";
const Home = async () => {
const electricCars = await fetchApi<Car[]>(API_URL, { cache: "no-store" });

const totals = new Map();
electricCars.forEach((car) => {
if (totals.has(car.make)) {
totals.set(car.make, totals.get(car.make) + car.number);
const totals: Map<string, number> = new Map();
electricCars.forEach(({ make, number }) => {
if (totals.has(make)) {
totals.set(make, (totals.get(make) as number) + number);
} else {
totals.set(car.make, car.number);
totals.set(make, number);
}
});

const popularMakes = Array.from(totals, ([make, number]) => ({
make,
number,
Expand Down
2 changes: 1 addition & 1 deletion app/coe/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const COEPage = async () => {
monthlyResults.filter(({ bidding_no }) => bidding_no === biddingRound);

return (
<div className="mx-auto flex max-w-7xl flex-col gap-y-8">
<div className="flex flex-col gap-y-8">
<HistoricalResult data={historicalResults} />
{biddingRounds.map((round) => {
return (
Expand Down
6 changes: 3 additions & 3 deletions components/CarTreemap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const CarTreemap = ({ data, popularMakes }: CarTreemapProps) => {
const filteredCars = useMemo(
() =>
cars.filter((car) =>
popularMakes.some(({ make }: Pick<Car, "make">) => make === car.make),
popularMakes.some(({ make }: Car) => make === car.make),
),
[cars, popularMakes],
);
Expand Down Expand Up @@ -61,13 +61,13 @@ export const CarTreemap = ({ data, popularMakes }: CarTreemapProps) => {
return (
filteredCars && (
<div className="flex flex-col items-center gap-y-4">
<div className="h-[600px] w-full md:w-[600px]">
<div className="w-full">
<ApexChart
options={options}
series={series}
type="treemap"
width="100%"
height="100%"
height={600}
/>
</div>
<label htmlFor="months-select">
Expand Down

0 comments on commit cf8bbbd

Please sign in to comment.