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

withBarValueLabel not displaying in correct positions in BarChart - Issue #6991 #7011

Closed
wants to merge 2 commits into from

Conversation

fsd-niraj
Copy link
Contributor

Added a function that determines "dy" and "dx" parameters of the label depending on height and width of the Bar Chart.

@Kenzo-Wada
Copy link
Contributor

CI is failing because of prettier. you should run npm run prettier:write

@fsd-niraj
Copy link
Contributor Author

Yes, I ran that command already.

Comment on lines +134 to +143
function labelCoordinates(): { dx: number, dy: number } {
let coord: { dx: number, dy: number } = { dx: 0, dy: 0 }
if (others.props.h < 300) {
coord = { ...coord, dx: Math.ceil(others?.width + 10) }
} else {
coord.dx = Math.ceil(others?.width - others?.viewBox?.x / 2)
}
coord = { ...coord, dy: Math.ceil(others.props.h / 15) }
return coord;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO: I think this way is much simple, WDYT? I prefer not using let in this case.

Suggested change
function labelCoordinates(): { dx: number, dy: number } {
let coord: { dx: number, dy: number } = { dx: 0, dy: 0 }
if (others.props.h < 300) {
coord = { ...coord, dx: Math.ceil(others?.width + 10) }
} else {
coord.dx = Math.ceil(others?.width - others?.viewBox?.x / 2)
}
coord = { ...coord, dy: Math.ceil(others.props.h / 15) }
return coord;
}
function labelCoordinates(): { dx: number, dy: number } {
return {
dx: others.props.h < 300
? Math.ceil(others?.width + 10)
: Math.ceil(others?.width - others?.viewBox?.x / 2),
dy: Math.ceil(others.props.h / 15)
};
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That looks good too.
I tried not to use ternary operators just in case we need to add more conditions in future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the code is not complicated yet, I think we should consider it only when additional conditions arise!

@Kenzo-Wada
Copy link
Contributor

Kenzo-Wada commented Oct 23, 2024

@fsd-niraj

you're sure?? plz have a look at this, which ran prettier:write on myside:)
https://github.com/fsd-niraj/mantine/pull/1

@fsd-niraj fsd-niraj closed this by deleting the head repository Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants