Skip to content

Commit df9782e

Browse files
authored
Wm 50 fe adding texts and tooltips to the platform (#108)
* fe: updated content + fix hover on category card * fe: update ranking widget styles
1 parent 6ce5410 commit df9782e

File tree

5 files changed

+71
-40
lines changed

5 files changed

+71
-40
lines changed

app-initial-data/indicators.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:4d61f2ae5c9c35f5d6a4f631c6c915b772366ae40b7ef1b40a88a671cb9a31aa
3-
size 27395
2+
oid sha256:d137228d03c49a1846d2eb9ff5e2680b9bee27b1b87d41c885f784672589f3c3
3+
size 24134

app/src/components/chart/index.tsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { useTranslations } from "next-intl";
55
import { IndicatorChartData } from "@/containers/indicators/types";
66

77
import PieChart from "@/components/chart/pie";
8-
import { RankingChart, RankingChartSection } from "@/components/chart/ranking";
8+
import {
9+
RankingChartLegend,
10+
RankingChartList,
11+
RankingChartSection,
12+
RankingSection,
13+
} from "@/components/chart/ranking";
914

1015
type ValidIndicatorData = IndicatorChartData & { value: number };
1116
const getValidData = (data: IndicatorChartData[]): ValidIndicatorData[] => {
@@ -33,15 +38,45 @@ const WidgetChart: FC<WidgetChartProps> = ({ indicator, data }) => {
3338
{ data: nonWetlands, title: t("non-wetlands"), type: "bars", unit },
3439
];
3540

36-
return <RankingChart sections={sections} withLegend />;
41+
return (
42+
<div className="w-full space-y-7">
43+
{sections.map((section) => (
44+
<RankingSection key={`ranking-chart-section-${section.title}`} section={section} />
45+
))}
46+
<RankingChartLegend />
47+
</div>
48+
);
3749
}
3850

3951
case "cost-of-intervention": {
40-
return <RankingChart data={getValidData(data)} />;
52+
const unit = data.reduce((acc, d) => d.unit || acc, "") || "";
53+
54+
return (
55+
<div className="w-full space-y-7">
56+
<RankingChartList data={getValidData(data)} unit={unit} />
57+
</div>
58+
);
4159
}
4260

4361
case "return-on-investment": {
44-
return <RankingChart data={getValidData(data)} />;
62+
const validData = getValidData(data);
63+
const unit = data.reduce((acc, d) => d.unit || acc, "") || "";
64+
65+
const wetlands = validData.filter((d) => d.group === "wetlands");
66+
const nonWetlands = validData.filter((d) => d.group === "non-wetlands");
67+
68+
const sections: RankingChartSection[] = [
69+
{ data: wetlands, type: "bars", unit },
70+
{ data: nonWetlands, type: "bars", unit },
71+
];
72+
73+
return (
74+
<div className="w-full space-y-7">
75+
{sections.map((section) => (
76+
<RankingSection key={`ranking-chart-section-${section.title}`} section={section} />
77+
))}
78+
</div>
79+
);
4580
}
4681

4782
case "wetland-types-get":

app/src/components/chart/ranking/index.tsx

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ import { ValidIndicatorData } from "@/components/chart/types";
1111

1212
type RankingChartSection = {
1313
data: ValidIndicatorData[];
14-
title: string;
1514
type: "bars" | "list";
16-
unit: string;
15+
title?: string;
16+
unit?: string;
1717
};
1818
interface Props {
1919
data: Array<ValidIndicatorData>;
2020
}
2121

22-
const RankingChartSectionHeader: FC<{ title: string; unit: string }> = ({ title, unit }) => (
23-
<header className="text-2xs mb-1 flex items-center justify-between py-1 leading-[22px] uppercase">
24-
<h3 className="font-medium">{title}</h3>
25-
<p className="font-normal">{unit}</p>
22+
const RankingChartSectionHeader: FC<{ title?: string; unit?: string }> = ({ title, unit }) => (
23+
<header
24+
className={cn({
25+
"text-2xs mb-1 flex items-center justify-end py-1 leading-[22px] uppercase": true,
26+
"justify-between": !!title && !!unit,
27+
})}
28+
>
29+
{!!title && <h3 className="font-medium">{title}</h3>}
30+
{!!unit && <p className="font-normal">{unit}</p>}
2631
</header>
2732
);
2833

@@ -31,7 +36,7 @@ const RankingChartList: FC<Props & { title?: string; unit?: string }> = ({ data,
3136

3237
return (
3338
<section>
34-
{title && unit && <RankingChartSectionHeader title={title} unit={unit} />}
39+
<RankingChartSectionHeader title={title} unit={unit} />
3540
<ul className="space-y-3">
3641
{data
3742
.sort((a, b) => b.value - a.value)
@@ -49,7 +54,11 @@ const RankingChartList: FC<Props & { title?: string; unit?: string }> = ({ data,
4954
);
5055
};
5156

52-
const RankingChartBars: FC<Props & { title: string; unit: string }> = ({ data, title, unit }) => {
57+
const RankingChartCategorizedBars: FC<Props & { title?: string; unit?: string }> = ({
58+
data,
59+
title,
60+
unit,
61+
}) => {
5362
const scale = useMemo(() => {
5463
const maxValue = Math.max(...data.map((item) => item.value));
5564
return (value: number) => (value / maxValue) * 100; // Scale to percentage
@@ -58,7 +67,7 @@ const RankingChartBars: FC<Props & { title: string; unit: string }> = ({ data, t
5867
if (data.length === 0) return null;
5968

6069
return (
61-
<section className="border-t border-dashed">
70+
<section className={cn({ "border-t border-dashed": !!title })}>
6271
<RankingChartSectionHeader title={title} unit={unit} />
6372
<ul className="space-y-4">
6473
{data
@@ -114,31 +123,12 @@ const RankingSection: FC<{
114123
return (
115124
<>
116125
{type === "bars" ? (
117-
<RankingChartBars data={data} title={title} unit={unit} />
126+
<RankingChartCategorizedBars data={data} title={title} unit={unit} />
118127
) : type === "list" ? (
119128
<RankingChartList data={data} title={title} unit={unit} />
120129
) : null}
121130
</>
122131
);
123132
};
124133

125-
const RankingChart: FC<{
126-
sections?: Array<RankingChartSection>;
127-
data?: ValidIndicatorData[];
128-
withLegend?: boolean;
129-
}> = ({ sections, data, withLegend }) => {
130-
return (
131-
<div className="w-full space-y-7">
132-
{data ? (
133-
<RankingChartList data={data} />
134-
) : sections ? (
135-
sections.map((section) => (
136-
<RankingSection key={`ranking-chart-section-${section.title}`} section={section} />
137-
))
138-
) : null}
139-
{withLegend && <RankingChartLegend />}
140-
</div>
141-
);
142-
};
143-
144-
export { RankingChart, RankingChartLegend, type RankingChartSection };
134+
export { RankingSection, RankingChartList, RankingChartLegend, type RankingChartSection };

app/src/containers/categories/item.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ export const CategoriesItem = (category: Category) => {
7676
)}
7777
>
7878
<header className="relative flex min-h-28 w-full flex-col justify-center">
79-
<div className="relative w-full">
79+
<div className="group relative w-full">
8080
<h2 className="font-display text-2xl">{category.name}</h2>
81+
<p
82+
className="invisible max-h-0 overflow-hidden text-sm font-normal opacity-0 transition-[opacity_max-height_visibility] duration-500 group-hover:visible group-hover:max-h-40 group-hover:opacity-100"
83+
style={{ transitionProperty: "opacity, max-height, visibility" }}
84+
>
85+
{category.description}
86+
</p>
8187
</div>
8288
</header>
8389

app/src/containers/landscapes/list.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export const LandscapesList = async () => {
3535
<li className="bg-background w-96 shrink-0 space-y-4 rounded-4xl p-6">
3636
<h1 className="font-display text-4xl text-blue-500">Highlighted landscapes</h1>
3737
<p className="text-foreground text-sm">
38-
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id, similique magnam tenetur
39-
eligendi beatae aut architecto deleniti iste autem adipisci ipsam hic nisi, quia, dicta
40-
quam animi vel. Et, nihil!
38+
Discover iconic wetland landscapes, see the different values they bring for nature and
39+
the communities around them and explore why additional efforts are needed for better
40+
management and protection.
4141
</p>
4242
</li>
4343

0 commit comments

Comments
 (0)