Skip to content

Commit

Permalink
Merge pull request #18 from ruchernchong/17-remove-charts-and-use-res…
Browse files Browse the repository at this point in the history
…ponsive-tables-only-for-mobile-viewport

Fix squashed charts on mobile
  • Loading branch information
ruchernchong authored Jan 9, 2024
2 parents ddd396a + 69d975b commit 0604274
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 39 deletions.
4 changes: 2 additions & 2 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 { Car } from "@/types";
import { Car, PopularMake } from "@/types";
import { WebSite, WithContext } from "schema-dts";
import { fetchApi } from "@/utils/fetchApi";

Expand All @@ -26,7 +26,7 @@ const Home = async () => {
}
});

const popularMakes = Array.from(totals, ([make, number]) => ({
const popularMakes: PopularMake[] = Array.from(totals, ([make, number]) => ({
make,
number,
}))
Expand Down
15 changes: 3 additions & 12 deletions components/CarInfographic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ export const CarInfographic = ({
new Date(),
);

const grid = {
padding: {
left: 90,
right: 90,
},
};

const chartOptions = {
chart: {
id: "target-chart",
Expand All @@ -46,9 +39,7 @@ export const CarInfographic = ({
categories,
},
yaxis: {
title: {
text: "Number of Registrations",
},
title: { text: "Number of Registrations" },
},
tooltip: {
intersect: false,
Expand All @@ -57,7 +48,6 @@ export const CarInfographic = ({
format: "MMM yyyy",
},
},
grid,
};

const brushOptions = {
Expand All @@ -71,7 +61,7 @@ export const CarInfographic = ({
selection: {
enabled: true,
xaxis: {
min: subMonths(latestMonth, 6).getTime(),
min: subMonths(latestMonth, 3).getTime(),
max: latestMonth.getTime(),
},
},
Expand All @@ -83,6 +73,7 @@ export const CarInfographic = ({
max: latestMonth.getTime(),
},
yaxis: {
show: false,
tickAmount: 1,
},
legend: { show: false },
Expand Down
20 changes: 17 additions & 3 deletions components/CarTreemap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import dynamic from "next/dynamic";
import { compareAsc, format, parseISO } from "date-fns";
import { API_URL, CHART_COLOURS } from "@/config";
import { fetchApi } from "@/utils/fetchApi";
import { Car } from "@/types";
import { Car, PopularMake } from "@/types";

const ApexChart = dynamic(() => import("react-apexcharts"), { ssr: false });

interface CarTreemapProps {
data: Car[];
popularMakes: any;
popularMakes: PopularMake[];
}

export const CarTreemap = ({ data, popularMakes }: CarTreemapProps) => {
Expand All @@ -30,7 +30,7 @@ export const CarTreemap = ({ data, popularMakes }: CarTreemapProps) => {
const filteredCars = useMemo(
() =>
cars.filter((car) =>
popularMakes.some(({ make }: Car) => make === car.make),
popularMakes.some(({ make }: PopularMake) => make === car.make),
),
[cars, popularMakes],
);
Expand All @@ -41,12 +41,26 @@ export const CarTreemap = ({ data, popularMakes }: CarTreemapProps) => {
},
dataLabels: {
enabled: true,
formatter: (text: string, opts: { value: number }) =>
`${text} - ${opts.value}`,
},
colors: CHART_COLOURS,
title: {
text: `Electric Car Make Distribution for ${selectedMonth}`,
align: "center" as "center",
},
xaxis: {
show: false,
labels: {
show: false,
},
axisBorder: {
show: false,
},
axisTicks: {
show: false,
},
},
};

const series = [
Expand Down
11 changes: 4 additions & 7 deletions components/HistoricalResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export const HistoricalResult = ({ data }: HistoricalResultProps) => {
colors: CHART_COLOURS,
stroke: { curve: "smooth" as "smooth", width: 3 },
dataLabels: { enabled: false },
fill: { opacity: 0.8 },
title: { text: "Historical COE Results", align: "center" as "center" },
xaxis: {
type: "datetime" as "datetime",
Expand All @@ -98,14 +97,11 @@ export const HistoricalResult = ({ data }: HistoricalResultProps) => {
new Intl.NumberFormat("en-SG", {
style: "currency",
currency: "SGD",
maximumFractionDigits: 0,
}).format(value),
align: "left" as "left",
},
},
grid: {
padding: {
left: 90,
right: 90,
},
floating: true,
},
};

Expand All @@ -132,6 +128,7 @@ export const HistoricalResult = ({ data }: HistoricalResultProps) => {
max: latestMonth.getTime(),
},
yaxis: {
show: false,
tickAmount: 1,
},
legend: { show: false },
Expand Down
31 changes: 16 additions & 15 deletions components/MonthlyResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const MonthlyResult = ({ data }: MonthlyResultProps) => {
},
dataLabels: {
enabled: true,
enabledOnSeries: [3],
// enabled: true,
formatter: (value: number, option: any) => {
if (option.seriesIndex === 3) {
return new Intl.NumberFormat("en-SG", {
Expand All @@ -60,13 +62,13 @@ export const MonthlyResult = ({ data }: MonthlyResultProps) => {
return value;
},
},
plotOptions: {
bar: {
dataLabels: {
position: "center",
},
},
},
// plotOptions: {
// bar: {
// dataLabels: {
// position: "center",
// },
// },
// },
stroke: { curve: "smooth" as "smooth", width: [0, 0, 0, 4] },
colors: CHART_COLOURS,
title: {
Expand All @@ -80,31 +82,30 @@ export const MonthlyResult = ({ data }: MonthlyResultProps) => {
categories,
},
yaxis: [
{ seriesName: "Quotas", title: { text: "Number of Bids" } },
{
show: false,
seriesName: "Quotas",
},
{ show: false, seriesName: "Quotas" },
{ show: false, seriesName: "Quotas" },
{
opposite: true,
title: { text: "Quota Premium ($)" },
labels: {
formatter: (value: number) =>
new Intl.NumberFormat("en-SG", {
style: "currency",
currency: "SGD",
maximumFractionDigits: 0,
}).format(value),
align: "right" as "right",
},
floating: true,
},
],
tooltip: {
shared: true,
intersect: false,
},
grid: {
padding: {
left: 120,
right: 120,
},
},
};

const series = [
Expand Down
2 changes: 2 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface Car {
selected?: boolean;
}

export type PopularMake = Pick<Car, "make" | "number">;

export type Dataset = {
name: string;
data: number[];
Expand Down

0 comments on commit 0604274

Please sign in to comment.