-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
CI is failing because of prettier. you should run |
Yes, I ran that command already. |
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; | ||
} |
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.
IMO: I think this way is much simple, WDYT? I prefer not using let
in this case.
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) | |
}; | |
} |
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.
That looks good too.
I tried not to use ternary operators just in case we need to add more conditions in future.
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.
Since the code is not complicated yet, I think we should consider it only when additional conditions arise!
you're sure?? plz have a look at this, which ran |
Added a function that determines "dy" and "dx" parameters of the label depending on height and width of the Bar Chart.