-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Client diversity piechart update #15251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LifeofDan-EL
wants to merge
36
commits into
ethereum:dev
Choose a base branch
from
LifeofDan-EL:client-diversity
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+194
−9
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
4bb1a87
Created React PieChart component
LifeofDan-EL 11827ed
Merge branch 'ethereum:dev' into client-diversity
LifeofDan-EL 1553d14
Testing to see if the chart works, before removing and updating the d…
LifeofDan-EL fb4c103
Merge branch 'client-diversity' of https://github.com/LifeofDan-EL/et…
LifeofDan-EL 84292b1
Fix lint errors
LifeofDan-EL 480a1e1
Fix lint errors
LifeofDan-EL 45761c8
Changed import way for the PieChart
LifeofDan-EL 0c8ac7c
Revert yarn.lock and .env.example to match upstream/dev
LifeofDan-EL 99615fa
Merge branch 'ethereum:dev' into client-diversity
LifeofDan-EL 202418c
Improved PieChart
LifeofDan-EL f8d0a70
Fixing import issue
LifeofDan-EL 171eefa
Slight improvement on the PieChart
LifeofDan-EL f689074
Merge branch 'ethereum:dev' into client-diversity
LifeofDan-EL 1ce8c30
Delete .yarnrc.yml
LifeofDan-EL 73091d9
Delete .yarn directory
LifeofDan-EL 1f0116e
Updated styling to use color palette
LifeofDan-EL cbe8b2e
Changed to accent colors
LifeofDan-EL 7cfd42c
Remove sticking out label, then attaching the percentage value to the…
LifeofDan-EL 352ed27
Trying to fix payload issue
LifeofDan-EL c57d2c2
Added ResponsiveContainer to PieChart
LifeofDan-EL 8c7ad14
Working on responsiveness
LifeofDan-EL c112033
Working on responsiveness
LifeofDan-EL a6b359b
Working on responsiveness
LifeofDan-EL 57ec8f0
Working on responsiveness
LifeofDan-EL 8ffc3da
Working on responsiveness
LifeofDan-EL 7e6926d
Working on responsiveness
LifeofDan-EL ce7e234
Working on responsiveness
LifeofDan-EL d8b85c6
Still working on it
LifeofDan-EL 64c2c57
Working on responsiveness
LifeofDan-EL d2b2910
Working on responsiveness
LifeofDan-EL 003b4d0
Testing for responsiveness
LifeofDan-EL b697fe3
Updated content
LifeofDan-EL e0d3b85
Merge branch 'ethereum:dev' into client-diversity
LifeofDan-EL 9724d25
Formatted footnote better
LifeofDan-EL dfdfc39
Merge branch 'client-diversity' of https://github.com/LifeofDan-EL/et…
LifeofDan-EL 8273f9f
Working on footnote issue
LifeofDan-EL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
"use client"; | ||
|
||
import { FaArrowTrendUp } from "react-icons/fa6"; | ||
import { | ||
Cell, | ||
Legend, | ||
Pie, | ||
PieChart as RechartsPieChart, | ||
ResponsiveContainer, | ||
} from "recharts"; | ||
|
||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { | ||
ChartConfig, | ||
ChartContainer, | ||
ChartTooltip, | ||
ChartTooltipContent, | ||
} from "@/components/ui/chart"; | ||
|
||
type PieChartDataPoint = { name: string; value: number }; | ||
|
||
/** | ||
* PieChartProps defines the properties for the PieChart component. | ||
* | ||
* @property {PieChartDataPoint[]} data - The data to be displayed in the chart. Each object should have a `name` and `value` property. | ||
* @property {string} [title] - The title of the chart. | ||
* @property {string} [description] - The description of the chart. | ||
* @property {string} [footerText] - The footer text of the chart. | ||
* @property {string} [footerSubText] - The footer subtext of the chart. | ||
*/ | ||
type PieChartProps = { | ||
data: PieChartDataPoint[]; | ||
title?: string; | ||
description?: string; | ||
footerText?: string; | ||
footerSubText?: string; | ||
}; | ||
|
||
const defaultChartConfig = { | ||
value: { | ||
label: "Value", | ||
color: "hsl(var(--accent-a))", | ||
}, | ||
} satisfies ChartConfig; | ||
|
||
const COLORS = [ | ||
"hsla(var(--accent-a))", | ||
"hsla(var(--accent-b))", | ||
"hsla(var(--accent-c))", | ||
]; | ||
/* | ||
PieChart component renders a pie chart with the provided data, utilizing accent colors, | ||
and a vertical legend positioned to the right. | ||
*/ | ||
|
||
export function PieChart({ | ||
data, | ||
title, | ||
description, | ||
footerText, | ||
footerSubText, | ||
}: PieChartProps) { | ||
return ( | ||
<Card className="w-full"> | ||
<CardHeader> | ||
{title && <CardTitle className="text-center">{title}</CardTitle>} | ||
{description && <CardDescription>{description}</CardDescription>} | ||
</CardHeader> | ||
<CardContent> | ||
<ChartContainer config={defaultChartConfig}> | ||
<div className="w-full min-h-[350px]"> | ||
<ResponsiveContainer width="100%" height={350}> | ||
<RechartsPieChart | ||
margin={{ top: 10, right: 10, bottom: 10, left: 10 }} | ||
> | ||
<ChartTooltip | ||
cursor={false} | ||
content={<ChartTooltipContent />} | ||
/> | ||
<Legend | ||
layout="vertical" | ||
verticalAlign="middle" | ||
align="right" | ||
wrapperStyle={{ | ||
fontSize: "0.85rem", | ||
paddingLeft: "10px", | ||
lineHeight: "1.8em", | ||
maxWidth: "40%", // Control legend width | ||
}} | ||
formatter={(value, entry) => { | ||
const payload = | ||
entry.payload as unknown as PieChartDataPoint; | ||
// Format to 2 decimal places if needed | ||
const formattedValue = Number.isInteger(payload.value) | ||
? payload.value | ||
: payload.value.toFixed(2); | ||
return `${value} (${formattedValue}%)`; | ||
}} | ||
/> | ||
<Pie | ||
data={data} | ||
dataKey="value" | ||
nameKey="name" | ||
cx="35%" | ||
cy="50%" | ||
outerRadius={75} | ||
innerRadius={0} | ||
paddingAngle={1} | ||
label={false} | ||
> | ||
{data.map((_, index) => ( | ||
<Cell | ||
key={`cell-${index}`} | ||
fill={COLORS[index % COLORS.length]} | ||
/> | ||
))} | ||
</Pie> | ||
</RechartsPieChart> | ||
</ResponsiveContainer> | ||
</div> | ||
</ChartContainer> | ||
</CardContent> | ||
{(footerText || footerSubText) && ( | ||
<CardFooter> | ||
<div className="flex w-full items-start gap-2 text-sm"> | ||
<div className="grid gap-2"> | ||
{footerText && ( | ||
<div className="flex items-center gap-2 font-medium leading-none"> | ||
{footerText} <FaArrowTrendUp className="h-4 w-4" /> | ||
</div> | ||
)} | ||
{footerSubText && ( | ||
<div className="text-muted-foreground flex items-center gap-2 leading-none"> | ||
{footerSubText} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
</CardFooter> | ||
)} | ||
</Card> | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few issues with these colors:
This is the current colors that we have https://dev--63b7ea99632763723c7f4d6b.chromatic.com/?path=/story/design-system-colors--primitives
@konopkja what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I looked at the preview after deployment and I agree there isn't enough contrast. Let me use values from the colour palette.