Skip to content

Commit 78816b0

Browse files
Merge pull request #2149 from topcoder-platform/PM-5879
PM-5879 Fix rating charts label
2 parents 84915e9 + ebb2b98 commit 78816b0

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/apps/profiles/src/member-profile/about-me/MemberRatingCard/MemberRatingInfoModal/MemberRatingInfoModal.spec.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,23 @@ describe('MemberRatingInfoModal', () => {
212212
expect(parseFloat(marker.style.left))
213213
.toBeCloseTo((3.5 / 6) * 100)
214214
})
215+
216+
it('hides the 2200+ axis label when the distribution has no elite buckets', () => {
217+
render(
218+
<MemberRatingInfoModal
219+
audienceLabel='developers'
220+
onClose={jest.fn()}
221+
percentile={15}
222+
profile={baseProfile}
223+
rating={1646}
224+
ratingDistribution={ratingDistribution}
225+
/>,
226+
)
227+
228+
expect(screen.getByText('1500'))
229+
.toBeInTheDocument()
230+
expect(screen.queryByText('2200+'))
231+
.not
232+
.toBeInTheDocument()
233+
})
215234
})

src/apps/profiles/src/member-profile/about-me/MemberRatingCard/MemberRatingInfoModal/MemberRatingInfoModal.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,29 @@ const getAxisLabelPosition = (
292292
return 100
293293
}
294294

295+
/**
296+
* Returns axis labels that fall within the visible distribution ranges.
297+
*
298+
* Hides labels such as `2200+` when the trimmed histogram has no elite buckets,
299+
* which otherwise stack on top of the final label (e.g. `1500`).
300+
*
301+
* @param {RatingDistributionRange[]} ranges - Visible rating distribution ranges.
302+
* @returns {Array<{ label: string, value: number }>} Axis labels to render.
303+
*/
304+
const getVisibleAxisLabels = (
305+
ranges: RatingDistributionRange[],
306+
): Array<{ label: string, value: number }> => {
307+
if (ranges.length === 0) {
308+
return chartAxisLabels
309+
}
310+
311+
const chartEnd = ranges[ranges.length - 1].end
312+
313+
return chartAxisLabels.filter((axisLabel: { label: string, value: number }) => (
314+
axisLabel.value <= chartEnd
315+
))
316+
}
317+
295318
/**
296319
* Calculates a bar height for a histogram count.
297320
*
@@ -359,6 +382,9 @@ const MemberRatingInfoModal: FC<MemberRatingInfoModalProps> = (props: MemberRati
359382
const markerPosition: number = props.rating !== undefined
360383
? getMarkerPosition(props.rating, distributionRanges)
361384
: 0
385+
const visibleAxisLabels: Array<{ label: string, value: number }> = useMemo(() => (
386+
getVisibleAxisLabels(distributionRanges)
387+
), [distributionRanges])
362388
const shouldStackMarkerRating: boolean = props.rating !== undefined && (
363389
markerPosition >= stackedMarkerPositionThreshold
364390
|| props.rating >= stackedMarkerRatingThreshold
@@ -476,7 +502,7 @@ const MemberRatingInfoModal: FC<MemberRatingInfoModalProps> = (props: MemberRati
476502
)}
477503

478504
<div className={styles.axisLabels}>
479-
{chartAxisLabels.map((axisLabel: { label: string, value: number }) => (
505+
{visibleAxisLabels.map((axisLabel: { label: string, value: number }) => (
480506
<span
481507
key={axisLabel.label}
482508
style={{

0 commit comments

Comments
 (0)