Skip to content

Commit

Permalink
Merge pull request #1034 from Open-Earth-Foundation/nina/feat/ON-3141…
Browse files Browse the repository at this point in the history
…/unifyColors

[on-3141] unify colors
  • Loading branch information
thehighestprimenumber authored Jan 7, 2025
2 parents a5b6e01 + 47370d0 commit 33a9c2c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SectorEmission } from "@/util/types";
import { ResponsiveBar } from "@nivo/bar";
import { SECTORS } from "@/util/constants";
import { allSectorColors, SECTORS } from "@/util/constants";
import { convertKgToKiloTonnes, convertKgToTonnes } from "@/util/helpers";
import { useTranslation } from "@/i18n/client";
import { toKebabCaseModified } from "@/app/[lng]/[inventory]/InventoryResultTab/index";
Expand Down Expand Up @@ -46,8 +46,6 @@ const EmissionBySectorChart: React.FC<EmissionBySectorChartProps> = ({
toKebabCaseModified(sector.name),
);

const colors = ["#5785F4", "#F17105", "#25AC4B", "#BFA937", "#F5D949"];

return (
<div className="min-h-[600px]">
<div className="h-[600px]">
Expand Down Expand Up @@ -80,7 +78,7 @@ const EmissionBySectorChart: React.FC<EmissionBySectorChartProps> = ({
)}
valueScale={{ type: "linear", min: 0, max: "auto" }}
indexScale={{ type: "band", round: true }}
colors={colors}
colors={allSectorColors}
borderColor={{
from: "color",
modifiers: [["darker", 1.6]],
Expand Down Expand Up @@ -136,7 +134,7 @@ const EmissionBySectorChart: React.FC<EmissionBySectorChartProps> = ({
>
<Box
className="h-4 w-4"
style={{ backgroundColor: colors[index] }}
style={{ backgroundColor: allSectorColors[index] }}
></Box>
<Text
fontSize="body.md"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { EmissionsForecastData } from "@/util/types";
import { TFunction } from "i18next/typescript/t";
import { getReferenceNumberByName, SECTORS, ISector } from "@/util/constants";
import {
getReferenceNumberByName,
SECTORS,
ISector,
allSectorColors,
} from "@/util/constants";
import {
Badge,
Box,
Expand Down Expand Up @@ -55,7 +60,6 @@ export const EmissionsForecastChart = ({

const data = convertToLineChartData(forecast);

const colors = ["#FFAB51", "#5162FF", "#51ABFF", "#D45252", "#CFAE53"];
return (
<ResponsiveLine
data={data}
Expand All @@ -80,7 +84,7 @@ export const EmissionsForecastChart = ({
tickRotation: 0,
format: (value: number) => convertKgToTonnes(value),
}}
colors={colors}
colors={allSectorColors}
tooltip={({ point }) => {
const year = point.data.x;
const sumOfYs = data.reduce((sum, series) => {
Expand Down Expand Up @@ -122,7 +126,7 @@ export const EmissionsForecastChart = ({
<Badge
colorScheme="gray"
boxSize="10px"
bg={colors[index]}
bg={allSectorColors[index]}
marginRight="8px"
/>
{series.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
SegmentedProgressValues,
} from "@/components/SegmentedProgress";
import { EmptyStateCardContent } from "@/app/[lng]/[inventory]/InventoryResultTab/EmptyStateCardContent";
import { allSectorColors, SECTORS } from "@/util/constants";

const EmissionsTable = ({
topEmissions,
Expand Down Expand Up @@ -96,11 +97,12 @@ const TopEmissionsWidget = ({

function getPercentagesForProgress(): SegmentedProgressValues[] {
const bySector: SectorEmission[] = results?.totalEmissions.bySector ?? [];
return bySector.map(({ sectorName, co2eq, percentage }) => {
return SECTORS.map(({ name }) => {
const sector = bySector.find((sector) => sector.sectorName === name)!;
return {
name: sectorName,
value: co2eq,
percentage: percentage,
name,
value: sector?.co2eq || 0,
percentage: sector?.percentage || 0,
} as SegmentedProgressValues;
});
}
Expand Down Expand Up @@ -147,6 +149,7 @@ const TopEmissionsWidget = ({
values={getPercentagesForProgress()}
total={results?.totalEmissions.total}
t={t}
colors={allSectorColors}
showLabels
showHover
/>
Expand Down
8 changes: 1 addition & 7 deletions app/src/components/SegmentedProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ export type SegmentedProgressValues =

export function SegmentedProgress({
values,
colors = [
"interactive.connected",
"interactive.tertiary",
"interactive.secondary",
"sentiment.negativeDefault",
"interactive.control",
],
colors = ["interactive.connected", "interactive.tertiary"],
max = 1,
height = 4,
showLabels = false,
Expand Down
16 changes: 16 additions & 0 deletions app/src/lib/app-theme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { extendTheme, theme } from "@chakra-ui/react";

export enum SectorColors {
I = "#575BF4",
II = "#DF2222",
III = "#F28C37",
IV = "#2D0D58",
V = "#CC6B1D",
}

export const appTheme = extendTheme({
colors: {
brand: {
Expand All @@ -15,6 +23,14 @@ export const appTheme = extendTheme({
alternative: "#001EA7",
},

sectors: {
I: SectorColors.I,
II: SectorColors.II,
III: SectorColors.III,
IV: SectorColors.IV,
V: SectorColors.V,
},

semantic: {
success: "#24BE00",
successOverlay: "#EFFDE5",
Expand Down
13 changes: 13 additions & 0 deletions app/src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PiPlant, PiTrashLight } from "react-icons/pi";
import { TbBuildingCommunity } from "react-icons/tb";
import { IconBaseProps } from "react-icons";
import { LiaIndustrySolid } from "react-icons/lia";
import { appTheme, SectorColors } from "@/lib/app-theme"; // Import the appTheme

export const maxPopulationYearDifference = 5;

Expand All @@ -28,6 +29,7 @@ export interface ISector {
scopes: number[];
};
};
color: string;
}

export const getSectorsForInventory = (inventoryType?: InventoryType) => {
Expand Down Expand Up @@ -65,6 +67,7 @@ export const SECTORS: ISector[] = [
name: "stationary-energy",
description: "stationary-energy-description",
icon: TbBuildingCommunity,
color: SectorColors.I,
inventoryTypes: {
[InventoryTypeEnum.GPC_BASIC]: { scopes: [1, 2] },
[InventoryTypeEnum.GPC_BASIC_PLUS]: { scopes: [1, 2, 3] },
Expand All @@ -77,6 +80,7 @@ export const SECTORS: ISector[] = [
name: "transportation",
description: "transportation-description",
icon: BsTruck,
color: SectorColors.II,
inventoryTypes: {
[InventoryTypeEnum.GPC_BASIC]: { scopes: [1, 2] },
[InventoryTypeEnum.GPC_BASIC_PLUS]: { scopes: [1, 2, 3] },
Expand All @@ -89,6 +93,7 @@ export const SECTORS: ISector[] = [
name: "waste",
description: "waste-description",
icon: PiTrashLight,
color: SectorColors.III,
inventoryTypes: {
[InventoryTypeEnum.GPC_BASIC]: { scopes: [1, 3] },
[InventoryTypeEnum.GPC_BASIC_PLUS]: { scopes: [1, 3] },
Expand All @@ -101,6 +106,7 @@ export const SECTORS: ISector[] = [
name: "ippu",
description: "ippu-description",
icon: LiaIndustrySolid,
color: SectorColors.IV,
testId: "ippu-sector-card",
inventoryTypes: {
[InventoryTypeEnum.GPC_BASIC]: { scopes: [] },
Expand All @@ -113,6 +119,7 @@ export const SECTORS: ISector[] = [
name: "afolu",
description: "afolu-description",
icon: PiPlant,
color: SectorColors.V,
testId: "afolu-sector-card",
inventoryTypes: {
[InventoryTypeEnum.GPC_BASIC]: { scopes: [] },
Expand All @@ -121,5 +128,11 @@ export const SECTORS: ISector[] = [
},
];

export const allSectorColors = SECTORS.map((sector) => {
return sector.color;
});
export const getSectorByName = (name: string) =>
SECTORS.find((s) => s.name === name);

export const getReferenceNumberByName = (name: keyof ISector) =>
findBy("name", name)?.referenceNumber;

0 comments on commit 33a9c2c

Please sign in to comment.