Skip to content
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

New component - PieChart #3470

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Conversation

nitzanyiz
Copy link
Contributor

@nitzanyiz nitzanyiz commented Dec 26, 2024

Description

Added a new component PieChart. The component gets segments which is an array of percentages to that each segment of the pie should cover. Each segment is a percentage representing the percentage of the pie to cover and a color for the pie segment.

Changelog

⭐ PieChart - New Component ⭐

Additional info

MADS-3418

@nitzanyiz nitzanyiz changed the title Feat/new component pie chart New component - Pie Chart Dec 26, 2024
@nitzanyiz nitzanyiz changed the title New component - Pie Chart New component - PieChart Dec 26, 2024
@nitzanyiz nitzanyiz requested a review from ethanshar December 26, 2024 13:50
@nitzanyiz nitzanyiz assigned nitzanyiz and ethanshar and unassigned nitzanyiz Dec 26, 2024
@nitzanyiz nitzanyiz marked this pull request as ready for review December 26, 2024 13:51
@ethanshar
Copy link
Collaborator

@nitzanyiz
When creating a new component, always create an example screen with it
It also makes it easier for the reviewer to check the new component

@nitzanyiz
Copy link
Contributor Author

@ethanshar I think I need to rethink the api. When I started to use the component I got into a few problems with the api. Lets discuss this.

@nitzanyiz nitzanyiz assigned ethanshar and unassigned nitzanyiz Jan 6, 2025
Copy link
Collaborator

@ethanshar ethanshar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!
Wrote a few comment

@@ -44,7 +44,8 @@ export const navigationData = {
screen: 'unicorn.components.SharedTransitionScreen'
},
{title: 'Stack Aggregator', tags: 'stack aggregator', screen: 'unicorn.components.StackAggregatorScreen'},
{title: 'Marquee', tags: 'sliding text', screen: 'unicorn.components.MarqueeScreen'}
{title: 'Marquee', tags: 'sliding text', screen: 'unicorn.components.MarqueeScreen'},
{title: 'PieChart', tags: 'pie chart data', screen: 'unicorn.components.PieChartScreen'}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this new component under Charts category, we don't have this category in public yet but it does exist in private

src/index.ts Outdated
@@ -82,6 +82,7 @@ export {default as HapticService, HapticType} from './services/HapticService';
export {default as Hint, HintProps} from './components/hint';
export {default as Icon, IconProps} from './components/icon';
export {default as Image, ImageProps} from './components/image';
export {default as PieChart, PieChartSegmentProps} from './components/piechart';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try keeping the exports order alphabetically

const total = useMemo(() => {
return _.sum(segments.map(s => s.percentage));
}, [segments]);
if (total !== 100) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should allow a total smaller than 100
I saw partial pie charts before, maybe users would want that. We can have the missing part as blank

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually works just by removing the error. Changed.

const DEFAULT_DIVIDER_WIDTH = 4;
const DEFAULT_PADDING = 0;

const PartialCircle = (props: PartialCircleProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find Segment or PieSegment a better name for this component, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think PieSegment is more clear. I'll change.

padding?: number;
};

const DEFAULT_DIVIDER_COLOR = '#FFFFFF';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using our Colors.$backgroundDefault here so in dark mode it won't stay white but use the default background color

Copy link
Contributor Author

@nitzanyiz nitzanyiz Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to set it in the global scope of the file or should it be at the component render? my meaning is using const DEFAULT_DIVIDER_COLOR = Colors.$backgroundDefault; inside the component and not out side of it.


export type PieChartProps = {
segments: PieChartSegmentProps[];
size?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding a defaultSegmentProps where the user can control default UI for all segments like the divider color and width

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for the border width and color as you suggested.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix folder name to pieChart

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are using an optional dependency it's possible the user won't have it installed, what we usually do is warn the user so they'll know to install it when using this component
moreover don't render the component if it's not installed, otherwise it will throw the user an error

You can see a reference for this behavior in our Card component that depends on blurView dep

@ethanshar ethanshar assigned nitzanyiz and unassigned ethanshar Jan 8, 2025
@nitzanyiz
Copy link
Contributor Author

@ethanshar , I made all the changes and added some to the api (border width and color). Also I added the api json.

@nitzanyiz nitzanyiz assigned ethanshar and unassigned nitzanyiz Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants